birds-eye
v1.0.10
Published
object or array with nesting → collection containing all primitive value types and corresponding nest depths
Downloads
8
Maintainers
Readme
birds-eye
object or array with nesting → collection containing all primitive value types and corresponding nest depths
Install
npm install --save birds-eye
Usage
Object with nesting:
const obj = {
i: Math.E,
j: (n) => n * n,
k: {
l: true,
m: [],
n: {
o: {
p: {
q: 'Q'
}
},
r: null
}
},
s: 42
}
Nested structure of the object's primitive values:
console.log(birdsEye(obj));
// =>
[ { type: 'number', depth: 0 },
{ type: 'boolean', depth: 1 },
{ type: 'string', depth: 4 },
{ type: 'null', depth: 2 },
{ type: 'number', depth: 0 } ]
Return all primitive types found at a given depth of nesting:
console.log(birdsEye.atDepth(obj, 0)); // => ['number', 'number']
console.log(birdsEye.atDepth(obj, 42)); // => []
This of course also works with nested arrays:
const arr = [2,[42,[[[true]]],'n',[1e6]], undefined];
console.log(birdsEye(arr));
// =>
[ { type: 'number', depth: 0 },
{ type: 'number', depth: 1 },
{ type: 'boolean', depth: 4 },
{ type: 'string', depth: 1 },
{ type: 'number', depth: 2 },
{ type: 'undefined', depth: 0 } ]
API
birdsEye(obj)
Arguments
obj
- object|array to map to a one dimensional collection
birdsEye.atDepth(obj, n)
Arguments
obj
- same as aboven
- the nest depth that the resulting collection should be filtered by
License
MIT © Kevin Donahue