Skip to content

Commit

Permalink
added output examples to close #2 - good idea
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterloftis committed Jan 15, 2013
1 parent 8a1b848 commit d4ad116
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
31 changes: 31 additions & 0 deletions README.md
Expand Up @@ -200,6 +200,37 @@ var withCryo = Cryo.parse(Cryo.stringify(obj));
console.log(withCryo.message === 'Hello'); // true
```

## Stringified Output

`Cryo.stringify()` returns valid JSON data with non-compatible types encoded as strings.
Thus, anything you can do with JSON, you can do with Cryo.

Here is the stringified result from the hello, world example:

```json
{
"root":"_CRYO_REF_2",
"references":[
{
"contents": {},
"value":"_CRYO_DATE_1358245390835"
},
{
"contents": {},
"value":"_CRYO_FUNCTION_function () {\n console.log(this.name + ' said hello in ' + this.created.getFullYear() + '!');\n }"
},
{
"contents":{
"name":"Hunter",
"created":"_CRYO_REF_0",
"hello":"_CRYO_REF_1"
},
"value":"_CRYO_OBJECT_"
}
]
}
```

## Tests

Tests require node.js.
Expand Down
14 changes: 14 additions & 0 deletions examples/output.js
@@ -0,0 +1,14 @@
var Cryo = require('../lib/cryo');

var obj = {
name: 'Hunter',
created: new Date(),
hello: function() {
console.log(this.name + ' said hello in ' + this.created.getFullYear() + '!');
}
};

var frozen = Cryo.stringify(obj);

console.log("Stringified cryo objects look like this:\n\n");
console.log(frozen);
21 changes: 21 additions & 0 deletions examples/output.json
@@ -0,0 +1,21 @@
{
"root":"_CRYO_REF_2",
"references":[
{
"contents": {},
"value":"_CRYO_DATE_1358245390835"
},
{
"contents": {},
"value":"_CRYO_FUNCTION_function () {\n console.log(this.name + ' said hello in ' + this.created.getFullYear() + '!');\n }"
},
{
"contents":{
"name":"Hunter",
"created":"_CRYO_REF_0",
"hello":"_CRYO_REF_1"
},
"value":"_CRYO_OBJECT_"
}
]
}

0 comments on commit d4ad116

Please sign in to comment.