1.4.3 • Published 7 months ago
dget-lit v1.4.3
dget-lit
Safely get a value from a nested object via a dot-notated path. In addition you have the ability to provide a fallback value to be returned if the full key path does not exists or the value is undefined.
Requirements
Install
# Using npm
$ npm install dget-lit
# Using yarn
$ yarn add dget-lit
Example
import { dget } from 'dget-lit';
let obj = {
a: {
two: 2,
b: {
three: undefined,
c: [3, 4, 5],
},
},
};
// use string dot notation for keys
dget(obj, 'a.two'); // 2
// or use an array key
dget(obj, ['a', 'two']); // 2
// use a default
dget(obj, 'a.b.three', 'my-default'); // 'my-default'
// to get a value from an array, use `.<index>` or `[<index>]`
dget(obj, 'a.b.c.2'); // 5
dget(obj, 'a.b.c[2]'); // 5
Development
(1) Install dependencies
# Using npm
$ npm install
# Using yarn
$ yarn
(2) Validate setup
$ ./Taskfile.sh validate
(3) Start development by running tests in watch-mode
$ ./Taskfile.sh test -w
This project was bootstrapped with @jvdx/core.
1.4.3
7 months ago
1.4.2
2 years ago
1.4.1
2 years ago
1.4.0
2 years ago
1.3.0
2 years ago
1.2.8
2 years ago
1.2.7
2 years ago
1.2.6
2 years ago
1.2.5
2 years ago
1.2.4
2 years ago
1.2.3
2 years ago
1.2.2
2 years ago
1.2.1
3 years ago
1.2.0
3 years ago
1.1.8
3 years ago
1.1.7
3 years ago
1.1.6
3 years ago
1.1.5
3 years ago
1.1.4
3 years ago
1.1.3
3 years ago
1.1.2
3 years ago
1.1.1
3 years ago
1.1.0
3 years ago
1.0.0
4 years ago
0.1.2
4 years ago
0.1.1
4 years ago
0.1.0
4 years ago