# @alexdee2007/deeks

> Retrieve all keys and nested keys from objects and arrays of objects.

Latest version **2.3.0** (published 2020-12-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install @alexdee2007/deeks
pnpm add @alexdee2007/deeks
yarn add @alexdee2007/deeks
bun add @alexdee2007/deeks
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.3.0 |
| Published | 2020-12-15 |
| First published | 2020-12-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 10 |
| Dependencies | 0 |
| Unpacked size | 11.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | mrodrig |
| Maintainers | alexdee2007 |
| Keywords | get, keys, object, document, deep, deeks, recursive |

## Links

- npm: https://www.npmjs.com/package/@alexdee2007/deeks
- Repository: https://github.com/mrodrig/deeks
- Homepage: https://mrodrig.github.io/deeks
- Issues: https://github.com/mrodrig/deeks/issues
- npm.io page: https://npm.io/package/@alexdee2007/deeks

## Alternatives

- [@cantoo/pdf-lib](https://npm.io/package/@cantoo/pdf-lib.md) — 297.9K weekly downloads
- [datatables.net-buttons](https://npm.io/package/datatables.net-buttons.md) — 200.1K weekly downloads
- [@ckeditor/ckeditor5-export-pdf](https://npm.io/package/@ckeditor/ckeditor5-export-pdf.md) — 167.0K weekly downloads
- [scanbot-web-sdk](https://npm.io/package/scanbot-web-sdk.md) — 15.0K weekly downloads
- [@syncfusion/ej2-angular-pdfviewer](https://npm.io/package/@syncfusion/ej2-angular-pdfviewer.md) — 8.8K weekly downloads

## Recent versions

- 2.3.0 (latest) — 2020-12-15

## README

# deeks - Deep Object Key Extraction

[![Dependencies](https://img.shields.io/david/mrodrig/deeks.svg)](https://www.npmjs.org/package/deeks)
[![Downloads](http://img.shields.io/npm/dm/deeks.svg)](https://www.npmjs.org/package/deeks)
[![NPM version](https://img.shields.io/npm/v/deeks.svg)](https://www.npmjs.org/package/deeks)
[![Minzipped Size](https://flat.badgen.net/bundlephobia/minzip/deeks)](https://bundlephobia.com/result?p=deeks)

[![Build Status](https://travis-ci.org/mrodrig/deeks.svg?branch=master)](https://travis-ci.org/mrodrig/deeks)
[![Coverage Status](https://coveralls.io/repos/github/mrodrig/deeks/badge.svg?branch=stable)](https://coveralls.io/github/mrodrig/deeks?branch=stable)
[![Maintainability](https://api.codeclimate.com/v1/badges/830bc7f29f61466986ac/maintainability)](https://codeclimate.com/github/mrodrig/deeks/maintainability)

**Retrieve all keys and nested keys from objects and arrays of objects.**

## Installing

```bash
npm install --save deeks
```

Example: 
```javascript
let keys = require('deeks'),
	docPath = require('doc-path');

let generatedKeys = keys.deepKeys({
	make: 'Nissan',
	model: 'GT-R',
	trim: 'NISMO',
	specifications: [
	    {mileage: 10},
	    {cylinders: 6}
	]
}, {
    expandArrayObjects: true,
    ignoreEmptyArraysWhenExpanding: true
});
// => ['make', 'model', 'trim', 'specifications.mileage', 'specifications.cylinders']

generatedKeys.forEach((key) => 
    console.log(
        docPath.evaluatePath(key)
    )
)
// Console Output:
// Nissan
// GT-R
// NISMO
// 10
// 6
```

## API

### deepKeys(object) 

`keys.deepKeys(object, options)`

Returns all keys in an object, even if they're nested several layers deep. 
The array of keys that is returned can then be used with the 
[`doc-path`](https://github.com/mrodrig/doc-path) module to get and set values 
at a specific key path.

Options (optional):
- expandArrayObjects - `Boolean` (Default: `false`) - Should objects appearing in arrays in the provided 
object also be expanded, such that keys appearing in those objects are extracted and 
included in the returned key path list?
	- Example:
	```json
	{
		"make": "Nissan",
		"model": "GT-R",
		"trim": "NISMO",
		"specifications": [
			{"mileage": 10},
			{"cylinders": 6}
		]
	}
	```
	- expandArrayObjects = `false` results in: `['make', 'model', 'trim', 'specifications']`
	- expandArrayObjects = `true` results in: `['make', 'model', 'trim', 'specifications.mileage', 'specifications.cylinders']`
- ignoreEmptyArraysWhenExpanding - `Boolean` (Default: `false`) - Should empty array keys be ignored when expanding array objects?
	- Note: This only has an effect when used with `expandArrayObjects`.
	- Example:
	```json
	{ 
		"features": [ {"name": "A/C" }],
		"rebates": []
	}
	```
	- ignoreEmptyArraysWhenExpanding = `false` results in: `['features.name', 'rebates']`
	- ignoreEmptyArraysWhenExpanding = `true` results in: `['features.name']`

Returns: `Array[String]`

Example: `['make', 'model', 'specifications.odometer.miles', 'specifications.odometer.kilometers']`

### deepKeysFromList(array) 

`keys.deepKeysFromList(array)`

Returns all keys in each object in the array, even if the keys are nested 
several layers deep in each of the documents. These can also be used with the 
[`doc-path`](https://github.com/mrodrig/doc-path) module.

Options (optional):
- expandArrayObjects - `Boolean` (Default: `false`) - Should objects appearing in arrays in the provided 
object also be expanded, such that keys appearing in those objects are extracted and 
included in the returned key path list?
	- Example:
	```json
	{
		"make": "Nissan",
		"model": "GT-R",
		"trim": "NISMO",
		"specifications": [
			{"mileage": 10},
			{"cylinders": 6}
		]
	}
	```
	- expandArrayObjects = `false` results in: `['make', 'model', 'trim', 'specifications']`
	- expandArrayObjects = `true` results in: `['make', 'model', 'trim', 'specifications.mileage', 'specifications.cylinders']`
- ignoreEmptyArraysWhenExpanding - `Boolean` (Default: `false`) - Should empty array keys be ignored when expanding array objects?
	- Note: This only has an effect when used with `expandArrayObjects`.
	- Example:
	```json
	[
		{ "features": [ {"name": "A/C" }] },
		{ "features": [] }
	] 
	```
	- ignoreEmptyArraysWhenExpanding = `false` results in: `['features.name', 'features']`
	- ignoreEmptyArraysWhenExpanding = `true` results in: `['features.name']`

Returns: `Array[Array[String]]`

Example: `[ ['make', 'model', 'specifications.odometer.miles', 'specifications.odometer.kilometers'] ]`

## Examples

This module integrates really nicely with the 
[`doc-path`](https://github.com/mrodrig/doc-path) module, which allows
the programmatic getting and setting of key paths produced by this module.

Here's an example of how this works:

```javascript
const path = require('doc-path'),
      keys = require('deeks');

let car = {
		make: 'Nissan',
		model: 'GT-R',
		trim: 'NISMO',
		specifications: {
			mileage: 10,
			cylinders: '6'
		}
	},
	
	carKeys = keys.deepKeys(car);

for(let keyPath of carKeys) {
    // Clear all values
    path.setPath(car, keyPath, '');
}
```

## Tests

```bash
$ npm test
```

_Note_: This requires `mocha`, `should`, and `underscore`.

To see test coverage, please run:
```bash
$ npm run coverage
```

Current Coverage is:
```
Statements   : 100% ( 46/46 )
Branches     : 100% ( 30/30 )
Functions    : 100% ( 9/9 )
Lines        : 100% ( 45/45 )
```

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