Last active
February 11, 2021 02:08
-
-
Save FagnerMartinsBrack/69da85976eea5e642164180e03f42489 to your computer and use it in GitHub Desktop.
(Medium) Why Small Modules Matter - End Result
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const readFileAsJSON = require("./read-file"); | |
const writeFileToJSON = require("./write-file"); | |
const flattenArray = require("flatten-array"); | |
module.exports = function flattenArrayInsideFile(fileName) { | |
return readFileAsJSON(fileName) | |
.then(function(parsedContent) { | |
const flattenedArray = flattenArray(parsedContent); | |
return writeFileToJSON(fileName, flattenedArray); | |
}) | |
.then(function() { | |
console.log("Done!"); | |
}); | |
}; | |
// async/await | |
module.exports = async function flattenArrayInsideFile(fileName) { | |
const parsedContent = await readFileAsJSON(fileName); | |
const flattenedArray = flattenArray(parsedContent); | |
await writeFileToJSON(fileName, flattenedArray); | |
console.log("Done!"); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What do you think of this idea?
update-file
flatten-array-inside-file