2.0.9 • Published 3 months ago

deep-nested-values v2.0.9

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

deep-nested-values

A simple tool to find deeply nested values in JSON data structures.

Installation

npm i deep-nested-values

Methods

hasDeepValue(data: object, route: string, createRoute: boolean = false)

Returns a Boolean indicating whether the specified route exists within the object, and creates it if createRoute is true.

getValue(data: object, route: string)

Returns the value at the specified route, or undefined if not found.

setValue(data: object, route: string, value: string | number, createRoute: boolean = true)

Sets the value at the route. By default, it creates the route if it doesn't exist. Returns a Boolean indicating success or failure.

Examples

import { getDeepValue, setDeepValue, hasDeepValue } from 'deep-nested-vales';

const data = {
    something: 'nothing',
    value: 32,
    nested: {
        hello: 'world',
        whatever: 'something',
        deepnested: {
            cat: 'meow',
            someNumber: 1234
        }
    }
}

hasDeepValue(data, 'nested.deepnested.cat');
//  returns true

getDeepValue(data, 'nested.deepnested.cat');
//  returns 'meow'

setDeepValue(data, 'nested.deepnested.cat', 'purr');
//  returns true

getDeepValue(data, 'nested.deepnested.cat');
//  returns 'purr'
2.0.9

3 months ago

2.0.8

4 months ago

2.0.7

6 months ago

2.0.6

6 months ago

2.0.5

1 year ago

2.0.4

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago