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
Convert JSON to an ECMAScript module
{
"name": "Sam"
}↓
export default {
name: 'Sam'
};Installation
npm install json-to-es-moduleAPI
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