{"_id":"polite-json","_rev":"2-e6779403a6776c3e451c8a62cd00b93d","name":"polite-json","dist-tags":{"latest":"5.0.0"},"versions":{"4.0.0":{"name":"polite-json","version":"4.0.0","description":"JSON.parse and stringify with better errors that respects formatting","main":"dist/cjs/index.js","module":"dist/mjs/index.js","exports":{".":{"import":{"types":"./dist/mjs/index.d.ts","default":"./dist/mjs/index.js"},"require":{"types":"./dist/cjs/index.d.ts","default":"./dist/cjs/index.js"}},"./package.json":{"import":"./package.json","require":"./package.json"}},"scripts":{"preversion":"npm test","postversion":"npm publish","prepublishOnly":"git push origin --follow-tags","prepare":"tsc -p tsconfig.json && tsc -p tsconfig-esm.json && bash scripts/fixup.sh","pretest":"npm run prepare","presnap":"npm run prepare","test":"c8 tap","snap":"c8 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":"^16.3.3","ts-node":"^10.9.1","typedoc":"^0.23.21","typescript":"^4.9.3"},"tap":{"coverage":false,"node-arg":["--no-warnings","--loader","ts-node/esm"],"ts":false},"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"},"types":"./dist/cjs/index.d.ts","gitHead":"f0122f8abd889dda176f2f927711362cdf3f7d42","bugs":{"url":"https://github.com/isaacs/polite-json/issues"},"homepage":"https://github.com/isaacs/polite-json#readme","_id":"polite-json@4.0.0","_nodeVersion":"18.16.0","_npmVersion":"9.6.7","dist":{"integrity":"sha512-9/r1kWUFvwwBwztZv++seGoP0UzuKahHoppPCp6BYibDxHO3ew0S0PD+JuSJ6DC1+w77HFBDK6RHcLtT/kOSjw==","shasum":"9c16f94c1ccbf58d7db83a51c27e5bd5412464fe","tarball":"https://registry.npmjs.org/polite-json/-/polite-json-4.0.0.tgz","fileCount":13,"unpackedSize":51947,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBObz0D1a+09Xq3mnmp3Q1yCBQo+7RRyOPmzzIYU6YDmAiBdko1MKeNursngUlejTURzQmgoDuYCzs07pSBxocoWZw=="}]},"_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_4.0.0_1686117037764_0.2946336168469854"},"_hasShrinkwrap":false},"4.0.1":{"name":"polite-json","version":"4.0.1","description":"JSON.parse and stringify with better errors that respects formatting","main":"dist/cjs/index.js","module":"dist/mjs/index.js","exports":{".":{"import":{"types":"./dist/mjs/index.d.ts","default":"./dist/mjs/index.js"},"require":{"types":"./dist/cjs/index.d.ts","default":"./dist/cjs/index.js"}},"./package.json":{"import":"./package.json","require":"./package.json"}},"scripts":{"preversion":"npm test","postversion":"npm publish","prepublishOnly":"git push origin --follow-tags","prepare":"tsc -p tsconfig.json && tsc -p tsconfig-esm.json && bash scripts/fixup.sh","pretest":"npm run prepare","presnap":"npm run prepare","test":"c8 tap","snap":"c8 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":"^16.3.3","ts-node":"^10.9.1","typedoc":"^0.23.21","typescript":"^4.9.3"},"tap":{"coverage":false,"node-arg":["--no-warnings","--loader","ts-node/esm"],"ts":false},"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"},"types":"./dist/cjs/index.d.ts","gitHead":"0f8ed9f9d000388b81b717f77301c56d19208374","bugs":{"url":"https://github.com/isaacs/polite-json/issues"},"homepage":"https://github.com/isaacs/polite-json#readme","_id":"polite-json@4.0.1","_nodeVersion":"19.9.0","_npmVersion":"9.6.3","dist":{"integrity":"sha512-8LI5ZeCPBEb4uBbcYKNVwk4jgqNx1yHReWoW4H4uUihWlSqZsUDfSITrRhjliuPgxsNPFhNSudGO2Zu4cbWinQ==","shasum":"57580c8576b1f8c24350be8dcdef5582bb7d75e7","tarball":"https://registry.npmjs.org/polite-json/-/polite-json-4.0.1.tgz","fileCount":13,"unpackedSize":53673,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC/e5/I1RrZGAz/leHjc83mXZNWe1NFzTe3X0kbTpueRAIgQH7bE1uD3eKZNHkaYt1FJ2dLLtt4gx5NKI24ZDjrai0="}]},"_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_4.0.1_1686120019177_0.3668092770147686"},"_hasShrinkwrap":false},"5.0.0":{"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":"https://registry.npmjs.org/polite-json/-/polite-json-5.0.0.tgz","fileCount":13,"unpackedSize":53875,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHxEh43KoUQQ5YcnHQLDFQ2UNVYNa4NOBPV/AziuiUsOAiEAjHvkzvPts9knrZyaryUzIngn8SsZGGNvDG05Pv4pmLY="}]},"_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}},"time":{"created":"2023-06-07T05:50:37.692Z","4.0.0":"2023-06-07T05:50:38.045Z","modified":"2024-05-18T23:29:49.377Z","4.0.1":"2023-06-07T06:40:19.377Z","5.0.0":"2024-05-18T23:29:49.247Z"},"maintainers":[{"name":"isaacs","email":"i@izs.me"}],"description":"JSON.parse and stringify with better errors that respects formatting","homepage":"https://github.com/isaacs/polite-json#readme","keywords":["JSON","parse","stringify","formatting","error","context"],"repository":{"type":"git","url":"git+https://github.com/isaacs/polite-json.git"},"bugs":{"url":"https://github.com/isaacs/polite-json/issues"},"license":"MIT","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","readmeFilename":"README.md"}