UNPKG

typed-jsonfile

Version:
14 lines (13 loc) 604 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseJsoncString = void 0; const jsonc_parser_1 = require("jsonc-parser"); const parseJsoncString = (jsoncString, errorTolerant = false) => { const errors = []; const json = (0, jsonc_parser_1.parse)(jsoncString, errors, { allowTrailingComma: true }); // TODO better error printing if (errors.length && !errorTolerant) throw errors.map(({ error, ...rest }) => ({ code: (0, jsonc_parser_1.printParseErrorCode)(error), ...rest })); return json; }; exports.parseJsoncString = parseJsoncString;