1.2.3 • Published 5 months ago

nested-data-navigator v1.2.3

Weekly downloads
-
License
ISC
Repository
github
Last release
5 months ago

nested-data-navigator npm NPM Downloads

Nested Data Navigator is a lightweight JavaScript package for navigating and retrieving values from nested data structures.

Install

You can install the package using npm:

npm install nested-data-navigator

Usage

const { grabValue, grabPath } = require("nested-data-navigator");

var person = {
  firstName: "Ali",
  lastName: "Parsa",
  age: 21,
  info: {
    address: {
      city: 'New York',
      zip: '10001',
    }
  }
};

console.log(grabValue(person, "info.city", "default value")) //=> 'New Yourk'
console.log(grabPath(person, "info.city", "default value")) //=> '.info.address.city' 

Example

You can grab value or path without select parents:

const { grabValue, grabPath } = require("nested-data-navigator");

var sample_1 = {
  firstName: "Ali",
  lastName: "Parsa",
  age: 21,
  info: {
    address: {
      city: 'New York',
      zip: '10001',
    }
  }
};

var sample_2 = {
  firstName: "Ali",
  lastName: "Parsa",
  age: 21,
  info: {
    location: {
      city: 'Canada',
      zip: '10001',
    }
  }
};

console.log(grabValue(sample_1, "info.city")) //=> 'New York'
console.log(grabPath(person, "info.city")) //=> '.info.address.city'

console.log(grabValue(sample_2, "city")) //=> 'Canada'
console.log(grabPath(person, "city")) //=> '.info.location.city'

console.log(grabValue(sample_2, "info.wrong","not found!")) //=> 'not found!'
1.2.3

5 months ago

1.2.1

5 months ago

1.1.4

5 months ago

1.1.3

5 months ago

1.1.2

5 months ago

1.1.1

5 months ago

1.1.0

5 months ago

1.0.15

5 months ago

1.0.14

5 months ago

1.0.13

5 months ago

1.0.12

5 months ago

1.0.11

5 months ago

1.0.10

5 months ago

1.0.9

5 months ago

1.0.8

6 months ago

1.0.7

6 months ago

1.0.6

6 months ago

1.0.5

6 months ago

1.0.4

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago