This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace lodash mapKeys with function Move mapkeys to utility Create camelCaseKeys which replaces usage of mapKeys
- Loading branch information
1 parent
2e91696
commit f466acc
Showing
6 changed files
with
34 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { camelCase } from 'change-case'; | ||
|
||
const mapKeys = ( | ||
obj: object, | ||
mapper: ( value: unknown, key: string ) => string | ||
) => | ||
Object.entries( obj ).reduce( | ||
( acc, [ key, value ] ) => ( { | ||
...acc, | ||
[ mapper( value, key ) ]: value, | ||
} ), | ||
{} | ||
); | ||
|
||
export const camelCaseKeys = ( obj: object ) => | ||
mapKeys( obj, ( _, key ) => camelCase( key ) ); |
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
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