If I have file places.mjs
export default { STATES: { 'AU' : {...}, 'US' : {...} } };
What is the javascript way to get the json into a file? I just need to remove the “export detault”, and the trailing semicolon and this can be read with
let json = require('json5')
let fs = require('fs-extra')
let a = json.parse(fs.readFileSync("./places.mjs"))
I can do this with sed, but what is the jacascript way to do this? I want to read an mjs and write json.
-- Removing the unwanted text and trailing semicoln
sed -i '' -e 's/export default//g' places.mjs
sed -i '' -r 's/(.*);/1/' places.mjs
---- run this program and print output to out.json
let json = require('json5')
let fs = require('fs-extra')
let a = json.parse(fs.readFileSync("./places.mjs"
console.log(a)
node chris.cjs > out.json
-- Adding the export default back, and trailing semicolon
echo "$(echo -n 'export default '; cat out.json)" > out.json
echo ';' >> out.json
Works as expected, but how to just handle it in javascript