{"_id":"json-stringify-deterministic@1.0.18","bugs":{"url":"https://github.com/Kikobeats/json-stringify-deterministic/issues"},"dist":{"shasum":"3a736f0ad24c2080b66c2c6e0f5694e285b056c9","tarball":"http://registry-npm.ywwl.com/json-stringify-deterministic/download/json-stringify-deterministic-1.0.18.tgz","fileCount":7,"integrity":"sha512-V9zW1SOlQNMgpYk4TYg2FAswRDKR857yW1gXlo+vJ/oqxW/+nEeWpOGucV1aIy9C24zNP0nqdTGLEvcL8LK3ug==","signatures":[{"sig":"MEUCIQCgvEpRvb8bNIi/ZTJk7Vhb+RgJhCiuh2lFO4Buzyvj/QIgOT5mM4Kz4pd658W8pDT+gDBchMZ9v9QxBasPq8Gnt5o=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDSJfgIBFgoT5xrD0YbqnLd9tI8QCY66V8cAFEZrPEpuAIhANGXt04xaXJNqXny574opSjE/RDcvsEFYvE3L2kdg5Qs"}],"unpackedSize":11627,"size":4587,"noattachment":false,"key":"/json-stringify-deterministic/-/json-stringify-deterministic-1.0.18.tgz"},"main":"lib","name":"json-stringify-deterministic","types":"./lib/index.d.ts","author":{"url":"https://github.com/Kikobeats","name":"Kiko Beats","email":"josefrancisco.verdu@gmail.com"},"engines":{"node":">= 4"},"gitHead":"e15b37c3d6835cfddd765df1cc26aa0f3c0a0950","license":"MIT","scripts":{"lint":"standard && standard-markdown","test":"c8 mocha --require should","clean":"rm -rf node_modules","pretest":"npm run lint","release":"standard-version -a","coveralls":"nyc report --reporter=text-lcov | coveralls","prerelease":"npm run contributors","postrelease":"npm run release:tags && npm run release:github && (ci-publish || npm publish --access=public)","contributors":"(npx git-authors-cli && npx finepack && git add package.json && git commit -m 'build: contributors' --no-verify) || true","release:tags":"git push --follow-tags origin HEAD:master","release:github":"github-generate-release"},"version":"1.0.18","_npmUser":{"name":"kikobeats","email":"josefrancisco.verdu@gmail.com"},"homepage":"https://github.com/Kikobeats/json-stringify-deterministic","keywords":["canonical","deterministic","digest","hash","json","keys","serialize","sort","stable","stringify"],"standard":{"globals":["describe","it"]},"commitlint":{"rules":{"body-max-line-length":[0]},"extends":["@commitlint/config-conventional"]},"repository":{"url":"git+https://github.com/kikobeats/json-stringify-deterministic.git","type":"git"},"_npmVersion":"11.19.0","description":"Deterministic JSON.stringify with sorted keys for consistent hashes and stable cache keys.","directories":{},"maintainers":[{"name":"kikobeats","email":"josefrancisco.verdu@gmail.com"}],"nano-staged":{"*.js":["npx @kikobeats/prettier-standard","standard --fix"],"*.md":["standard-markdown"],"package.json":["finepack"]},"_nodeVersion":"24.21.0","contributors":[],"_hasShrinkwrap":false,"devDependencies":{"c8":"latest","mocha":"latest","should":"latest","finepack":"latest","standard":"latest","ci-publish":"latest","nano-staged":"latest","@commitlint/cli":"latest","git-authors-cli":"latest","simple-git-hooks":"latest","standard-version":"latest","standard-markdown":"latest","github-generate-release":"latest","@commitlint/config-conventional":"latest"},"simple-git-hooks":{"commit-msg":"npx commitlint --edit","pre-commit":"npx nano-staged"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/json-stringify-deterministic_1.0.18_1791875687810_0.2692824473850346"},"readme":"# json-stringify-deterministic\n\n[![Last version](https://img.shields.io/github/v/tag/Kikobeats/json-stringify-deterministic?style=flat-square)](https://github.com/Kikobeats/json-stringify-deterministic/releases)\n[![Coverage Status](https://img.shields.io/coverallsCoverage/github/Kikobeats/json-stringify-deterministic?style=flat-square)](https://coveralls.io/github/Kikobeats/json-stringify-deterministic)\n[![NPM Status](https://img.shields.io/npm/dm/json-stringify-deterministic?style=flat-square)](https://www.npmjs.com/package/json-stringify-deterministic)\n\n> Deterministic version of `JSON.stringify()`, so you can get a consistent hash from stringified results.\n\nSimilar to [json-stable-stringify](https://github.com/substack/json-stable-stringify) *but*:\n\n- No Dependencies. Minimal as possible.\n- Better cycles detection.\n- Support serialization for object without `.toJSON` (such as `RegExp`).\n- Provides built-in TypeScript declarations.\n\n## Install\n\n```bash\nnpm install json-stringify-deterministic --save\n```\n\n## Usage\n\n```js\nconst stringify = require('json-stringify-deterministic')\nconst obj = { c: 8, b: [{ z: 6, y: 5, x: 4 }, 7], a: 3 }\n\nconsole.log(stringify(obj))\n// => {\"a\":3,\"b\":[{\"x\":4,\"y\":5,\"z\":6},7],\"c\":8}\n```\n\n## API\n\n### stringify(&lt;obj&gt;, [opts])\n\n#### obj\n\n*Required*<br>\nType: `object`\n\nThe input `object` to be serialized.\n\n#### opts\n\n##### opts.stringify\n\nType: `function`\nDefault: `JSON.stringify`\n\nDeterminate how to stringify primitives values.\n\n##### opts.cycles\n\nType: `boolean`\nDefault: `false`\n\nDeterminate how to resolve cycles.\n\nUnder `true`, when a cycle is detected, `[Circular]` will be inserted in the node.\n\n##### opts.compare\n\nType: `function`\n\nCustom comparison function for object keys.\n\nYour function `opts.compare` is called with these parameters:\n\n``` js\nopts.cmp({ key: akey, value: avalue }, { key: bkey, value: bvalue })\n```\n\nFor example, to sort on the object key names in reverse order you could write:\n\n``` js\nconst stringify = require('json-stringify-deterministic')\n\nconst obj = { c: 8, b: [{z: 6,y: 5,x: 4}, 7], a: 3 }\nconst objSerializer = stringify(obj, function (a, b) {\n  return a.key < b.key ? 1 : -1\n})\n\nconsole.log(objSerializer)\n// => {\"c\":8,\"b\":[{\"z\":6,\"y\":5,\"x\":4},7],\"a\":3}\n```\n\nOr if you wanted to sort on the object values in reverse order, you could write:\n\n```js\nconst stringify = require('json-stringify-deterministic')\n\nconst obj = { d: 6, c: 5, b: [{ z: 3, y: 2, x: 1 }, 9], a: 10 }\nconst objtSerializer = stringify(obj, function (a, b) {\n  return a.value < b.value ? 1 : -1\n})\n\nconsole.log(objtSerializer)\n// => {\"d\":6,\"c\":5,\"b\":[{\"z\":3,\"y\":2,\"x\":1},9],\"a\":10}\n```\n\n##### opts.space\n\nType: `string`<br>\nDefault: `''`\n\nIf you specify `opts.space`, it will indent the output for pretty-printing.\n\nValid values are strings (e.g. `{space: \\t}`). For example:\n\n```js\nconst stringify = require('json-stringify-deterministic')\n\nconst obj = { b: 1, a: { foo: 'bar', and: [1, 2, 3] } }\nconst objSerializer = stringify(obj, { space: '  ' })\nconsole.log(objSerializer)\n// => {\n//   \"a\": {\n//     \"and\": [\n//       1,\n//       2,\n//       3\n//     ],\n//     \"foo\": \"bar\"\n//   },\n//   \"b\": 1\n// }\n```\n\n##### opts.replacer\n\nType: `function`<br>\n\nThe replacer parameter is a function `opts.replacer(key, value)` that behaves\nthe same as the replacer\n[from the core JSON object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_native_JSON#The_replacer_parameter).\n\n## Related\n\n- [sort-keys-recursive](https://github.com/Kikobeats/sort-keys-recursive): Sort the keys of an array/object recursively.\n\n## License\n\nMIT © [Kiko Beats](https://github.com/Kikobeats).\n","publish_time":1791875687890,"_cnpm_publish_time":1791875687890,"dist-tags":{"latest":"1.0.18"}}