{"name":"polite-json","version":"5.0.0","description":"JSON.parse and stringify with better errors that respects formatting","main":"./dist/commonjs/index.js","exports":{"./package.json":"./package.json",".":{"import":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.js"},"require":{"types":"./dist/commonjs/index.d.ts","default":"./dist/commonjs/index.js"}}},"scripts":{"preversion":"npm test","postversion":"npm publish","prepublishOnly":"git push origin --follow-tags","prepare":"tshy","pretest":"npm run prepare","presnap":"npm run prepare","test":"tap","snap":"tap","postsnap":"npm run format","format":"prettier --write . --loglevel warn","typedoc":"typedoc --tsconfig tsconfig-esm.json ./src/*.ts"},"repository":{"type":"git","url":"git+https://github.com/isaacs/polite-json.git"},"keywords":["JSON","parse","stringify","formatting","error","context"],"license":"MIT","devDependencies":{"@types/node":"^18.11.9","@types/tap":"^15.0.7","c8":"^7.12.0","prettier":"^2.8.2","sync-content":"^1.0.2","tap":"^18.8.0","tshy":"^1.14.0","typedoc":"^0.23.21"},"tap":{"typecheck":true},"prettier":{"semi":false,"printWidth":80,"tabWidth":2,"useTabs":false,"singleQuote":true,"jsxSingleQuote":false,"bracketSameLine":true,"arrowParens":"avoid","endOfLine":"lf"},"engines":{"node":"^14.17.0 || ^16.13.0 || >=18.0.0"},"funding":{"url":"https://github.com/sponsors/isaacs"},"tshy":{"exports":{"./package.json":"./package.json",".":"./src/index.ts"}},"types":"./dist/commonjs/index.d.ts","type":"module","_id":"polite-json@5.0.0","gitHead":"8cbf9e006ac2be7706283d2eb7349dd8190dd16b","bugs":{"url":"https://github.com/isaacs/polite-json/issues"},"homepage":"https://github.com/isaacs/polite-json#readme","_nodeVersion":"20.11.0","_npmVersion":"10.7.0","dist":{"integrity":"sha512-OLS/0XeUAcE8a2fdwemNja+udKgXNnY6yKVIXqAD2zVRx1KvY6Ato/rZ2vdzbxqYwPW0u6SCNC/bAMPNzpzxbw==","shasum":"85c0603a905b604fffd15dbcd5990f752f6b6682","tarball":"http://registry-npm.ywwl.com/polite-json/download/polite-json-5.0.0.tgz","fileCount":13,"unpackedSize":53875,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHxEh43KoUQQ5YcnHQLDFQ2UNVYNa4NOBPV/AziuiUsOAiEAjHvkzvPts9knrZyaryUzIngn8SsZGGNvDG05Pv4pmLY="}],"size":9311,"noattachment":false,"key":"/polite-json/-/polite-json-5.0.0.tgz"},"_npmUser":{"name":"isaacs","email":"i@izs.me"},"directories":{},"maintainers":[{"name":"isaacs","email":"i@izs.me"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/polite-json_5.0.0_1716074989056_0.10299347863557351"},"_hasShrinkwrap":false,"readme":"# polite-json\n\nThis is a Node.js library for getting nicer errors out of\n`JSON.parse()`, including context and position of the parse\nerrors.\n\nIt also preserves the newline and indentation styles of the JSON\ndata, by putting them in the object or array in the\n`Symbol.for('indent')` and `Symbol.for('newline')` properties, so\nthat if you `stringify()` the object you parsed, it'll be\nformatted with the same indentation and newlines (in most cases,\nit's not a super clever streaming in-place editor, it just uses\nthe first line break and indentation it sees).\n\n## Install\n\n`$ npm install --save polite-json`\n\n### Example\n\n```js\nimport { parse, parseNoExceptions, stringify } from 'polite-json'\n// or: const { parse, stringify } = require('polite-json')\n\nparse('\"foo\"') // returns the string 'foo'\nconst obj = parse('{\\r\\n\\t\"hello\": \"world\"\\r\\n}') // { hello: 'world' }\nstringify(obj) // stringifies with \\r\\n line breaks, \\t indentation\nparse('garbage') // more useful error message\nparseNoExceptions('garbage') // no error, just undefined\n```\n\n### Features\n\n- Like JSON.parse, but the errors are better, and style choices\n  are (mostly) preserved.\n- Strips a leading byte-order-mark that you sometimes get reading files.\n- Has a `noExceptions` method that returns undefined rather than throwing.\n- Attaches the newline character(s) used to the `Symbol.for('newline')`\n  property on objects and arrays.\n- Attaches the indentation character(s) used to the `Symbol.for('indent')`\n  property on objects and arrays.\n\n## Indentation\n\nIndentation and newline information is saved on the\n`Symbol.for('indent')` and `Symbol.for('newline')` properties,\nrespectively. This is usually not a problem for JSON objects,\nsince JSON ignores symbols, but if you are using them for some\nother purpose, it could cause weird behavior.\n\nIndentation is determined by looking at the whitespace between\nthe initial `{` and `[` and the character that follows it. If\nyou have lots of weird inconsistent indentation, then it won't\ntrack that or give you any way to preserve it. Whether this is a\nbug or a feature is debatable ;)\n\n### API\n\n#### `parse(txt, reviver = null, context = 20)`\n\nWorks just like `JSON.parse`, but will include a bit more\ninformation when an error happens, and attaches a\n`Symbol.for('indent')` and `Symbol.for('newline')` on objects and\narrays. This throws a `JSONParseError`.\n\n#### `parseNoExceptions(txt, reviver = null)`\n\nWorks just like `JSON.parse`, but will return `undefined` rather\nthan throwing an error.\n\n#### `class JSONParseError(er, text, context = 20, caller = null)`\n\nExtends the JavaScript `SyntaxError` class to parse the message\nand provide better metadata.\n\nPass in the error thrown by the built-in `JSON.parse`, and the\ntext being parsed, and it'll parse out the bits needed to be\nhelpful.\n\n`context` defaults to 20.\n\nThe `er` parameter is attached as the `JSONParseError.cause`\nproperty. This is used to provide a reference to the original\nsystem error that was raised by `JSON.parse()`.\n\nSet a `caller` function to trim internal implementation details\nout of the stack trace. When calling `parseJson`, this is set to\nthe `parseJson` function. If not set, then the constructor\ndefaults to itself, so the stack trace will point to the spot\nwhere you call `new JSONParseError`.\n\n#### `stringify(obj, reviver = undefined, indent = undefined)`\n\nIf the object was parsed using the `parse()` methods in this\nlibrary, then it will default to using the same indentation and\nnewline strings that were detected, if relevant.\n\nIf `indent` is set, then the stored formatting information is\nignored, and `\\n` newlines will be used.\n\nA final newline will be appended if indentation is used.\n","publish_time":1716074989247,"_cnpm_publish_time":1716074989247,"dist-tags":{"latest":"5.0.0"}}