Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jeremenichelli/deepget
Small package to get deep nested properties from JavaScript objects
https://github.com/jeremenichelli/deepget
Last synced: 16 days ago
JSON representation
Small package to get deep nested properties from JavaScript objects
- Host: GitHub
- URL: https://github.com/jeremenichelli/deepget
- Owner: jeremenichelli
- License: mit
- Created: 2018-02-21T22:22:31.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-03-16T15:27:09.000Z (over 6 years ago)
- Last Synced: 2024-10-11T13:34:40.310Z (about 1 month ago)
- Language: JavaScript
- Size: 61.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# deepget
Small package to get deep nested properties from JavaScript objects## Install
```sh
# npm
npm install dpgt --save# yarn
yarn add dpgt
```### Use
Import the utility and get nested properties passing the object and the key path.
```js
import deepget from 'dpgt';// some object with nested properties
const cartoon = {
title: 'Rick and Morty',
seasons: 3,
characters: {
rick: {
firstName: 'Rick'
lastName: 'Sanchez'
},
morty: {
firstName: 'Morty'
lastName: 'Smith'
},
}
};deepget(cartoon, 'characters.rick.lastName');
// Sanchez
```You can also use an array as a key path.
```js
deepget(cartoon, [ 'characters', 'rick', 'lastName' ]);
// Sanchez
```Default values are supported too as a thrid optional argument.
```js
deepget(cartoon, [ 'characters', 'beth' ], 'Not found');
// Not found
```## TODO
- Write tests
- Write contributing guide