Skip to content

Commit

Permalink
docs: update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rubeniskov committed Nov 23, 2020
1 parent 5c27fed commit bfa316d
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 14 deletions.
60 changes: 52 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ for (;;) {
console.log(value);
}
```
### Outputs
## Outputs

### [Default options](#traversejsonoptions--object)

__{}__
```
[ '/foo', 0 ]
Expand All @@ -87,6 +90,10 @@ __{}__
[ '/nested/nested/nested/nested/depth', 4 ]
[ '/bar', 1 ]
```


### Return eather the nested and flatten values

__{ [nested](#traversejsonoptions--object): true }__
```
[ '/foo', 0 ]
Expand All @@ -102,26 +109,42 @@ __{ [nested](#traversejsonoptions--object): true }__
[ '/nested/nested/nested/nested/depth', 4 ]
[ '/bar', 1 ]
```


### Only traverse on depth 1

__{ [recursive](#traversejsonoptions--object): false }__
```
[ '/foo', 0 ]
[ '/nested',
{ depth: 1, nested: { depth: 2, nested: [Object] } } ]
[ '/bar', 1 ]
```


### Skips even entries

__{ [step](#traversejsonoptions--object): 2 }__
```
[ '/foo', 0 ]
[ '/bar', 1 ]
```


### Match only the paths ending with _depth_

__{ [test](#traversejsonoptions--object): /depth$/ }__
```
[ '/nested/depth', 1 ]
[ '/nested/nested/depth', 2 ]
[ '/nested/nested/nested/depth', 3 ]
[ '/nested/nested/nested/nested/depth', 4 ]
```
__{ [test](#traversejsonoptions--object): /nested$/, nested: true }__


### Return eather the nested and flatten values ending with _nested_

__{ [test](#traversejsonoptions--object): /nested$/, [nested](#traversejsonoptions--object): true }__
```
[ '/nested',
{ depth: 1, nested: { depth: 2, nested: [Object] } } ]
Expand All @@ -130,6 +153,10 @@ __{ [test](#traversejsonoptions--object): /nested$/, nested: true }__
[ '/nested/nested/nested', { depth: 3, nested: { depth: 4 } } ]
[ '/nested/nested/nested/nested', { depth: 4 } ]
```


### Match only the paths ending with _foo_ or _depth_

__{ [test](#traversejsonoptions--object): "**/{depth,foo}" }__
```
[ '/foo', 0 ]
Expand All @@ -138,11 +165,28 @@ __{ [test](#traversejsonoptions--object): "**/{depth,foo}" }__
[ '/nested/nested/nested/depth', 3 ]
[ '/nested/nested/nested/nested/depth', 4 ]
```


### Match entries which has a number value equal or greater than 3

__{ [test](#traversejsonoptions--object): ([,value]) => typeof value === 'number' && value >= 3 }__
```
[ '/nested/nested/nested/depth', 3 ]
[ '/nested/nested/nested/nested/depth', 4 ]
```


### Traverse recursively through the same key

__{ [test](#traversejsonoptions--object): "@nested" }__
```
[ '/nested',
{ depth: 1, nested: { depth: 2, nested: [Object] } } ]
[ '/nested/nested',
{ depth: 2, nested: { depth: 3, nested: [Object] } } ]
[ '/nested/nested/nested', { depth: 3, nested: { depth: 4 } } ]
[ '/nested/nested/nested/nested', { depth: 4 } ]
```
<a name="createIterator"></a>

## createIterator(obj, [opts]) ⇒ <code>Iterable</code>
Expand Down Expand Up @@ -195,12 +239,12 @@ for (let [k, v] of ientries) {
**Kind**: global typedef
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| [opts.recursive] | <code>Boolean</code> | enable/disable nested arrays and objects recursion |
| [opts.nested] | <code>Boolean</code> | also emit nested array or objects |
| [opts.step] | <code>Boolean</code> | the step to increment, default 1 |
| [opts.test] | <code>String</code> \| <code>function</code> \| <code>RegeExp</code> | regexp, string [minimatch](https://www.npmjs.com/package/minimatch) or function to filter properties |
| Name | Type | Default | Description |
| --- | --- | --- | --- |
| [opts.recursive] | <code>Boolean</code> | <code>true</code> | enable/disable nested arrays and objects recursion |
| [opts.nested] | <code>Boolean</code> | <code>false</code> | also emit nested array or objects |
| [opts.step] | <code>Boolean</code> | <code>1</code> | the step to increment, default 1 |
| [opts.test] | <code>String</code> \| <code>function</code> \| <code>RegeExp</code> | <code></code> | regexp, string [minimatch](https://www.npmjs.com/package/minimatch) or function to filter properties |
<a name="TraverseJsonEntry"></a>
Expand Down
47 changes: 41 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ const {

/**
* @typedef {Object} TraverseJsonOptions
* @prop {Boolean} [opts.recursive] enable/disable nested arrays and objects recursion
* @prop {Boolean} [opts.nested] also emit nested array or objects
* @prop {Boolean} [opts.step] the step to increment, default 1
* @prop {String|Function|RegeExp} [opts.test] regexp, string [minimatch](https://www.npmjs.com/package/minimatch) or function to filter properties
* @prop {Boolean} [opts.recursive=true] enable/disable nested arrays and objects recursion
* @prop {Boolean} [opts.nested=false] also emit nested array or objects
* @prop {Boolean} [opts.step=1] the step to increment, default 1
* @prop {String|Function|RegeExp} [opts.test=null] regexp, string [minimatch](https://www.npmjs.com/package/minimatch) or function to filter properties
*/

/**
Expand Down Expand Up @@ -69,7 +69,10 @@ const {
* console.log(value);
* }
* ```
* ### Outputs
* ## Outputs
*
* ### [Default options](#traversejsonoptions--object)
*
* __{}__
* ```
* [ '/foo', 0 ]
Expand All @@ -79,6 +82,10 @@ const {
* [ '/nested/nested/nested/nested/depth', 4 ]
* [ '/bar', 1 ]
* ```
*
*
* ### Return eather the nested and flatten values
*
* __{ [nested](#traversejsonoptions--object): true }__
* ```
* [ '/foo', 0 ]
Expand All @@ -94,26 +101,42 @@ const {
* [ '/nested/nested/nested/nested/depth', 4 ]
* [ '/bar', 1 ]
* ```
*
*
* ### Only traverse on depth 1
*
* __{ [recursive](#traversejsonoptions--object): false }__
* ```
* [ '/foo', 0 ]
* [ '/nested',
* { depth: 1, nested: { depth: 2, nested: [Object] } } ]
* [ '/bar', 1 ]
* ```
*
*
* ### Skips even entries
*
* __{ [step](#traversejsonoptions--object): 2 }__
* ```
* [ '/foo', 0 ]
* [ '/bar', 1 ]
* ```
*
*
* ### Match only the paths ending with _depth_
*
* __{ [test](#traversejsonoptions--object): /depth$/ }__
* ```
* [ '/nested/depth', 1 ]
* [ '/nested/nested/depth', 2 ]
* [ '/nested/nested/nested/depth', 3 ]
* [ '/nested/nested/nested/nested/depth', 4 ]
* ```
* __{ [test](#traversejsonoptions--object): /nested$/, nested: true }__
*
*
* ### Return eather the nested and flatten values ending with _nested_
*
* __{ [test](#traversejsonoptions--object): /nested$/, [nested](#traversejsonoptions--object): true }__
* ```
* [ '/nested',
* { depth: 1, nested: { depth: 2, nested: [Object] } } ]
Expand All @@ -122,6 +145,10 @@ const {
* [ '/nested/nested/nested', { depth: 3, nested: { depth: 4 } } ]
* [ '/nested/nested/nested/nested', { depth: 4 } ]
* ```
*
*
* ### Match only the paths ending with _foo_ or _depth_
*
* __{ [test](#traversejsonoptions--object): "&#42;&#42;/{depth,foo}" }__
* ```
* [ '/foo', 0 ]
Expand All @@ -130,11 +157,19 @@ const {
* [ '/nested/nested/nested/depth', 3 ]
* [ '/nested/nested/nested/nested/depth', 4 ]
* ```
*
*
* ### Match entries which has a number value equal or greater than 3
*
* __{ [test](#traversejsonoptions--object): ([,value]) => typeof value === 'number' && value >= 3 }__
* ```
* [ '/nested/nested/nested/depth', 3 ]
* [ '/nested/nested/nested/nested/depth', 4 ]
* ```
*
*
* ### Traverse recursively through the same key
*
* __{ [test](#traversejsonoptions--object): "@nested" }__
* ```
* [ '/nested',
Expand Down

0 comments on commit bfa316d

Please sign in to comment.