JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 43
  • Score
    100M100P100Q63062F
  • License ISC

Convert JSON to an ECMAScript module

Package Exports

  • json-to-es-module

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (json-to-es-module) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

json-to-es-module

npm version Build Status codecov

Convert JSON to an ECMAScript module

{
  "name": "Sam"
}

export default {
  name: 'Sam'
};

Installation

Use npm.

npm install json-to-es-module

API

const jsonToEsModule = require('json-to-es-module');

jsonToEsModule(str [, option])

str: string (JSON string)
option: Object
Return: string

jsonToEsModule(`{
  "foo": 1,
  "bar": [
    true,
    null
  ]
}`);
//=> 'export default {\n\tfoo: 1,\n\tbar: [\n\t\ttrue,\n\t\tnull\n\t]\n};\n'

option.filename

Type: string

Filename displayed in the error message.

try {
  jsonToEsModule('"');
} catch (err) {
  err.message; //=> Unexpected end of JSON input while parsing near '"'
}

try {
  jsonToEsModule('"', {filename: 'source.json'});
} catch (err) {
  err.message; //=> Unexpected end of JSON input while parsing near '"' in source.json
}

License

ISC License © 2018 - 2019 Shinnosuke Watanabe