2.0.0 • Published 1 year ago

dget-lit v2.0.0

Weekly downloads
53
License
MIT
Repository
github
Last release
1 year ago

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.

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

2.0.0

1 year ago

1.4.3

2 years ago

1.4.2

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.2.8

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago