{"name":"json-stable-stringify","version":"1.2.1","description":"deterministic JSON.stringify() with custom sorting to get deterministic hashes from stringified results","main":"index.js","scripts":{"prepack":"npmignore --auto --commentLines=autogenerated","prepublishOnly":"safe-publish-latest","prepublish":"not-in-publish || npm run prepublishOnly","lint":"eslint --ext=js,mjs .","postlint":"tsc && attw -P","pretest":"npm run lint","tests-only":"tape 'test/**/*.js'","test":"npm run tests-only","posttest":"npx npm@'>= 10.2' audit --production","version":"auto-changelog && git add CHANGELOG.md","postversion":"auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""},"repository":{"type":"git","url":"git://github.com/ljharb/json-stable-stringify.git"},"keywords":["json","stringify","deterministic","hash","sort","stable"],"author":{"name":"James Halliday","email":"mail@substack.net","url":"http://substack.net"},"license":"MIT","bugs":{"url":"https://github.com/ljharb/json-stable-stringify/issues"},"homepage":"https://github.com/ljharb/json-stable-stringify","funding":{"url":"https://github.com/sponsors/ljharb"},"dependencies":{"call-bind":"^1.0.8","call-bound":"^1.0.3","isarray":"^2.0.5","jsonify":"^0.0.1","object-keys":"^1.1.1"},"devDependencies":{"@arethetypeswrong/cli":"^0.17.2","@ljharb/eslint-config":"^21.1.1","@ljharb/tsconfig":"^0.2.2","@types/call-bind":"^1.0.5","@types/isarray":"^2.0.3","@types/object-keys":"^1.0.3","@types/tape":"^5.8.0","auto-changelog":"^2.5.0","encoding":"^0.1.13","eslint":"=8.8.0","in-publish":"^2.0.1","npmignore":"^0.3.1","safe-publish-latest":"^2.0.0","tape":"^5.9.0","typescript":"next"},"engines":{"node":">= 0.4"},"testling":{"files":"test/*.js"},"auto-changelog":{"output":"CHANGELOG.md","template":"keepachangelog","unreleased":false,"commitLimit":false,"backfillLimit":false,"hideCredit":true},"publishConfig":{"ignore":[".github/workflows","types"]},"_id":"json-stable-stringify@1.2.1","gitHead":"cbe368f21cc3da54f9567587ed97211d54f29c4e","types":"./index.d.ts","_nodeVersion":"23.5.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-Lp6HbbBgosLmJbjx0pBLbgvx68FaFU1sdkmBuckmhhJ88kL13OA51CDtR2yJB50eCNMH9wRqtQNNiAqQH4YXnA==","shasum":"addb683c2b78014d0b78d704c2fcbdf0695a60e2","tarball":"http://registry-npm.ywwl.com/json-stable-stringify/download/json-stable-stringify-1.2.1.tgz","fileCount":19,"unpackedSize":34695,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIF4VPfpZJ6jlQTkIP3ucHovIK/s5zOUeHZi3jOvjVCrZAiEA/9u42vekgNU0l6Nvc9EQfg2fm6ccuZKZPqOcLBJAjD0="}],"size":11398,"noattachment":false,"key":"/json-stable-stringify/-/json-stable-stringify-1.2.1.tgz"},"_npmUser":{"name":"ljharb","email":"ljharb@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/json-stable-stringify_1.2.1_1734818063068_0.00039311129779218135"},"_hasShrinkwrap":false,"readme":"# json-stable-stringify <sup>[![Version Badge][npm-version-svg]][package-url]</sup>\n\n[![github actions][actions-image]][actions-url]\n[![coverage][codecov-image]][codecov-url]\n[![License][license-image]][license-url]\n[![Downloads][downloads-image]][downloads-url]\n\n[![npm badge][npm-badge-png]][package-url]\n\ndeterministic version of `JSON.stringify()` so you can get a consistent hash from stringified results\n\nYou can also pass in a custom comparison function.\n\n# example\n\n``` js\nconst stringify = require('json-stable-stringify');\n\nconst obj = { c: 8, b: [{ z: 6, y: 5, x: 4 }, 7], a: 3 };\n\nconsole.log(stringify(obj));\n```\n\noutput:\n\n```\n{\"a\":3,\"b\":[{\"x\":4,\"y\":5,\"z\":6},7],\"c\":8}\n```\n\n# methods\n\n``` js\nconst stringify = require('json-stable-stringify')\n```\n\n<a id=\"var-str--stringifyobj-opts\"></a>\n## const str = stringify(obj, opts)\n\nReturn a deterministic stringified string `str` from the object `obj`.\n\n## options\n\n### cmp\n\nIf `opts` is given, you can supply an `opts.cmp` to have a custom comparison function for object keys.\nYour function `opts.cmp` is called with these parameters:\n\n``` js\nopts.cmp({ key: akey, value: avalue }, { key: bkey, value: bvalue }, { get(key): value })\n```\n\nFor example, to sort on the object key names in reverse order you could write:\n\n``` js\nconst stringify = require('json-stable-stringify');\n\nconst obj = { c: 8, b: [{ z: 6, y: 5, x: 4 },7], a: 3 };\n\nconst s = stringify(obj, function (a, b) {\n\treturn b.key.localeCompare(a.key);\n});\n\nconsole.log(s);\n```\n\nwhich results in the output string:\n\n``` js\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-stable-stringify');\n\nconst obj = { d: 6, c: 5, b: [{ z: 3, y: 2, x: 1 }, 9], a: 10 };\n\nconst s = stringify(obj, function (a, b) {\n\treturn a.value < b.value ? 1 : -1;\n});\n\nconsole.log(s);\n```\n\nwhich outputs:\n\n``` js\n{\"d\":6,\"c\":5,\"b\":[{\"z\":3,\"y\":2,\"x\":1},9],\"a\":10}\n```\n\nAn additional param `get(key)` returns the value of the key from the object being currently compared.\n\n### space\n\nIf you specify `opts.space`, it will indent the output for pretty-printing.\nValid values are strings (e.g. `{space: \\t}`) or a number of spaces\n(`{space: 3}`).\n\nFor example:\n\n```js\nconst obj = { b: 1, a: { foo: 'bar', and: [1, 2, 3] } };\n\nconst s = stringify(obj, { space: '  ' });\n\nconsole.log(s);\n```\n\nwhich outputs:\n\n```\n{\n  \"a\": {\n    \"and\": [\n      1,\n      2,\n      3\n    ],\n    \"foo\": \"bar\"\n  },\n  \"b\": 1\n}\n```\n\n### replacer\n\nThe replacer parameter is a function `opts.replacer(key, value)` that behaves the 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# install\n\nWith [npm](https://npmjs.org) do:\n\n```\nnpm install json-stable-stringify\n```\n\n# license\n\nMIT\n\n[package-url]: https://npmjs.org/package/json-stable-stringify\n[npm-version-svg]: https://versionbadg.es/ljharb/json-stable-stringify.svg\n[deps-svg]: https://david-dm.org/ljharb/json-stable-stringify.svg\n[deps-url]: https://david-dm.org/ljharb/json-stable-stringify\n[dev-deps-svg]: https://david-dm.org/ljharb/json-stable-stringify/dev-status.svg\n[dev-deps-url]: https://david-dm.org/ljharb/json-stable-stringify#info=devDependencies\n[npm-badge-png]: https://nodei.co/npm/json-stable-stringify.png?downloads=true&stars=true\n[license-image]: https://img.shields.io/npm/l/json-stable-stringify.svg\n[license-url]: LICENSE\n[downloads-image]: https://img.shields.io/npm/dm/json-stable-stringify.svg\n[downloads-url]: https://npm-stat.com/charts.html?package=json-stable-stringify\n[codecov-image]: https://codecov.io/gh/ljharb/json-stable-stringify/branch/main/graphs/badge.svg\n[codecov-url]: https://app.codecov.io/gh/ljharb/json-stable-stringify/\n[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/json-stable-stringify\n[actions-url]: https://github.com/ljharb/json-stable-stringify/actions\n","publish_time":1734818063279,"maintainers":[{"name":"ljharb","email":"ljharb@gmail.com"}],"_cnpm_publish_time":1734818063279,"dist-tags":{"latest":"1.3.0"}}