# dotmap

> easy dot-notation accessor functions

Latest version **0.1.0** (published 2013-03-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install dotmap
pnpm add dotmap
yarn add dotmap
bun add dotmap
```

## 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.1.0 |
| Published | 2013-03-05 |
| First published | 2013-03-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Agile Diagnosis |
| Maintainers | jden |
| Keywords | dot, accessor, map |

## Links

- npm: https://www.npmjs.com/package/dotmap
- Repository: git@github.com:AgileDiagnosis/dotmap
- npm.io page: https://npm.io/package/dotmap

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2013-03-05

## README

# dotmap
easy dot-notation accessor functions

## installation

    $ npm install dotmap

## usage

Have you ever wanted to build some functions, say, for an `Array#map` iterator, to reach into an object? Now you can!

    var dot = require('dotmap')

    var people = [
      {name: {first: 'A', last: 'Turing'}, age: 23},
      {name: {first: 'B', last: 'Cool'}, age: 31},
      {name: {first: 'C', last: 'Coolidge'}, age: 104}
    ]

    var firsts = people.map(dot('name.first'))
    // => ['A', 'B', 'C']

Sometimes you'd rather get undefined then a ReferenceError. For that, we can use `dot.safe`

    var people = [
      {name: {first: 'A', last: 'Turing'}, age: 23},
      {name: {first: 'B', last: 'Cool'}, age: 31},
      {name: {first: 'C', last: 'Coolidge'}, age: 104},
      {name: {last: 'Roosevelt'}, age: 49}
    ]

    var firsts = people.map(dot.safe('name.first'))
    // => ['A', 'B', 'C', undefine]


And for convenience, you can call `dot.get` to create and use the accessor function at the same time:

    var data = {name: {first: 'C', last: 'Coolidge'}, age: 104}

    dot.get(data, 'name.first')
    // => 'C'

Note that due to the overhead of creating functions, it's best to avoid using `dot.get` in a tight loop.

## hasn't this been done?

Yes. You've written it. Also, I've used and enjoyed @rauchg's [dot-component](https://npmjs.org/package/dot-component). The advantage here is that it's special cased for accessing, and it's optimized for speed. We unroll some of the loops to avoid as much array manipulation as possible.


## running the tests

change to package root director

    $ npm test

## contributors

jden <jason@denizac.org>

## license

MIT. (c) 2013 Agile Diagnosis <hello@agilediagnosis.com>, see LICENSE.md

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