@iamnapo/get
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

@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.

Package Sidebar

Install

npm i @iamnapo/get

Weekly Downloads

2

Version

1.0.3

License

MIT

Unpacked Size

4.12 kB

Total Files

5

Last publish

Collaborators

  • iamnapo