ixfx
    Preparing search index...
    • Yields the direct (ie. non-recursive) children of a tree-like object as a pairing of node name and value. Supports basic objects, Maps and arrays.

      To iterate recursively, consider depthFirst

      Each child is returned in an TraverseObjectEntry structure:

      type Entry = Readonly<{
      // Property name
      name: string,
      // Value of property, as if you called `object[propertyName]`
      sourceValue: any,
      // Branch nodes will have _undefined_, leaf nodes will contain the value
      leafValue: any
      }>;

      For example, iterating over a flat object:

      const verySimpleObject = { field: `hello`, flag: true }
      const kids = [ ...children(verySimpleObject) ];
      // Yields:
      // [ { name: "field", sourceValue: `hello`, leafValue: `hello` },
      // { name: "flag", sourceValue: true, leafValue: true } ]

      For objects containing objects:

      const lessSimpleObject = { field: `hello`, flag: true, colour: { `red`, opacity: 0.5 } }
      const kids = [ ...children(verySimpleObject) ];
      // Yields as before, plus:
      // { name: "colour", sourceValue: { name: 'red', opacity: 0.5 }, leafValue: undefined }

      Note that 'sourceValue' always contains the property value, as if you access it via object[propName]. 'leafValue' only contains the value if it's a leaf node.

      Arrays are assigned a name based on index.

      Parameters

      Returns IterableIterator<
          Readonly<
              { _kind: "entry"; leafValue: any; name: string; sourceValue: any },
          >,
      >

      const colours = [ { r: 1, g: 0, b: 0 }, { r: 0, g: 1, b: 0 }, { r: 0, g: 0, b: 1 } ];
      // Children:
      // [
      // { name: "array[0]", value: {r:1,g:0,b:0} },
      // { name: "array[1]", value: {r:0,g:1,b:0} },
      // { name: "array[2]", value: {r:0,g:0,b:1} },
      // ]

      Pass in options.name (eg 'colours') to have names generated as 'colours[0]', etc. Options can also be used to filter children. By default all direct children are returned.