path-crawler

0.1.0 • Public • Published

path-crawler

An utility to crawl generic objects paths.

import {crawl} from 'path-crawler';
// const {crawl} = require('path-crawler');

crawl(
  ['test?.some.number[]'],
  ({id, field, hint, optional}, value) => {
    // id is the unique path index, 0 in this case
    // field is the last field of the path: "number"
    // hint can be empty string, ?, or []
    // optional is true if the field was optional
    // if non undefined value is returned,
    // the original field is overwritten with the new value.
    return value.map(x => x * x);
  },
  {
    test: {
      some: [
        // will become [1, 4, 9]
        {number: [1, 2, 3]},
        // will become [16, 25]
        {number: [4, 5]}
      ]
    }
  }
);

Dependencies (0)

    Dev Dependencies (3)

    Package Sidebar

    Install

    npm i path-crawler

    Weekly Downloads

    15

    Version

    0.1.0

    License

    ISC

    Unpacked Size

    7.55 kB

    Total Files

    6

    Last publish

    Collaborators

    • webreflection