# walk-object-sync

> Walk an object's keys

Latest version **1.0.0** (published 2017-08-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install walk-object-sync
pnpm add walk-object-sync
yarn add walk-object-sync
bun add walk-object-sync
```

## 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.0 |
| Published | 2017-08-10 |
| First published | 2017-08-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Mark McKelvy |
| Maintainers | mmckelvy |
| Keywords | walk object, recursion, nodes object |

## Links

- npm: https://www.npmjs.com/package/walk-object-sync
- Repository: https://github.com/mmckelvy/walk-object-sync
- Homepage: https://github.com/mmckelvy/walk-object-sync#readme
- Issues: https://github.com/mmckelvy/walk-object-sync/issues
- npm.io page: https://npm.io/package/walk-object-sync

## Dependencies (1)

- [is-pure-object](https://npm.io/package/is-pure-object.md) ^1.0.0

## Recent versions

- 1.0.0 (latest) — 2017-08-10

## README

# walk-object-sync
Walks an object's keys, calling a function when each node is reached. Walk will be performed synchronously.  Excludes the async version of walkObject for compatibilty with ES6 and below.

## Example
```
const walkObject = require('walk-object-sync')

const obj = {
  order: {
    number: 123,
    customer: {
      name: 'John Smith'
    },
    items: [
      {
        sku: 456,
        description: 'shirt'
      },
      {
        sku: 789,
        description: 'pants'
      }
    ]
  },
}

walkObject(obj, ({ value, location, isLeaf }) => {
  if (isLeaf) console.log(value, location)
})

//
123, ['order', 'number']
'John Smith', ['order', 'customer', 'name']
456, ['order', 'customer', 'items', 0, 'sku']
'shirt', ['order', 'customer', 'items', 0, 'description']
789, ['order', 'customer', 'items', 1, 'sku']
'pants', ['order', 'customer', 'items', 1, 'description']
```

## Installation
```
npm install --save walk-object-sync
```

## API
#### `walkObject(root, fn)`

param: `{object} root` - The object to walk.

param: `{function} fn` - Function to call on each node.

The function will be passed an object with the following properties:

`value: {any}` - The value of the current node.

`key: {string}` - The key for the current node. If node is an element of an array key will be in the format of `key:index`. See walk-object.test.js for an example.

`location: {array}` - The full location of the current node (see examples above).

`isLeaf: {boolean}` - Whether or not the node is a leaf.

## Test
```
npm test
```

## License
MIT

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