# dot-safe

> access unstructured data without errors

Latest version **1.0.5** (published 2022-04-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install dot-safe
pnpm add dot-safe
yarn add dot-safe
bun add dot-safe
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2022-04-05 |
| First published | 2017-12-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Richard Remer |
| Maintainers | rremer |
| Keywords | object, property, array, push, pop, proxy |

## Links

- npm: https://www.npmjs.com/package/dot-safe
- Repository: https://github.com/Zingle/dot-safe
- Homepage: https://github.com/Zingle/dot-safe#readme
- Issues: https://github.com/Zingle/dot-safe/issues
- npm.io page: https://npm.io/package/dot-safe

## Alternatives

- [react-native-root-siblings](https://npm.io/package/react-native-root-siblings.md) — 102.9K weekly downloads
- [@praxisui/dialog](https://npm.io/package/@praxisui/dialog.md) — 2.0K weekly downloads
- [easy-toggle-state](https://npm.io/package/easy-toggle-state.md) — 350 weekly downloads
- [ngx-lightbox-evp](https://npm.io/package/ngx-lightbox-evp.md) — 19 weekly downloads
- [react-native-modal-translucent-axton](https://npm.io/package/react-native-modal-translucent-axton.md) — 4 weekly downloads

## Recent versions

- 1.0.5 (latest) — 2022-04-05
- 1.0.3 — 2021-04-22
- 1.0.2 — 2021-04-20
- 1.0.1 — 2019-06-01
- 1.0.0 — 2017-12-28

## README

dot-safe
========
The `dot-safe` function creates an object proxy that an be used to safely
access object properties and manipulate arrays.  It is intended to be used with
unstructured data to avoid lots of `(obj && obj.prop && obj.prop.foo)` noise.

Usage
-----

```js
const safe = require("dot-safe");
const object = {}
const proxy = safe(object);

// set nested properties; intermediary objects created as needed
proxy.foo.bar = 13;

// push values onto arrays; array and intermediary objects created as needed
proxy.list.push(42);
proxy.list.push(23);

// safely access nested properties or pop from arrays
assert(proxy.foo.bar.valueOf() === 13);
assert(proxy.baz.bang.valueOf() === undefined);
assert(proxy.list.pop() === 23);
assert(proxy.baz.pop() === undefined);

// after all that, object now looks like:
// {
//   foo: {bar: 13},
//   list: [42]
// }
```

API
---

### safe(object) => Proxy
Create an object proxy that can be used to safely access nested data within the
object.

Performance Considerations
--------------------------
Each time a property is accessed, a new `Proxy` is created.  If you are going
to be accessing the same nested property of a particular object, consider
saving the result for subsequent property access.

```js
const proxy = safe(object);

// GOOD: do this
const status = proxy.info.status;
while (status.valueOf() === "incomplete") { ... }

// BAD: don't do this
while (proxy.info.status.valueOf() === "incomplete") { ... }
```

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