1.0.0 • Published 5 years ago

@reconbot/jsoff v1.0.0

Weekly downloads
11
License
ISC
Repository
github
Last release
5 years ago

jsoff

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

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"},{}]}