UNPKG

@jspm/generator

Version:

Package Import Map Generation Tool

23 lines (21 loc) 856 B
import { JspmError } from './err.js'; import { detectStyle } from './source-style.js'; export function parseStyled(source, fileName) { // remove any byte order mark if (source.startsWith('\uFEFF')) source = source.substr(1); let style = detectStyle(source); try { return { json: JSON.parse(source), style }; } catch (e) { throw new JspmError(`Error parsing JSON file${fileName ? ' ' + fileName : ''}`); } } export function stringifyStyled(json, style) { let jsonString = JSON.stringify(json, null, style.tab); return style.indent + jsonString.replace(/([^\\])""/g, '$1' + style.quote + style.quote) // empty strings .replace(/([^\\])"/g, '$1' + style.quote).replace(/\n/g, style.newline + style.indent) + (style.trailingNewline || ''); } //# sourceMappingURL=json.js.map