125 lines
7.9 KiB
JSON
125 lines
7.9 KiB
JSON
{
|
|
"_args": [
|
|
[
|
|
{
|
|
"raw": "safe-json-stringify@~1",
|
|
"scope": null,
|
|
"escapedName": "safe-json-stringify",
|
|
"name": "safe-json-stringify",
|
|
"rawSpec": "~1",
|
|
"spec": ">=1.0.0 <2.0.0",
|
|
"type": "range"
|
|
},
|
|
"/Volumes/2009-SSD/GT2/GT2-iOS/node_modules/@expo/bunyan"
|
|
]
|
|
],
|
|
"_from": "safe-json-stringify@>=1.0.0 <2.0.0",
|
|
"_id": "safe-json-stringify@1.0.4",
|
|
"_inCache": true,
|
|
"_location": "/safe-json-stringify",
|
|
"_nodeVersion": "6.7.0",
|
|
"_npmOperationalInternal": {
|
|
"host": "packages-18-east.internal.npmjs.com",
|
|
"tmp": "tmp/safe-json-stringify-1.0.4.tgz_1488293228348_0.7028744479175657"
|
|
},
|
|
"_npmUser": {
|
|
"name": "jonatanpedersen",
|
|
"email": "jp@jonatanpedersen.com"
|
|
},
|
|
"_npmVersion": "3.10.8",
|
|
"_phantomChildren": {},
|
|
"_requested": {
|
|
"raw": "safe-json-stringify@~1",
|
|
"scope": null,
|
|
"escapedName": "safe-json-stringify",
|
|
"name": "safe-json-stringify",
|
|
"rawSpec": "~1",
|
|
"spec": ">=1.0.0 <2.0.0",
|
|
"type": "range"
|
|
},
|
|
"_requiredBy": [
|
|
"/@expo/bunyan"
|
|
],
|
|
"_resolved": "https://registry.npmjs.org/safe-json-stringify/-/safe-json-stringify-1.0.4.tgz",
|
|
"_shasum": "81a098f447e4bbc3ff3312a243521bc060ef5911",
|
|
"_shrinkwrap": null,
|
|
"_spec": "safe-json-stringify@~1",
|
|
"_where": "/Volumes/2009-SSD/GT2/GT2-iOS/node_modules/@expo/bunyan",
|
|
"author": {
|
|
"name": "Debitoor"
|
|
},
|
|
"bugs": {
|
|
"url": "https://github.com/debitoor/safe-json-stringify/issues"
|
|
},
|
|
"dependencies": {},
|
|
"description": "Prevent defined property getters from throwing errors",
|
|
"devDependencies": {
|
|
"tape": "4.6.3"
|
|
},
|
|
"directories": {},
|
|
"dist": {
|
|
"shasum": "81a098f447e4bbc3ff3312a243521bc060ef5911",
|
|
"tarball": "https://registry.npmjs.org/safe-json-stringify/-/safe-json-stringify-1.0.4.tgz"
|
|
},
|
|
"gitHead": "a757cb33c792531b9c04635e3c995aed2a5691bf",
|
|
"homepage": "https://github.com/debitoor/safe-json-stringify",
|
|
"license": "MIT",
|
|
"main": "index.js",
|
|
"maintainers": [
|
|
{
|
|
"name": "gausby",
|
|
"email": "martin@gausby.dk"
|
|
},
|
|
{
|
|
"name": "ebdrup",
|
|
"email": "allan@878.dk"
|
|
},
|
|
{
|
|
"name": "bubenshchykov",
|
|
"email": "a.bubenshchykov@gmail.com"
|
|
},
|
|
{
|
|
"name": "eagleeye",
|
|
"email": "eagleeyes91@gmail.com"
|
|
},
|
|
{
|
|
"name": "kapetan",
|
|
"email": "mirza.kapetanovic@gmail.com"
|
|
},
|
|
{
|
|
"name": "wtfil",
|
|
"email": "evgen.filatov@gmail.com"
|
|
},
|
|
{
|
|
"name": "bifrost",
|
|
"email": "dan@steenbjerg.com"
|
|
},
|
|
{
|
|
"name": "mpushkin",
|
|
"email": "mfbeast@mail.ru"
|
|
},
|
|
{
|
|
"name": "jonatanpedersen",
|
|
"email": "jp@jonatanpedersen.com"
|
|
},
|
|
{
|
|
"name": "fizker",
|
|
"email": "benjamin@fizkerinc.dk"
|
|
}
|
|
],
|
|
"name": "safe-json-stringify",
|
|
"optionalDependencies": {},
|
|
"readme": "# Safe JSON Stringify\n[![Build Status](https://travis-ci.org/debitoor/safe-json-stringify.svg?branch=master)](https://travis-ci.org/debitoor/safe-json-stringify)\n[![NPM Version](https://img.shields.io/npm/v/safe-json-stringify.svg)](https://www.npmjs.com/package/safe-json-stringify)\n\nA wrapper for `JSON.stringify` that handles circular references and prevent defined getters from throwing errors.\n\nCircular references are handled by returning `[Circular]` when a circular reference is spotted.\n\nDefined getters that throws errors are handled by returning `[Throws]`.\n\nUsage\n-----\nInstall it using NPM\n\n```sh\nnpm install safe-json-stringify\n```\n\nAnd require it into your Node project.\n\n```js\nconst safeJsonStringify = require('safe-json-stringify');\nconst data = {foo: 'bar'}\n\nconsole.log(safeJsonStringify(data));\n```\n\nAn `ensureProperties` function is exposed too, which returns a safe object without the stringify step. Usage: `safeJsonStringify.ensureProperties(data);`.\n\n\nWhy?\n----\nThe `stringify` function on the JavaScript JSON object will take any data and return a string representation of said data. If this data contains an object literal it will attempt to return the values of any enumerable property set on this object. This can be dangerous because JavaScript support a couple of ways to define property getters on objects.\n\nThe old, non-standard, and now deprecated `Object.prototype.__defineGetter__()` will define a named property which value is the return of a given function.\n\n```js\n// Never ever do this in your code. Please.\nvar obj = {};\nobj.__defineGetter__('foo', function() { return 'bar'; });\n\nJSON.stringify(obj); // {\"foo\":\"bar\"}\n```\n\nThis is kinda bad, because we could make that function throw an error.\n\n```js\n// Never ever do this in your code. Please.\nvar obj = {};\nobj.__defineGetter__('foo', function() { throw new Error('ouch!'); });\n\nJSON.stringify(obj); // error thrown\n```\n\nThis property is created as an enumerable on the object, so the object from the previous example would make any function that iterate choke and throw an error. This is bad because one would never expect a simple property get to throw an error and bring down a system.\n\n`JSON.stringify` will blindly trust any object property, and will throw an error if it hits a defined property that throws an error. This could potentially take down your program.\n\nThe slightly better `Object.defineProperty()` does the same thing, but has the common courtesy to not define the getter as enumerable--that is pr default. The following example would bring us in the same situation as with `__defineGetter__`.\n\n```js\n// Never ever do this in your code. Please.\nvar obj = {};\nObject.defineProperty(obj, 'foo', {\n get: function() { throw new Error('ouch!'); },\n\tenumerable: true // enumerable is false by default\n});\n\nJSON.stringify(obj); // error thrown\n```\n\nSo, we can not trust any of them. One could argue that they should never be used, and we can, and should, apply that principle to our own software, but we cannot trust code from third party modules. If data from third party modules are to be stringified by JSON we should take these situations into considerations. This module attempt to do that by spotting defined getters and return \"[Throws]\" if said getter throws an error.\n\n```js\nvar safeJsonStringify = require('safe-json-stringify');\n// Never ever do this in your code. Please.\nvar obj = {};\nObject.defineProperty(obj, 'foo', {\n get: function() { throw new Error('ouch!'); },\n\tenumerable: true\n});\n\nsafeJsonStringify(obj); // '{\"foo\":\"[Throws]\"}'\n```\n\nAnd it attempt to handle circular references too. It returns \"[Circular]\" if it spots one.\n\n\nLicense\n-------\nThe MIT License (MIT)\n\nCopyright (c) 2014-2017 [Debitoor](https://debitoor.com/)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n",
|
|
"readmeFilename": "README.md",
|
|
"repository": {
|
|
"type": "git",
|
|
"url": "git+ssh://git@github.com/debitoor/safe-json-stringify.git"
|
|
},
|
|
"scripts": {
|
|
"postversion": "git push && git push --tags",
|
|
"preversion": "npm test",
|
|
"test": "tape test/safe-json-stringify-test.js"
|
|
},
|
|
"version": "1.0.4"
|
|
}
|