项目作者: iamnapo

项目描述 :
🔍 Get the value at a specific object (or string) path, without caring if it exists.
高级语言: JavaScript
项目地址: git://github.com/iamnapo/get.git
创建时间: 2020-09-17T07:08:33Z
项目社区:https://github.com/iamnapo/get

开源协议:MIT License

下载


@iamnapo/get

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

build @iamnapo/get"">npm @iamnapo/get"">size license

Install

  1. $ npm i @iamnapo/get

Usage

  1. const get = require("@iamnapo/get");
  2. get([4, 5], "[0]"); // => 4
  3. get({ a: { b: 1 } }, "a.b"); // => 1
  4. get({ a: { b: 1 } }, "a.c", "blah"); // => "blah"
  5. 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.