data-path-finder

0.0.4 • Public • Published

data-path-finder

This library allows for traversing a javascript object to find particular properties specified in a data-path string.

A data-path string provides the ability to specify an object-traversal mechanism to grab specific attribute values out of the provided object.

Data Path specification

A data-path string conforms to a simple specification of a property tree.

Consider the following javascript object:

{
  userName:"Jose",
  address: "San Pablo de Heredia",
  favoriteCars: [ 
    {
      make:"Nissan",
      model:"versa"
    },
    {
      make:"Toyota",
      model:"Rav4"
    },
    {
      make:"Hyundai",
      model:"Santa Fe"
    }
  ]
}

The data-path specification "userName" points to the value "Jose", while the data-path specification "favoriteCars[].make" point to the value ["Nissan","Toyota","Hyundai"]

Uses of this library

Known uses for data-path expressions implemented in this library include data transformation, mapping and verification out of dynamic rules specified in text. For example for comparing two objects of different structure that may have common attributes.

Example using the cli.js file

  1. In an empty directory, run npm install data-path-finder
  2. Then run cd node_modules/data-path-finder/src
  3. Then run `node cli.js "../es_samples/favoriteCars.json" "favoriteCars[].make"
  4. The command should display a result of ["Nissan","Toyota","Hyundai"]

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i data-path-finder

      Weekly Downloads

      2

      Version

      0.0.4

      License

      MIT

      Unpacked Size

      9.67 kB

      Total Files

      10

      Last publish

      Collaborators

      • janunezc
      • jerome.yackley