-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add set and construct to object module (#236)
- Loading branch information
Showing
9 changed files
with
289 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
title: construct | ||
description: Builds an object from key paths and values | ||
group: Object | ||
--- | ||
|
||
## Basic usage | ||
|
||
The opposite of crush, given an object that was crushed into key paths and values will return the original object reconstructed. | ||
|
||
```ts | ||
import { construct } from 'radash' | ||
|
||
const flat = { | ||
name: 'ra', | ||
power: 100, | ||
'friend.name': 'loki', | ||
'friend.power': 80, | ||
'enemies.0.name': 'hathor', | ||
'enemies.0.power': 12 | ||
} | ||
|
||
construct(flat) | ||
// { | ||
// name: 'ra', | ||
// power: 100, | ||
// friend: { | ||
// name: 'loki', | ||
// power: 80 | ||
// }, | ||
// enemies: [ | ||
// { | ||
// name: 'hathor', | ||
// power: 12 | ||
// } | ||
// ] | ||
// } | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
title: set | ||
description: Set a value on an object using a path key | ||
group: Object | ||
--- | ||
|
||
## Basic usage | ||
|
||
Opposite of get, dynamically set a nested value into an object using a key path. Does not modify the given initial object. | ||
|
||
```ts | ||
import { set } from 'radash' | ||
|
||
set({}, 'name', 'ra') | ||
// => { name: 'ra' } | ||
|
||
set({}, 'cards[0].value', 2) | ||
// => { cards: [{ value: 2 }] } | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
c30ed56
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
radash-docs – ./
radash-docs-git-master-ray-unishinedev.vercel.app
radash-docs-ray-unishinedev.vercel.app
radash-docs.vercel.app