putil-stringify

1.1.0 • Public • Published

putil-stringify

NPM Version NPM Downloads Build Status Test Coverage Dependencies DevDependencies

Alternate to native JSON.stringify. It offers more control in replacer callback, etc formatting dates with custom format. And also replacer callback can have 3 arguments which gives current object being serialized.

const a = {a: 1, b: '2', c: {d: new Date()}};
let s = stringify(a, (k, v) => {
  if (instanceof Date)
    return 'today';
  return v;
});
console.log(s);
{"a":1,"b":"2","c":{"d":"today"}}
const a = {a: {num: 5}};
const b = {a: a, b: 'Hello'};
let s = stringify(b, (o, k, v) => {
  if (=== a.a && k === 'num')
    return v+1;
  return v;
});
console.log(s);
{"a":{"a":{"num":6}},"b":"Hello"}

Installation

  • $ npm install putil-stringify --save

Node Compatibility

  • node >= 6.x;

License

MIT

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.1.0
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.1.0
    0
  • 1.0.0
    0

Package Sidebar

Install

npm i putil-stringify

Weekly Downloads

0

Version

1.1.0

License

MIT

Last publish

Collaborators

  • erayhanoglu