json-to-js.js 500 B

1234567891011121314
  1. import fs from 'fs'
  2. const COMMENT = '// This file is a workaround for a bug in web browsers\' "native"' + '\n' +
  3. '// ES6 importing system which is uncapable of importing "*.json" files.' + '\n' +
  4. '// https://github.com/catamphetamine/libphonenumber-js/issues/239'
  5. const path = process.argv[2]
  6. jsonToJs(path)
  7. function jsonToJs(path) {
  8. let contents = fs.readFileSync(path, 'utf-8')
  9. contents = COMMENT + '\n' + 'export default ' + contents
  10. fs.writeFileSync(path + '.js', contents)
  11. }