{"_id":"cryo","_rev":"16-2057fa86155f5d68bca5c5f257582587","name":"cryo","description":"Easily pickle/serialize/freeze/store and re-hydrate complex JavaScript objects (including Functions)","dist-tags":{"latest":"0.0.6"},"versions":{"0.0.1":{"name":"cryo","version":"0.0.1","description":"Easily pickle/serialize/freeze/store and re-hydrate complex JavaScript objects (including Functions)","keywords":["pickle","serialize","store","hydrate","freeze","json"],"author":{"name":"Hunter Loftis","email":"hunter@hunterloftis.com"},"repository":{"type":"git","url":"git@github.com:hunterloftis/cryo.git"},"main":"./lib/cryo.js","engines":{"node":">= 0.4.x"},"dependencies":{"mocha":"~1.7.4","chai":"~1.4.2"},"_id":"cryo@0.0.1","dist":{"shasum":"87e907a5c27dddca3b9b27be81455bd57e666759","tarball":"https://registry.npmjs.org/cryo/-/cryo-0.0.1.tgz","integrity":"sha512-BunMaMfqMBrMVz8du0VBMJE7HxnDs9cR2JhOY5TB3myajY3quvcyjOqtMSd9OIjoQcnIo+77jPyZwjWb1LnFkQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAvRjMaG/LUXivPRAMU44N+EBZ/qq5f6RZvIuiSYpp8qAiAEf1jAyumgyZlHVN/WESq+RmKhdTkVHw8pjHO2851kEQ=="}]},"_npmVersion":"1.1.62","_npmUser":{"name":"hunterloftis","email":"hunter@hunterloftis.com"},"maintainers":[{"name":"hunterloftis","email":"hunter@hunterloftis.com"}]},"0.0.2":{"name":"cryo","version":"0.0.2","description":"Easily pickle/serialize/freeze/store and re-hydrate complex JavaScript objects (including Functions)","keywords":["pickle","serialize","store","hydrate","freeze","json"],"author":{"name":"Hunter Loftis","email":"hunter@hunterloftis.com"},"repository":{"type":"git","url":"git@github.com:hunterloftis/cryo.git"},"main":"./lib/cryo.js","engines":{"node":">= 0.4.x"},"dependencies":{"mocha":"~1.7.4","chai":"~1.4.2"},"_id":"cryo@0.0.2","dist":{"shasum":"a19766ad0413de0c723e73a0b904e9408d768113","tarball":"https://registry.npmjs.org/cryo/-/cryo-0.0.2.tgz","integrity":"sha512-lIWKfPZMNXhyLHgMFc5wngQ2QaURQNqEg9bBEwl08tvGUlsd5r2Axr21FRLFfmQxkvFU1d4bW6v02T+mUQA7JQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDqEkly56E956IjmG1/QwXJQUdeL6cByQDAZSdyTJQZmQIgM023PllcDixrpGXRX7QE76R4EmjiSbE8nYTkaUcK0nI="}]},"_npmVersion":"1.1.62","_npmUser":{"name":"hunterloftis","email":"hunter@hunterloftis.com"},"maintainers":[{"name":"hunterloftis","email":"hunter@hunterloftis.com"}]},"0.0.3":{"name":"cryo","version":"0.0.3","description":"Easily pickle/serialize/freeze/store and re-hydrate complex JavaScript objects (including Functions)","keywords":["pickle","serialize","store","hydrate","freeze","json"],"author":{"name":"Hunter Loftis","email":"hunter@hunterloftis.com"},"repository":{"type":"git","url":"git@github.com:hunterloftis/cryo.git"},"main":"./lib/cryo.js","engines":{"node":">= 0.4.x"},"dependencies":{"mocha":"~1.7.4","chai":"~1.4.2"},"_id":"cryo@0.0.3","dist":{"shasum":"1d9151c7707f592592403b8728a2e075d75b49c3","tarball":"https://registry.npmjs.org/cryo/-/cryo-0.0.3.tgz","integrity":"sha512-8oj4BIaYlW4LUjTYFW1UKcw1PNk2emTbyHwI77zJGAdggyk3Dcn0cGk8F9MbzUzR4dFaSjBLBLEBkXt+JfZ+BA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEAkkZLFxs/dQ1lXp/dj1CKCzpqqqh9upOhdOK7NslAXAiEAgn8hBuv/0rJgC6Ui8T1G/4zOG3lVuZp562iO06cVo0w="}]},"_npmVersion":"1.1.62","_npmUser":{"name":"hunterloftis","email":"hunter@hunterloftis.com"},"maintainers":[{"name":"hunterloftis","email":"hunter@hunterloftis.com"}]},"0.0.4":{"name":"cryo","version":"0.0.4","description":"Easily pickle/serialize/freeze/store and re-hydrate complex JavaScript objects (including Functions)","keywords":["pickle","serialize","store","hydrate","freeze","json"],"author":{"name":"Hunter Loftis","email":"hunter@hunterloftis.com"},"repository":{"type":"git","url":"git@github.com:hunterloftis/cryo.git"},"main":"./lib/cryo.js","engines":{"node":">= 0.4.x"},"dependencies":{"mocha":"~1.7.4","chai":"~1.4.2"},"_id":"cryo@0.0.4","dist":{"shasum":"50ffef882a1a09f1fd970f2f1f95df0392f530be","tarball":"https://registry.npmjs.org/cryo/-/cryo-0.0.4.tgz","integrity":"sha512-WVC4utl/aI7GoghkUCeDmR1kSh32bwZWNXVnmp9f1f1GGml3OFWSHVBVXitmdBCzJw41MOf2Vwms6IO/Bx8gEw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIC/etJL67dwu0DPbcb5b7UFqCw/ELabZlx12VxXg/QXeAiEA1OnBXag19VbNUFwHurMJNbhGnZAHZekRXYJcFm06IKY="}]},"_npmVersion":"1.1.62","_npmUser":{"name":"hunterloftis","email":"hunter@hunterloftis.com"},"maintainers":[{"name":"hunterloftis","email":"hunter@hunterloftis.com"}]},"0.0.5":{"name":"cryo","version":"0.0.5","description":"Easily pickle/serialize/freeze/store and re-hydrate complex JavaScript objects (including Functions)","keywords":["pickle","serialize","store","hydrate","freeze","json"],"author":{"name":"Hunter Loftis","email":"hunter@hunterloftis.com"},"repository":{"type":"git","url":"git@github.com:hunterloftis/cryo.git"},"main":"./lib/cryo.js","engines":{"node":">= 0.4.x"},"dependencies":{"mocha":"~1.7.4","chai":"~1.4.2"},"_id":"cryo@0.0.5","dist":{"shasum":"f790eac72765a29db617f354c821bbfc92617383","tarball":"https://registry.npmjs.org/cryo/-/cryo-0.0.5.tgz","integrity":"sha512-Ji7YaYB51NQmsiCXd1ZiUE4I/W1MZPH5cdjzOUolCSO4AwVBSwHuz87al3C7L50O5g9eFWjSfS+aVYElSCbYEQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDosKk+hYrYRjucpOpEyOn3kNH0L3KTZWKHpwgxdJ2oiAIgND4T8FyOY2To0TSqWzAiObRmNmGt0KJNJMV8ly7d8AM="}]},"_npmVersion":"1.1.62","_npmUser":{"name":"hunterloftis","email":"hunter@hunterloftis.com"},"maintainers":[{"name":"hunterloftis","email":"hunter@hunterloftis.com"}]},"0.0.6":{"name":"cryo","version":"0.0.6","description":"Easily pickle/serialize/freeze/store and re-hydrate complex JavaScript objects (including Functions)","keywords":["pickle","serialize","store","hydrate","freeze","json"],"author":{"name":"Hunter Loftis","email":"hunter@hunterloftis.com"},"repository":{"type":"git","url":"git+ssh://git@github.com/hunterloftis/cryo.git"},"main":"./lib/cryo.js","engines":{"node":">= 0.4.x"},"devDependencies":{"mocha":"~1.7.4","chai":"~1.4.2"},"gitHead":"bff8f9d22ce0db01eb08053d028c249d6aa6f0ac","bugs":{"url":"https://github.com/hunterloftis/cryo/issues"},"homepage":"https://github.com/hunterloftis/cryo#readme","_id":"cryo@0.0.6","scripts":{},"_shasum":"16833295d2ee16ff39711db840617b7ae4af0ba4","_from":".","_npmVersion":"2.14.4","_nodeVersion":"4.1.1","_npmUser":{"name":"hunterloftis","email":"hunter@hunterloftis.com"},"maintainers":[{"name":"hunterloftis","email":"hunter@hunterloftis.com"}],"dist":{"shasum":"16833295d2ee16ff39711db840617b7ae4af0ba4","tarball":"https://registry.npmjs.org/cryo/-/cryo-0.0.6.tgz","integrity":"sha512-vSbO1hJvP9oOGXcKHiAj3U37rtErI8jIZ8gOp8EfiQgPncAv6nc4JArGWzqrxlwA5xe6Sph5OUAg//7yqTOyIg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIG0U+AFLu1hkaOqAghlTzQlx3Km1CrgMdm+7Oxr8/eVaAiEA1ooO2mTqhkbdxFvrFQbKvWAkNn2MxNfAeCr6pOMD58w="}]}}},"readme":"# Cryo\n\nJSON on steroids.\n\nBuilt for node.js and browsers. Cryo is inspired by Python's pickle and works similarly to JSON.stringify() and JSON.parse().\nCryo.stringify() and Cryo.parse() improve on JSON in these circumstances:\n\n- [Undefined](#undefined)\n- [Date](#date)\n- [Infinity](#infinity)\n- [Object references](#references)\n- [Attached properties](#properties)\n- [Functions](#functions)\n- [DOM Nodes](#dom)\n\n## Installation\n\n### node.js\n\n```\n$ npm install cryo\n```\n\n### browser\n\nWith Bower:\n\n```\nbower install cryo\n```\n\nAdd the [latest minified build](https://github.com/hunterloftis/cryo/tree/master/build) to your project as a script:\n\n```html\n<script type='text/javascript' src='cryo-0.0.4.js'></script>\n```\n\n## Use\n\nCryo has a very simple API that mimicks JSON:\n\n- `Cryo.stringify(item, [callback])`\n- `Cryo.parse(string, [callback])`\n\n```js\nvar Cryo = require('cryo');\n\nvar obj = {\n  name: 'Hunter',\n  created: new Date(),\n  hello: function() {\n    console.log(this.name + ' said hello in ' + this.created.getFullYear() + '!');\n  }\n};\n\nvar frozen = Cryo.stringify(obj);\nvar hydrated = Cryo.parse(frozen);\n\nhydrated.hello(); // Hunter said hello in 2013!\n```\n\n## More powerful JSON\n\n### Undefined\n\nCryo takes a verbatim snapshot of all your properties, including those that are `undefined` - which JSON ignores.\n\n```js\nvar Cryo = require('../lib/cryo');\n\nvar obj = {\n  defaultValue: undefined\n};\n\nvar withJSON = JSON.parse(JSON.stringify(obj));\nconsole.log(withJSON.hasOwnProperty('defaultValue'));   // false\n\nvar withCryo = Cryo.parse(Cryo.stringify(obj));\nconsole.log(withCryo.hasOwnProperty('defaultValue'));   // true\n```\n\n### Date\n\nCryo successfully works with `Date` objects, which `JSON.stringify()` mangles into strings.\n\n```js\nvar Cryo = require('../lib/cryo');\n\nvar now = new Date();\n\nvar withJSON = JSON.parse(JSON.stringify(now));\nconsole.log(withJSON instanceof Date);              // false\n\nvar withCryo = Cryo.parse(Cryo.stringify(now));\nconsole.log(withCryo instanceof Date);              // true\n```\n\n### References\n\n`JSON.stringify()` makes multiple copies of single objects, losing object relationships.\nWhen several references to the same object are stringified with JSON, those references are turned into clones of each other.\nCryo maintains object references so the restored objects are identical to the originals.\nThis is easier to understand with an example:\n\n```js\nvar Cryo = require('../lib/cryo');\n\nvar userList = [{ name: 'Abe' }, { name: 'Bob' }, { name: 'Carl' }];\nvar state = {\n  users: userList,\n  activeUser: userList[1]\n};\n\nvar withJSON = JSON.parse(JSON.stringify(state));\nconsole.log(withJSON.activeUser === withJSON.users[1]);   // false\n\nvar withCryo = Cryo.parse(Cryo.stringify(state));\nconsole.log(withCryo.activeUser === withCryo.users[1]);   // true\n```\n\n### Infinity\n\nCryo successfully stringifies and parses `Infinity`, which JSON mangles into `null`.\n\n```js\nvar Cryo = require('../lib/cryo');\n\nvar number = Infinity;\n\nvar withJSON = JSON.parse(JSON.stringify(number));\nconsole.log(withJSON === Infinity);                 // false\n\nvar withCryo = Cryo.parse(Cryo.stringify(number));\nconsole.log(withCryo === Infinity);                 // true\n```\n\n### Properties\n\nObjects, Arrays, Dates, and Functions can all hold properties, but JSON will only stringify properties on Objects.\nCryo will recover properties from all containers:\n\n```js\nvar Cryo = require('../lib/cryo');\n\nfunction first() {}\nfirst.second = new Date();\nfirst.second.third = [1, 2, 3];\nfirst.second.third.fourth = { name: 'Hunter' };\n\ntry {\n  var withJSON = JSON.parse(JSON.stringify(first));\n  console.log(withJSON.second.third.fourth.name === 'Hunter');\n} catch(e) {\n  console.log('error');                                       // error\n}\n\nvar withCryo = Cryo.parse(Cryo.stringify(first));\nconsole.log(withCryo.second.third.fourth.name === 'Hunter');  // true\n```\n\n### Functions\n\nCryo will stringify functions, which JSON ignores.\n\n**Note:** Usually, if you've come up with a solution that needs to serialize functions, a better solution exists that doesn't.\nHowever, sometimes this can be enormously useful.\nCryo will make faithful hydrated functions and objects with properties that are functions.\n\n```js\nvar Cryo = require('../lib/cryo');\n\nfunction fn() {\n  console.log('Hello, world!');\n}\n\ntry {\n  var withJSON = JSON.parse(JSON.stringify(fn));\n  withJSON();\n} catch(e) {\n  console.log('error');                             // error\n}\n\nvar withCryo = Cryo.parse(Cryo.stringify(fn));\nwithCryo();                                         // Hello, world!\n```\n\n### Custom Types\n\nCryo can allow you to stringify and parse custom types by using the optional callback argument. The callback for `stringify` is called before each item is stringified, allowing you to alter an object just before it's serialized. The callback for `parse` is called after each item is re-created, allowing you to alter an object just after it's de-serialized:\n\n```js\nfunction Person() {}\nvar person = new Person();\nperson.friends = [new Person()];\n\nvar stringified = Cryo.stringify(person, function(obj) {\n  // store any object's constructor name under a variable called\n  // __class__ which can later be be used to restore the object's\n  // prototype.\n  obj.__class__ = obj.constructor.name;\n});\nvar parsed = Cryo.parse(stringified, function(obj) {\n  // look for objects that define a __class__ and restore their\n  // prototype by finding the class on the global window (you may need\n  // to look elsewhere for the class).\n  if (obj.__class__ && window[obj.__class__]) {\n    obj.__proto__ = window[obj.__class__].prototype;\n    delete obj.__class__;\n  }\n});\n\nparsed instanceof Person; // true\nparsed.friends[0] instanceof Person; // true\n```\n\n### DOM\n\nJSON chokes when you try to stringify an object with a reference to a DOM node, giving `Uncaught TypeError: Converting circular structure to JSON.`\nCryo will ignore DOM nodes so you can serialize such objects without hassle.\n\n```js\nvar obj = {\n  button: document.getElementById('my-button');\n  message: 'Hello'\n};\n\ntry {\n  var withJSON = JSON.parse(JSON.stringify(obj));\n  console.log(withJSON.message === 'Hello');\n} catch(e) {\n  console.log('error');                             // error\n}\n\nvar withCryo = Cryo.parse(Cryo.stringify(obj));\nconsole.log(withCryo.message === 'Hello');          // true\n```\n\n## Stringified Output\n\n`Cryo.stringify()` returns valid JSON data with non-compatible types encoded as strings.\nThus, anything you can do with JSON, you can do with Cryo.\n\nHere is the stringified result from the hello, world example:\n\n```json\n{\n  \"root\":\"_CRYO_REF_2\",\n  \"references\":[\n    {\n      \"contents\": {},\n      \"value\":\"_CRYO_DATE_1358245390835\"\n    },\n    {\n      \"contents\": {},\n      \"value\":\"_CRYO_FUNCTION_function () {\\n    console.log(this.name + ' said hello in ' + this.created.getFullYear() + '!');\\n  }\"\n    },\n    {\n      \"contents\":{\n        \"name\":\"Hunter\",\n        \"created\":\"_CRYO_REF_0\",\n        \"hello\":\"_CRYO_REF_1\"\n      },\n      \"value\":\"_CRYO_OBJECT_\"\n    }\n  ]\n}\n```\n\n## Tests\n\nTests require node.js.\n\n```\n$ git clone git://github.com/hunterloftis/cryo.git\n$ cd cryo\n$ make setup\n$ make test\n```\n","maintainers":[{"name":"hunterloftis","email":"hunter@hunterloftis.com"}],"time":{"modified":"2022-06-14T03:59:08.019Z","created":"2013-01-02T18:33:11.879Z","0.0.1":"2013-01-02T18:33:12.522Z","0.0.2":"2013-01-03T08:21:33.364Z","0.0.3":"2013-01-03T15:09:11.024Z","0.0.4":"2013-01-03T22:19:43.411Z","0.0.5":"2013-01-10T01:07:57.689Z","0.0.6":"2015-10-13T17:32:08.610Z"},"author":{"name":"Hunter Loftis","email":"hunter@hunterloftis.com"},"repository":{"type":"git","url":"git+ssh://git@github.com/hunterloftis/cryo.git"},"users":{"johnsonj":true,"muroc":true},"homepage":"https://github.com/hunterloftis/cryo#readme","keywords":["pickle","serialize","store","hydrate","freeze","json"],"bugs":{"url":"https://github.com/hunterloftis/cryo/issues"},"readmeFilename":"README.md"}