Skip to content

Instantly share code, notes, and snippets.

@gerrard00
Created November 26, 2018 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gerrard00/a20b8f6a825330ea9f2f24ab3c465d91 to your computer and use it in GitHub Desktop.
Save gerrard00/a20b8f6a825330ea9f2f24ab3c465d91 to your computer and use it in GitHub Desktop.
Convert a json object to a node module...don't ask
'use strict';
const fs = require('fs');
const util = require('util');
const contents = fs.readFileSync(0, 'utf8');
const jsonObject = JSON.parse(contents);
const javascriptString = util.inspect(jsonObject, { depth: null });
console.log(`
'use strict';
module.exports =
${javascriptString}
;
`);
@gerrard00
Copy link
Author

Invoke with prettier:

node json-to-node-module.js < input.json | prettier --stdin --parser flow --single-quote --trailing-comma all > output.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment