Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/reconbot/js-off


https://github.com/reconbot/js-off

Last synced: 4 days ago
JSON representation

Awesome Lists containing this project

README

        

# jsoff

Count which JSON fields you've accessed and remove the rest.

```js
const { jsOff, countSymbol } = require('@reconbot/jsoff')
const input = {
foo: {
bar: 4,
baz: null
},
arr: [{ name: 'spock', age: 64 }, { name: undefined }]
}

const data = jsOff(input)

console.log(data.foo.bar)
console.log(data.arr.map(i => i.name ))

console.log(data[countSymbol])
// { foo: 1, arr: 1 })
console.log(data.arr[0][countSymbol])
// { name: 1, age: 0 }
console.log(JSON.stringify(data))
// {"foo":{"bar":4},"arr":[{"name":"spock"},{}]}
```