1.0.0 • Published 1 year ago

blots-digx v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

B L O T S - D I G X

Dig values out of nested objects.

This project ls is my humble attempt to learn and work with more TS, Jest, all things NPM and get it up to NPM repository for the masses!

Installation

npm install blots-digx --save

or

yarn add blots-digx

Usage

Digging values from deeply nested objects

import dg from "blots-digx";
const source = { param: [{}, { test: "A" }] };

dg(source, "param[1].test") //=> A

Sets and Maps also work in the similar manner.

const source = new Map([
  ["param", new Set()],
  ["innerSet", new Set([new Map(), new Map([["innerKey", "value"]])])],
]);

dg(source, "innerSet[1].innerKey"); //=> value

When path is incorrect it returns undefined

dg({ param: [] }, "param[1].test") //=> undefined

Or it can thrown an exception when optional shouldThrow parameter is set to true

dg({ param: [] }, "param[1].test", true) //=> ! Could not dig the value using path
1.0.0

1 year ago