Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/reconbot/js-off
https://github.com/reconbot/js-off
Last synced: 4 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/reconbot/js-off
- Owner: reconbot
- Created: 2019-02-19T00:40:02.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-02-19T02:21:16.000Z (over 5 years ago)
- Last Synced: 2024-10-31T07:34:19.659Z (12 days ago)
- Language: JavaScript
- Homepage:
- Size: 18.6 KB
- Stars: 41
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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"},{}]}
```