roxan

0.0.0-prealpha • Public • Published

ROXAN: JSON + Recursive Structures

Installation

npm install rexon

Usage

var rexon = require('rexon');
var obj = {
  nullMember: null,
  stringMember: "string\n",
  numberMember: 12,
  voidMember: void 0,
  boolMember: true,
  arrayMember: [[], [[]], [[[]]], [[[[]]]], [[[[[]]]]]]
};
 
obj.itself = obj;
obj.itselfInArray = [obj, [obj]];
 
var result = rexon.stringify(obj)
// result:
// {
//   "nullMember": null,
//   "stringMember": "string\n",
//   "numberMember": 12,
//   "voidMember": undefined,
//   "boolMember": true,
//   "arrayMember": [
//     [],
//     [
//       []
//     ],
//     [
//       [
//  []
//       ]
//     ],
//     [
//       [
//  [
//    []
//  ]
//       ]
//     ],
//     [
//       [
//  [
//    [
//      []
//    ]
//  ]
//       ]
//     ]
//   ],
//   "itself": &0,
//   "itselfInArray": [
//     &0,
//     [
//       &0
//     ]
//   ]
// }
 

Streaming

even though, by default, roxan.stringify returns a whole string after the whole object passed to it has been stringified, this behaviour can be easily customized:

var roxan = require('roxan');
 
function writeToConsoleImmediately(chunk) {
  console.log(chunk);
}
 
var obj = ... // the same value as `obj`, above
 
roxan.stringify(obj, {rawWrite: writeToConsoleImmediately}); // streams `stringify`'s output to stdout as it is getting produced

Please note that roxan.stringify no longer returns a string when it is provided with a custom rawWrite.

Package Sidebar

Install

npm i roxan

Weekly Downloads

0

Version

0.0.0-prealpha

License

MIT

Unpacked Size

9.14 kB

Total Files

4

Last publish

Collaborators

  • elenakay