# split-keypath

> Splits strings into an array of keys used for reading nested data structures

Latest version **1.0.1** (published 2016-03-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install split-keypath
pnpm add split-keypath
yarn add split-keypath
bun add split-keypath
```

## 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.1 |
| Published | 2016-03-23 |
| First published | 2016-03-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Miguel Castillo |
| Maintainers | manchagnu |
| Keywords | split, keypath |

## Links

- npm: https://www.npmjs.com/package/split-keypath
- Repository: https://github.com/MiguelCastillo/split-keypath
- Issues: https://github.com/MiguelCastillo/split-keypath/issues
- npm.io page: https://npm.io/package/split-keypath

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2016-03-23
- 1.0.0 — 2016-03-23

## README

# split-keypath
> Splits strings into an array of keys used for reading nested data structures

split-keypath is a method that takes a string as an input and generates an array of keys that can be used for reading values from a deeply nested object.  The algorithm supports extracting array keys, which is how you can specify arbitrary keys. Please see below for examples.


## Install

```
$ npm install split-keypath
```

> The npm package has a bundle for the browser


## Examples

``` javascript
import splitKeypath from "split-keypath";
var result = splitKeypath("hello.world");
// Result is ["hello", "world"]
```

``` javascript
import splitKeypath from "split-keypath";
var result = splitKeypath("hello[0].world[some really long string. with non ascii chars.]");
// Result is ["hello", "0", "world", "some really long string. with non ascii chars."];
```

Practical use that reads a value from a somewhat deeply nested object hierarchy

``` javascript
import splitKeypath from "split-keypath";

function readDeepValue(input, keypath) {
  return splitKeypath(keypath).reduce((nested, key) => nested[key], input);
}

var input = {
  some: {
    deep: [
      {
        key: 42
      }
    ]
  }
};

var result = readDeepValue(input, "some.deep[0].key");
// Result is 42
```


## License
MIT

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