@iamnapo/get
v1.0.3
Published
Get the value at a specific object (or string) path, without caring if it exists
Downloads
13
Readme
@iamnapo/get
Get the value at a specific object (or string) path, without caring if it exists
Install
$ npm i @iamnapo/get
Usage
const get = require("@iamnapo/get");
get([4, 5], "[0]"); // => 4
get({ a: { b: 1 } }, "a.b"); // => 1
get({ a: { b: 1 } }, "a.c", "blah"); // => "blah"
get("napo", "[1]"); // => "a"
API
get(object, path, defaultValue?)
Get path
of object
, returning defaultValue
if it doesn‘t exist.
object
Type: object | Array | string
Base object to get value from.
path
Type: string
Path to get value at.
defaultValue
Type: string
Default: undefined
Return value if path doesn‘t exist.