Have ideas to improve npm?Join in the discussion! »

    birds-eye

    1.0.10 • Public • Published

    birds-eye

    object or array with nesting → collection containing all primitive value types and corresponding nest depths

    Build Status

    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 above
    • n - the nest depth that the resulting collection should be filtered by

    License

    MIT © Kevin Donahue

    Install

    npm i birds-eye

    DownloadsWeekly Downloads

    5

    Version

    1.0.10

    License

    MIT

    Last publish

    Collaborators

    • avatar