Comparing version 2.1.0 to 2.1.1
@@ -28,3 +28,3 @@ 'use strict' | ||
* @param {object} - the input object | ||
* @param {string} - the property accessor expression. | ||
* @param {string} - the property accessor expression. | ||
* @returns {*} | ||
@@ -50,3 +50,3 @@ * @alias module:object-get | ||
if (arr) { | ||
return prev && prev[arr[1]][arr[2]] | ||
return prev && prev[arr[1]] && prev[arr[1]][arr[2]] | ||
} else { | ||
@@ -53,0 +53,0 @@ return prev && prev[curr] |
{ | ||
"name": "object-get", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"description": "Access nested property values at any depth with a simple expression.", | ||
@@ -23,5 +23,5 @@ "main": "lib/object-get.js", | ||
"devDependencies": { | ||
"jsdoc-to-markdown": "^1.3.6", | ||
"tape": "^4.5.1" | ||
"jsdoc-to-markdown": "^5.0.3", | ||
"tape": "^4.13.0" | ||
} | ||
} |
[![view on npm](http://img.shields.io/npm/v/object-get.svg)](https://www.npmjs.org/package/object-get) | ||
[![npm module downloads](http://img.shields.io/npm/dt/object-get.svg)](https://www.npmjs.org/package/object-get) | ||
[![Build Status](https://travis-ci.org/75lb/object-get.svg?branch=master)](https://travis-ci.org/75lb/object-get) | ||
[![Dependency Status](https://david-dm.org/75lb/object-get.svg)](https://david-dm.org/75lb/object-get) | ||
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](https://github.com/feross/standard) | ||
<a name="module_object-get"></a> | ||
# object-get | ||
Access nested property values at any depth with a simple expression. | ||
**Example** | ||
```js | ||
const objectGet = require('object-get') | ||
***No longer maintained. Please consider using the lodash [`_.get`](https://lodash.com/docs/4.17.15#get) method or similar*** | ||
const colour = objectGet(mammal, 'fur.appearance.colour') | ||
const text = objectGet(el, 'children[2].children[1].children[1].textContent') | ||
``` | ||
Helps avoid long logical expressions like: | ||
```js | ||
const colour = mammal && mammal.fur && mammal.fur.appearance && mammal.fur.appearance.colour | ||
``` | ||
<a name="exp_module_object-get--objectGet"></a> | ||
## objectGet(object, expression) ⇒ <code>\*</code> ⏏ | ||
Returns the value at the given property. | ||
**Kind**: Exported function | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| object | <code>object</code> | the input object | | ||
| expression | <code>string</code> | the property accessor expression. | | ||
**Example** | ||
```js | ||
> objectGet({ animal: 'cow' }, 'animal') | ||
'cow' | ||
> objectGet({ animal: { mood: 'lazy' } }, 'animal') | ||
{ mood: 'lazy' } | ||
> objectGet({ animal: { mood: 'lazy' } }, 'animal.mood') | ||
'lazy' | ||
> objectGet({ animal: { mood: 'lazy' } }, 'animal.email') | ||
undefined | ||
``` | ||
* * * | ||
© 2015-16 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown). |
@@ -42,2 +42,4 @@ 'use strict' | ||
t.strictEqual(objectGet(element, 'children[1].children[0].three'), 3) | ||
t.strictEqual(objectGet(element, 'otherChildren[0].four'), undefined) | ||
t.strictEqual(objectGet(element, 'children[1].otherChildren[0].five'), undefined) | ||
t.end() | ||
@@ -51,5 +53,11 @@ }) | ||
t.throws(function () { | ||
objectGet({ one: 1 }, undefined) | ||
}) | ||
t.throws(function () { | ||
objectGet(null, 'one') | ||
}) | ||
t.throws(function () { | ||
objectGet(undefined, null) | ||
}) | ||
t.end() | ||
}) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
110
6052
7
13