{"_id":"@anyhowstep/json-recursive","_rev":"2-157f0fc2a092b1f073a913b11ec5c197","name":"@anyhowstep/json-recursive","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@anyhowstep/json-recursive","version":"1.0.0","description":"stringify() and parse() recursive objects","main":"dist/src/main/index.js","types":"dist/src/main/index.d.ts","scripts":{"test":"ts-node","test-all":"ts-node ./src/test/test-all.ts","build":"(rm -r ./dist || true) && tsc -d --diagnostics"},"author":{"name":"anyhowstep"},"license":"ISC","repository":{"type":"git","url":"git+https://github.com/AnyhowStep/json-recursive.git"},"dependencies":{"schema-decorator":"^2.38.0"},"devDependencies":{"@types/tape":"^4.2.32","tape":"^4.9.1","ts-node":"^7.0.1","typescript":"^3.0.1"},"gitHead":"5182d70d46120b20015c59c24aaef829f9ee126a","bugs":{"url":"https://github.com/AnyhowStep/json-recursive/issues"},"homepage":"https://github.com/AnyhowStep/json-recursive#readme","_id":"@anyhowstep/json-recursive@1.0.0","_npmVersion":"5.3.0","_nodeVersion":"6.11.0","_npmUser":{"name":"anyhowstep","email":"justin.ng.1994@outlook.com"},"dist":{"integrity":"sha512-6KuJdRKS50w0yKjmxFvEPVYgqqwAQEdES4ULSkwblcltwiOQSUFIC31jtGRTFJTdWAhCl7w7MsimM0yMwg68kQ==","shasum":"34bf1fcb9a657b940076acbdf005b9e47ff27496","tarball":"https://registry.npmjs.org/@anyhowstep/json-recursive/-/json-recursive-1.0.0.tgz","fileCount":11,"unpackedSize":31111,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbkuW2CRA9TVsSAnZWagAAf88P/j+tAGo4fFC/Y37HTzID\niDMXxExCt+iXegl9V42YmzOw1UNekWvaYYaRKn1jEiIYKXHUvt//aXxiodhV\nFCri53+b1BRHqwBvQCANvUGvEKtHFuovDcokvePiFcI9n7kuLGsioBvWeR/o\njiM+ocf+1UbRNQRdHfa8YdkclggdnaMBhpnELuZ7wSxOcEGkpHyhQIP/HWPu\n48pTcS7uAGwg0N8DUdnT3BpgCqLiOaM3J3H7FOPZsStxGrVNjSziYzdPDZmc\nO//SPtC8r+B6kMniPxfxCFGIMLNzA5xbc/0GGZt0TyiIhA2ZTWZXvbEoCuqz\nnw4kqixcGIsmJjVLZzVxLoTjA6rPC4NU29boIzYjtylasgkGuszusWm2dJGO\neuwmGt/WYukGD2YoNZxrN8+fFbC8letpXNZlYbeRPg+oUTpgBt3bL+o9uJbk\nKDbIZrUnZdoN/4Lj3EShccq60xSj+H/5EE39AR5shuwhuWEkJpRZTyvurEFv\nkZHAc5hYt4Z4qGuQBjdla+ylBSHl/6p4qCU+AYlO2GktsVJ8cWE5wSrBJynv\nLnN5OxQrO3ygNyQmf2evP6+cZCYuv6NN/2qVVOgf9v3O8hz3kUl/ThEzX2X9\np84QFyQ2flP6hNfcJqqoiScg60/HRK8sEtzLslh4XTcYZKvY/dJZW4xYd2Ss\nNiTQ\r\n=ZAuO\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFYYWmTiBnOK0XkkqoBHJiO2clrYyXB29RN78IGoXzmcAiEA4XF/OcQkJxgGVuRlde7A2jq+vSTvH8YoZFPyPkQ0rrs="}]},"maintainers":[{"name":"anyhowstep","email":"justin.ng.1994@outlook.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/json-recursive_1.0.0_1536353718042_0.27248425027539924"},"_hasShrinkwrap":false},"1.0.1":{"name":"@anyhowstep/json-recursive","version":"1.0.1","description":"stringify() and parse() recursive objects","main":"dist/src/main/index.js","types":"dist/src/main/index.d.ts","scripts":{"test":"ts-node","test-all":"ts-node ./src/test/test-all.ts","build":"(rm -r ./dist || true) && tsc -d --diagnostics"},"author":{"name":"anyhowstep"},"license":"ISC","repository":{"type":"git","url":"git+https://github.com/AnyhowStep/json-recursive.git"},"dependencies":{"schema-decorator":"^2.38.0"},"devDependencies":{"@types/tape":"^4.2.32","tape":"^4.9.1","ts-node":"^7.0.1","typescript":"^3.0.1"},"gitHead":"154e025136fa1d9290abc4eb396a54011f15c554","bugs":{"url":"https://github.com/AnyhowStep/json-recursive/issues"},"homepage":"https://github.com/AnyhowStep/json-recursive#readme","_id":"@anyhowstep/json-recursive@1.0.1","_npmVersion":"5.3.0","_nodeVersion":"6.11.0","_npmUser":{"name":"anyhowstep","email":"justin.ng.1994@outlook.com"},"dist":{"integrity":"sha512-Zon5RVJr1jxQR3/BfAxH1TM2gYWpVS+qrgrucayeQi037Wyr8t18noYPp6ga2w3vGjeKXwRZk0cXc4/hCfiw9w==","shasum":"9cfcb6245e8a5fa9c9890680270db4406626d426","tarball":"https://registry.npmjs.org/@anyhowstep/json-recursive/-/json-recursive-1.0.1.tgz","fileCount":11,"unpackedSize":31126,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbkudoCRA9TVsSAnZWagAAKwsP/RcFPeZnucB4D+Ef9dQT\ne3HHEAeLSW1sprg3eNzK3FWWh3Wk5wZiVuKGUlNzhWc7ivpf7DVeMVJXWrCe\ngPoSfv2rGfIwMCexb/3XDQeeJsW9+5jNFXeSg82HUoL68pOLL0AwWZ6ycw/r\n1jIG1fiY9U3Sra09aITxm3rEnf9xjFLoR9slySuTzMw/q7SYH8Ap+qxF9Abg\neJg0oPLCoqsq7/cT1w8wQai6e534Y6TjkmeGEbctul4IuIO4DBToDdib4iJI\nZcRrN17dtYRZFSlc8CDWOQB3LXw64EhwrZnPDVvcGJwFkDoGFhfIQTcAMdXw\ncOJ9kpysLfThre8D2d/sCEJcAksFJpfUTgF3LQ1wnU3ZmctgEB85bEv6uQL/\n4jor1DIngFa2D5SKgDivHBATvyB/4bq6iGw579339PKBuMBIN4Zkjv89uok8\nTCRZpd9jL5FKPLzUQeA7nJvBV87mELlCcx8jBa7uYgzrDkKdbw9XaeuqezVj\nDycHNv3rim6kRhmAjJNHBW+hBSZgfyM0XFZJ2v4nOHUhB7Vz5H2pJ0wEQFFp\n+ROgxGk7KWIgkPoDlh8aDO66UndrVwdofdESlHwPCSr77hwlvBCqag/F2Dnt\npDclfHfP84bAlNJtwwlv6/RmcNmPvbTVjFwbt6JjFVLEQYaI+4vRLF8DXSEL\naMd+\r\n=Dl2+\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCFJFziB/kRuQ+5Yv3R5jw8LZPsNi62HD7h4KXX5RpyLQIhAP2zYF/tJ/Yf7TznDrz10gweJJYfAf88apcXcx33/tpL"}]},"maintainers":[{"name":"anyhowstep","email":"justin.ng.1994@outlook.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/json-recursive_1.0.1_1536354151635_0.2917412682130771"},"_hasShrinkwrap":false}},"time":{"created":"2018-09-07T20:55:17.878Z","1.0.0":"2018-09-07T20:55:18.150Z","modified":"2022-04-04T14:27:00.285Z","1.0.1":"2018-09-07T21:02:31.769Z"},"maintainers":[{"name":"anyhowstep","email":"justin.ng.1994@outlook.com"}],"description":"stringify() and parse() recursive objects","homepage":"https://github.com/AnyhowStep/json-recursive#readme","repository":{"type":"git","url":"git+https://github.com/AnyhowStep/json-recursive.git"},"author":{"name":"anyhowstep"},"bugs":{"url":"https://github.com/AnyhowStep/json-recursive/issues"},"license":"ISC","readme":"# `json-recursive`\n\nYet-another-recursive-`JSON.stringify()`-implementation.\n\n-----\n\n### Install\n\n`npm install --save @anyhowstep/json-recursive`\n\n-----\n\n### Test\n\n`npm run test-all`\n\n-----\n\n### Build\n\n`npm run build`\n\n-----\n\n### Basic Usage (`stringify()`, `parse()`)\n\n```ts\nimport * as json from \"@anyhowstep/json-recursive\";\n\nconst x : any = {};\nconst y : any = {};\nx.y = y;\ny.x = x;\n\n//{\"y\":{\"x\":{\"$recursive\":[]}}}\nconst str = json.stringify(x);\n//`obj` has same structure as `x`\nconst obj = json.parse(str);\n```\n\n```ts\nimport * as json from \"@anyhowstep/json-recursive\";\n\nconst arr : any[] = [];\narr.push(arr);\n\n//[{\"$recursive\":[]}]\nconst str = json.stringify(arr);\n//`obj` has same structure as `arr`\nconst obj = json.parse(str);\n```\n\n```ts\nimport * as json from \"@anyhowstep/json-recursive\";\n\nconst x : any = {};\nx.y = {};\nx.z = {};\nx.y.z = x.z;\nx.z.y = x.y;\nx.x = x;\n\n//{\"y\":{\"z\":{\"y\":{\"$recursive\":[\"y\"]}}},\"z\":{\"$recursive\":[\"y\",\"z\"]},\"x\":{\"$recursive\":[]}}\nconst str = json.stringify(x);\n//`obj` has same structure as `x`\nconst obj = json.parse(str);\n```\n\n```ts\nimport * as json from \"@anyhowstep/json-recursive\";\n\nconst x : any = {};\nx.x = x;\nx.date = new Date();\n\n//{\"x\":{\"$recursive\":[]},\"date\":\"2018-09-07T20:23:46.427Z\"}\nconst str = json.stringify(x);\n//`obj` has same structure as `x`\n//But `obj.date` is of type `string`\n//because JSON.stringify() does that.\nconst obj = json.parse(str);\n```\n\n`stringify()` may return `undefined`; particularly, `JSON.stringify(undefined)`.\n\n`stringifyOrError()` will return `string` or throw an `Error`.\n\n-----\n\n### Caveats\n\nAs you can see, recursive objects have the structure,\n\n```ts\n{ $recursive : string[] }\n```\n\nTherefore, in general `$recursive` is a reserved field.\n\n`TODO: Maybe allow one to set the field to use for recursion?`\n\n-----\n\n### `ReplacerDelegate`\n\n`stringify()` allows you to use a `ReplacerDelegate`.\n\n```ts\nexport type ReplacerDelegate = (this : any, key : string, value : any) => any;\n```\n\n```ts\nimport * as json from \"@anyhowstep/json-recursive\";\n//`json.includeError` is a replacer delegate\n//that stringifies instances of `Error`.\n//Normally, instances of `Error` get stringified to empty objects.\n\nconst x : any = {};\nx.x = x;\nx.error = new Error(\"This is a test message\");\n\n//{\"x\":{\"$recursive\":[]},\"error\":{\"name\":\"Error\",\"message\":\"This is a test message\",\"stack\":\"Error: This is a test message\\n    at Test.tape\"}}\nconst str = json.stringify(x, json.includeError);\n//`obj` has same structure as `x`\n//But `obj.error` is not an instance of `Error`\nconst obj = json.parse(str);\n```\n\n```ts\nimport * as json from \"@anyhowstep/json-recursive\";\n//`json.ignoreLeadingUnderscoreKey` is a replacer delegate\n//that ignores keys beginning with underscores.\n\nconst x : any = {};\nx._x = x;\nx.y = {\n    x : x,\n    _x : x,\n};\n\n//{\"y\":{\"x\":{\"$recursive\":[]}}}\nconst str = json.stringify(x, json.ignoreLeadingUnderscoreKey);\n//`obj` has same structure as `x`\n//But `obj._x` does not exist\n//and `obj.y._x` does not exist\nconst obj = json.parse(str);\n```\n\n-----\n\n### Chaining Replacers\n\n`ReplacerDelegate`s may be chained.\n\n```ts\nconst str = json.stringifyOrError(x, json.chainReplacers(\n    json.includeError,\n    json.ignoreLeadingUnderscoreKey\n));\n```","readmeFilename":"README.md"}