https://github.com/iamnapo/get
🔍 Get the value at a specific object (or string) path, without caring if it exists.
https://github.com/iamnapo/get
array get object path string
Last synced: about 1 year ago
JSON representation
🔍 Get the value at a specific object (or string) path, without caring if it exists.
- Host: GitHub
- URL: https://github.com/iamnapo/get
- Owner: iamnapo
- License: mit
- Created: 2020-09-17T07:08:33.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2020-10-17T17:10:30.000Z (over 5 years ago)
- Last Synced: 2024-10-07T21:50:07.685Z (over 1 year ago)
- Topics: array, get, object, path, string
- Language: JavaScript
- Homepage: https://npm.im/@iamnapo/get
- Size: 19.5 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @iamnapo/get
> Get the value at a specific object (or string) path, without caring if it exists
[](https://github.com/iamnapo/get/actions) [](https://www.npmjs.com/package/@iamnapo/get) [](https://bundlephobia.com/result?p=@iamnapo/get) [](./LICENSE)
## Install
```sh
$ npm i @iamnapo/get
```
## Usage
```js
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.