N
N
Nikita Kudrin2021-04-27 19:35:55
Node.js
Nikita Kudrin, 2021-04-27 19:35:55

How to translate from CommonJS to ES6?

There are functions:

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);
    }
}


how
const props = require(file)
change to `import ... from ...`?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question