Skip to content

Commit

Permalink
chore: update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mew-ton committed Oct 5, 2023
1 parent 6d4a75f commit a4fe7f5
Showing 1 changed file with 76 additions and 3 deletions.
79 changes: 76 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ Whether you're looking to flatten a nested structure or revert a flat map into i
## Key Features

- **Lightweight & Standalone**: Operates without any external dependencies, ensuring quick installations and reduced bundle sizes.
- **fold**: Flatten a multi-layered JSON object into a single-tiered representation.
- **unfold**: Transform a single-layer JSON map back to its original nested structure.
- **twist**: Reshape and reorganize the keys of your JSON structure, mirroring the intricate adjustments made in origami.
- **Simple & Intuitive**: Designed with a simple API that is easy to learn and use.

## Installation

Expand All @@ -25,6 +23,8 @@ npm install json-origami

### fold

Flatten a multi-layered JSON object into a single-tiered representation.

```javascript
import { fold } from 'json-origami'

Expand All @@ -42,6 +42,8 @@ console.log(result)

### unfold

Transform a single-layer JSON map back to its original nested structure.

```javascript
import { unfold } from 'json-origami'

Expand All @@ -59,6 +61,8 @@ console.log(result)

### twist

Reshape and reorganize the keys of your JSON structure, mirroring the intricate adjustments made in origami.

```javascript
import { twist } from 'json-origami'

Expand All @@ -81,6 +85,46 @@ console.log(result)
/// { foo: 1, bar: 2, baz: [3, { e: 4 }] }
```

### pick

Select only the specified keys from a JSON object.

```javascript
import { pick } from 'json-origami'

const obj = {
a: 1,
b: {
c: 2,
d: [3, { e: 4 }]
}
}

const result = pick(obj, ['a', 'b.c'])
console.log(result)
/// { a: 1, b: { c: 2 } }
```

### omit

Remove the specified keys from a JSON object.

```javascript
import { omit } from 'json-origami'

const obj = {
a: 1,
b: {
c: 2,
d: [3, { e: 4 }]
}
}

const result = omit(obj, ['b.c', 'b.d[1]'])
console.log(result)
/// { a: 1, b: { d: [3] } }
```

## Options

### arrayIndex
Expand All @@ -106,6 +150,35 @@ conole.log(result)
/// { a: 1, 'b.c': 2, 'b.d.0': 3, 'b.d.1.e': 4 }
```

### pruneArray

Options for 'unfold', 'twist', 'pick', 'omit'

**Type**: `boolean`
**Default**: `true`

Specifies whether to remove the specified array elements or not.

```javascript
import { twist } from 'json-origami'

const obj = {
a: 1,
b: {
c: 2,
d: [3, 4, 5, 6]
}
}

const result1 = twist(obj, { 'b.d[1]': 'D' }, { pruneArray: true })
console.log(result1)
/// { a: 1, b: { c: 2, d: [3, 5, 6] }, D: 4 }

const result2 = twist(obj, { 'b.d[1]': 'D' }, { pruneArray: false })
console.log(result2)
/// { a: 1, b: { c: 2, d: [3, undefined, 5, 6] }, D: 4 }
```

### keyPrefix

Options for 'fold'
Expand Down

0 comments on commit a4fe7f5

Please sign in to comment.