-
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 crush function to object module (#228)
- Loading branch information
Showing
9 changed files
with
113 additions
and
3 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: crush | ||
description: Flattens a deep object to a single dimension | ||
group: Object | ||
--- | ||
|
||
## Basic usage | ||
|
||
Flattens a deep object to a single dimension. The deep keys will be converted to a dot notation in the new object. | ||
|
||
```ts | ||
import { crush } from 'radash' | ||
|
||
const ra = { | ||
name: 'ra', | ||
power: 100, | ||
friend: { | ||
name: 'loki', | ||
power: 80 | ||
}, | ||
enemies: [ | ||
{ | ||
name: 'hathor', | ||
power: 12 | ||
} | ||
] | ||
} | ||
|
||
crush(ra) | ||
// { | ||
// name: 'ra', | ||
// power: 100, | ||
// 'friend.name': 'loki', | ||
// 'friend.power': 80, | ||
// 'enemies.0.name': 'hathor', | ||
// 'enemies.0.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 |
---|---|---|
|
@@ -56,3 +56,5 @@ objectify( | |
// 'enemies.0.power': 12 | ||
// } | ||
``` | ||
|
||
_As of v10.5.0+ you can get this behavior via the crush function_ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,7 @@ export { toFloat, toInt } from './number' | |
export { | ||
assign, | ||
clone, | ||
crush, | ||
get, | ||
invert, | ||
keys, | ||
|
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
b852d2e
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.vercel.app
radash-docs-ray-unishinedev.vercel.app
radash-docs-git-master-ray-unishinedev.vercel.app