# attribute-retriever

> A library for safely retrieving nested attributes from an object in a single invocation.

Latest version **0.0.2** (published 2018-01-21) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install attribute-retriever
pnpm add attribute-retriever
yarn add attribute-retriever
bun add attribute-retriever
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2018-01-21 |
| First published | 2018-01-21 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Patrick Divine |
| Maintainers | pddivine |

## Links

- npm: https://www.npmjs.com/package/attribute-retriever
- Repository: https://github.com/pddivine/attribute-retriever
- Homepage: https://github.com/pddivine/attribute-retriever#readme
- Issues: https://github.com/pddivine/attribute-retriever/issues
- npm.io page: https://npm.io/package/attribute-retriever

## Recent versions

- 0.0.2 (latest) — 2018-01-21
- 0.0.1 — 2018-01-21

## README

# attribute-retriever
A library for safely retrieving nested attributes from an object in a single invocation.

## Motivation
Often as JavaScript developers we must obtain a nested value within an object. A happy path may look like this:

```javascript
const nestedAttribute = object.where.everything.exists; // Value of the nested 'exists' attribute

```

Following a non-happy path, we may see something like this:
```javascript
const nestAttribute = object.where.X.is.undefined;

/*
Uncaught TypeError: Cannot read property 'is' of undefined
    at <anonymous>:1:5
*/

```

If we do not do this safely, avoiding the TypeError, we can do something like this:

```javascript
const nestedAttribute = object && object.where && object.where.X && object.where.X.is && object.where.X.is.undefined; // undefined

```

This can get a little verbose.

## Use

What about something that reads simpler? How about?

```javascript
const getAttr = require('attribute-retriever');

const nestedAttribute_1 = getAttr('object.where.everything.exists'); // Value of the nested 'exists' attribute
const nestedAttribute_2 = getAttr('object.where.X.is.undefined'); // undefined

```

And _voila!_ Simpler.

---
_Source: https://npm.io/package/attribute-retriever · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
