@kingjs/descriptor.nested.to-paths

1.0.1 • Public • Published

@kingjs/descriptor.nested.to-paths

Returns paths constructed of nodes that satisfy a predicate.

Usage

Return an array of pet names like this:

var toPaths = require('@kingjs/descriptor.nested.to-paths');

var people = {
  alice: { 
    pet: 'tiger' 
  },
  bob: { 
    pet: 'snuggles' 
  },
  chris: {
    pet: 'spike'
  }
};

var result = toPaths(
  people, 
  x => x instanceof Object, 
  null
);

result:

{
  { 
    alice: { pet: null },
    bob: { pet: null },
    chris: { pet: null },
  }
}

API

declare function toPaths(
  tree: NestedDescriptor,
  predicate: () => boolean,
  value?: any
): NestedDescriptor

Interfaces

Parameters

  • tree: A tree from which a subtree worth of nodes is selected that satisfy a predicate.
  • predicate: Selects which nodes to include in the subtree.
  • value: Optional leaf value.

Returns

Returns an subtree of tree where each node satisfies the predicate.

Install

With npm installed, run

$ npm install @kingjs/descriptor.nested.to-paths

License

MIT

Analytics

Readme

Keywords

none

Package Sidebar

Install

npm i @kingjs/descriptor.nested.to-paths

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

3.46 kB

Total Files

4

Last publish

Collaborators

  • kingces95