1.0.6 • Published 6 years ago

@kingjs/descriptor.nested.for-each v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

@kingjs/descriptor.nested.for-each

Invoke a callback for each path.

Usage

Create a new descriptor with pet names for property names like this:

'use strict';

var forEach = require('@kingjs/descriptor.nested.for-each');

var values = {
  alice: {
    pet: { name: 'tiger' }
  },
  bob: {
    pet: { name: 'snuggles' }
  },
  chris: {
    pet: { name: 'spike' }
  },
}

var result = { };
forEach(values, { 
  '*': { 
    pet: { 
      name: null 
    } 
  } 
}, o => result[o] = true);

result

result:

{
  tiger: true,
  snuggles: true,
  spike: true
}

API

declare function forEach(
  tree: NestedDescriptor,
  paths: NestedDescriptor,
  callback: (leaf, path) => any,
  thisArg?
): void

Interfaces

Parameters

  • tree: The tree whose nodes will be frozen.
  • paths: The paths of the tree to pass to the callback.
  • callback: Used to update paths of tree:
    • leaf: The leaf value.
    • path: The path value.
  • thisArg: The this argument to pass to callback.

Install

With npm installed, run

$ npm install @kingjs/descriptor.nested.for-each

License

MIT

Analytics