# stringify-keys

> Build an array of key paths from an object.

Latest version **3.0.0** (published 2019-01-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install stringify-keys
pnpm add stringify-keys
yarn add stringify-keys
bun add stringify-keys
```

## 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 | 3.0.0 |
| Published | 2019-01-22 |
| First published | 2014-12-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4.0 |
| Dependencies | 0 |
| Unpacked size | 9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 17 |
| Author | Brian Woodward |
| Maintainers | doowb, jonschlinkert |
| Keywords | dot, keys, nested, notation, object, path, paths, recurse, recursive, separator, stringify |

## Links

- npm: https://www.npmjs.com/package/stringify-keys
- Repository: https://github.com/doowb/stringify-keys
- Issues: https://github.com/doowb/stringify-keys/issues
- npm.io page: https://npm.io/package/stringify-keys

## 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

- 3.0.0 (latest) — 2019-01-22
- 2.0.0 — 2018-08-03
- 1.0.1 — 2018-05-15
- 1.0.0 — 2018-01-17
- 0.3.0 — 2015-08-27
- 0.2.0 — 2015-05-21
- 0.1.2 — 2014-12-22
- 0.1.1 — 2014-12-22
- 0.1.0 — 2014-12-22

## README

# stringify-keys [![NPM version](https://img.shields.io/npm/v/stringify-keys.svg?style=flat)](https://www.npmjs.com/package/stringify-keys) [![NPM monthly downloads](https://img.shields.io/npm/dm/stringify-keys.svg?style=flat)](https://npmjs.org/package/stringify-keys) [![NPM total downloads](https://img.shields.io/npm/dt/stringify-keys.svg?style=flat)](https://npmjs.org/package/stringify-keys) [![Linux Build Status](https://img.shields.io/travis/doowb/stringify-keys.svg?style=flat&label=Travis)](https://travis-ci.org/doowb/stringify-keys)

> Build an array of key paths from an object.

Please consider following this project's author, [Brian Woodward](https://github.com/doowb), and consider starring the project to show your :heart: and support.

## Install

Install with [npm](https://www.npmjs.com/):

```sh
$ npm install --save stringify-keys
```

See the [Release History](#release-history) for changes.

## Usage

```js
const stringify = require('stringify-keys');

let obj = { a: 'a', b: { c: { d: { e: 'f' } } } };
console.log(stringify(obj));
//=> [ 'a', 'b.c.d.e' ]
```

Include values in the result:

```js
console.log(stringify(obj, { values: true }));
//=> { a: 'a', 'b.c.d.e': 'f' }
```

Keys with dots are automatically escaped with backslashes (this can be [customized](#optionsescape)):

```js
let obj = { 'a.b.c': { d: 'e' } };
console.log(stringify(obj));
//=> [ 'a\\.b\\.c.d' ]

console.log(stringify(obj, { values: true }));
//=> { 'a\\.b\\.c.d': 'e' }
```

Objects with arrays return the array indices as part of the paths:

```js
let obj = { a: 'a', b: [{ c: { d: 'e' } }, { f: { g: 'h' } }] };

console.log(stringify(obj));
//=> [ 'a', 'b.0.c.d', 'b.1.f.g' ]

console.log(stringify(obj, { values: true }));
//=> { a: 'a', 'b.0.c.d': 'e', 'b.1.f.g': 'h' }
```

## Options

### options.separator

**Type**: `string`

**Default**: `.`

Custom separator to use for creating object paths (`a.b.c`):

**Example**

```js
let obj = { 'a.b.c': { d: 'e' } };
console.log(stringify(obj, { separator: '/' }));
//=>  [ 'a.b.c/d' ]

console.log(stringify(obj, { separator: '/', values: true }));
//=>  { 'a.b.c/d': 'e' }
```

### options.escape

**Type**: `function`

**Default**: adds `\\` before dots

Custom function to use for escaping keys.

**Example**

```js
let obj = { 'a.b.c': { d: 'e' } };
let escape = str => str.split('.').join('/');

console.log(stringify(obj, { escape }));
//=>  [ 'a/b/c.d' ]

console.log(stringify(obj, { escape, values: true }));
//=>  { 'a/b/c.d': 'e' }
```

## Release History

### v3.0

* Redundant (parent) keys are no longer included in the output. Thus `{ a: { b: 'c' } }` now returns `['a.b']` instead of `['a', 'a.b']`.

### v2.0

* Added support for traversing into arrays.

## About

<details>
<summary><strong>Contributing</strong></summary>

Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).

</details>

<details>
<summary><strong>Running Tests</strong></summary>

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

```sh
$ npm install && npm test
```

</details>

<details>
<summary><strong>Building docs</strong></summary>

_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_

To generate the readme, run the following command:

```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```

</details>

### Related projects

You might also be interested in these projects:

* [expand-hash](https://www.npmjs.com/package/expand-hash): Recursively expands property keys with dot-notation into objects. | [homepage](https://github.com/doowb/expand-hash "Recursively expands property keys with dot-notation into objects.")
* [expand-object](https://www.npmjs.com/package/expand-object): Expand a string into a JavaScript object using a simple notation. Use the CLI or… [more](https://github.com/jonschlinkert/expand-object) | [homepage](https://github.com/jonschlinkert/expand-object "Expand a string into a JavaScript object using a simple notation. Use the CLI or as a node.js lib.")
* [glob-object](https://www.npmjs.com/package/glob-object): Filter an object using glob patterns and dot notation. | [homepage](https://github.com/jonschlinkert/glob-object "Filter an object using glob patterns and dot notation.")
* [kind-of](https://www.npmjs.com/package/kind-of): Get the native type of a value. | [homepage](https://github.com/jonschlinkert/kind-of "Get the native type of a value.")

### Contributors

| **Commits** | **Contributor** |  
| --- | --- |  
| 19 | [doowb](https://github.com/doowb) |  
| 17 | [jonschlinkert](https://github.com/jonschlinkert) |  
| 1  | [contra](https://github.com/contra) |  

### Author

**Brian Woodward**

* [GitHub Profile](https://github.com/doowb)
* [Twitter Profile](https://twitter.com/doowb)
* [LinkedIn Profile](https://linkedin.com/in/woodwardbrian)

### License

Copyright © 2019, [Brian Woodward](https://github.com/doowb).
Released under the [MIT License](LICENSE).

***

_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on January 22, 2019._

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