@HepkaPlay
JavaScript Junior.

Как из CommonJS перевести в ES6?

Есть функции:

function findFiles(folderPath) {
    let files = []
    folderPath = isAbsolute(folderPath) ? folderPath : join(process.cwd(), folderPath)
    const folder = readdirSync(folderPath, { withFileTypes: true });

    for (const file of folder) {
        const pathFile = join(folderPath, file.name)
        if (file.isDirectory()) {
            files = [...files, ...findFiles(pathFile)]
            continue
        }
        files.push(pathFile)
    }
    return files
}

function folderHandler(handlerPath, fn) {
    for (const file of findFiles(handlerPath)) {
        const { dir, base } = parse(file);
        const props = require(file);
        fn(props, base, parse(dir).name);
    }
}


Как
const props = require(file)
переделать в `import ... from ...`?
  • Вопрос задан
  • 126 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы