Skip to content
/ get Public

🔍 Get the value at a specific object (or string) path, without caring if it exists.

License

Notifications You must be signed in to change notification settings

iamnapo/get

Repository files navigation

@iamnapo/get

Get the value at a specific object (or string) path, without caring if it exists

build npm size license

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.