json-chop
Minimal object-to-json formatting and chopping tool.
Installation
npm install --save json-chop
Description
If you don't want rely on libraries like lodash
to do minimal object manipulation you can just use JSON.stringify
's built-in filter capabilities - or this library, which abstracts a thin layer over it.
This is believed to be much more performant then walking trees.
No dependencies.
Usage
'use strict'const chop = // an arbitrary objectlet obj = somekey: nestedKey: 'hello' _id: 12234555 version: null __v: '0.8.0' oneHunrdred: 100 // define key and or value you want to finlter. `undefined` and empty// arrays will be filtered automaticallylet options = keyBlacklist: '__v' '_id' valueBlacklist: '' 100 null// async version with a callbackchop// sync version returns the value from the functionlet res = chopconsole// {"somekey":{"nestedKey":"hello"}}
Roadmap
Test suite- Type checking for dev input
- optionally return an object
- safe mode (try ... catch)
- Chopping array of nulls
Credits
License
MIT