Permalink
Browse files

added properties example

  • Loading branch information...
1 parent 638f5cd commit 00252309a284b2fabcf5f8ac8d7ede2e2519f814 @hunterloftis committed Jan 3, 2013
Showing with 42 additions and 4 deletions.
  1. +26 −4 README.md
  2. +16 −0 examples/properties.js
View
@@ -3,7 +3,7 @@
Easily serialize and deserialize JavaScript objects.
Built for node.js and browsers. Cryo is inspired by Python's pickle and works similarly to JSON.stringify() and JSON.parse().
-Cryo.stringify() and Cryo.parse() handle these additional circumstances:
+Cryo.stringify() and Cryo.parse() improve on JSON in these circumstances:
- [Undefined](#undefined)
- [Date](#date)
@@ -107,7 +107,7 @@ console.log(withCryo.activeUser === withCryo.users[1]); // true
### Infinity
-Cry successfully stringifies and parses `Infinity`, which JSON mangles into `null`.
+Cryo successfully stringifies and parses `Infinity`, which JSON mangles into `null`.
```js
var Cryo = require('../lib/cryo');
@@ -121,10 +121,32 @@ var withCryo = Cryo.parse(Cryo.stringify(number));
console.log(withCryo === Infinity); // true
```
-### Functions
-
### Properties
+Objects, Arrays, Dates, and Functions can all hold properties, but JSON will only stringify properties on Objects.
+Cryo will recover properties from all containers:
+
+```js
+var Cryo = require('../lib/cryo');
+
+function first() {}
+first.second = new Date();
+first.second.third = [1, 2, 3];
+first.second.third.fourth = { name: 'Hunter' };
+
+try {
+ var withJSON = JSON.parse(JSON.stringify(first));
+ console.log(withJSON.second.third.fourth.name === 'Hunter');
+} catch(e) {
+ console.log('error'); // error
+}
+
+var withCryo = Cryo.parse(Cryo.stringify(first));
+console.log(withCryo.second.third.fourth.name === 'Hunter'); // true
+```
+
+### Functions
+
## Tests
View
@@ -0,0 +1,16 @@
+var Cryo = require('../lib/cryo');
+
+function first() {}
+first.second = new Date();
+first.second.third = [1, 2, 3];
+first.second.third.fourth = { name: 'Hunter' };
+
+try {
+ var withJSON = JSON.parse(JSON.stringify(first));
+ console.log(withJSON.second.third.fourth.name === 'Hunter');
+} catch(e) {
+ console.log('error'); // error
+}
+
+var withCryo = Cryo.parse(Cryo.stringify(first));
+console.log(withCryo.second.third.fourth.name === 'Hunter'); // true

0 comments on commit 0025230

Please sign in to comment.