Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 12 days 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 (about 4 years ago)
- Default Branch: main
- Last Pushed: 2020-10-17T17:10:30.000Z (about 4 years ago)
- Last Synced: 2024-10-07T21:50:07.685Z (about 1 month 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
[![build](https://img.shields.io/github/workflow/status/iamnapo/get/ci?style=for-the-badge&logo=github&label=)](https://github.com/iamnapo/get/actions) [![npm](https://img.shields.io/npm/v/@iamnapo/get.svg?style=for-the-badge&logo=npm&label=)](https://www.npmjs.com/package/@iamnapo/get) [![size](https://img.shields.io/bundlephobia/min/@iamnapo/get.svg?style=for-the-badge&label=size)](https://bundlephobia.com/result?p=@iamnapo/get) [![license](https://img.shields.io/github/license/iamnapo/get.svg?style=for-the-badge)](./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.