Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Replace snake case keys package with change case
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejolley committed Apr 21, 2023
1 parent 8bebf88 commit c10bb11
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 51 deletions.
15 changes: 4 additions & 11 deletions assets/js/base/utils/camel-case-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,10 @@
*/
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,
} ),
{}
);
/**
* Internal dependencies
*/
import { mapKeys } from './map-keys';

export const camelCaseKeys = ( obj: object ) =>
mapKeys( obj, ( _, key ) => camelCase( key ) );
2 changes: 2 additions & 0 deletions assets/js/base/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export * from './get-icons-from-payment-methods';
export * from './parse-style';
export * from './create-notice';
export * from './get-navigation-type';
export * from './map-keys';
export * from './camel-case-keys';
export * from './snake-case-keys';
export * from './debounce';
export * from './keyby';
11 changes: 11 additions & 0 deletions assets/js/base/utils/map-keys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const mapKeys = (
obj: object,
mapper: ( value: unknown, key: string ) => string
) =>
Object.entries( obj ).reduce(
( acc, [ key, value ] ) => ( {
...acc,
[ mapper( value, key ) ]: value,
} ),
{}
);
12 changes: 12 additions & 0 deletions assets/js/base/utils/snake-case-keys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* External dependencies
*/
import { snakeCase } from 'change-case';

/**
* Internal dependencies
*/
import { mapKeys } from './map-keys';

export const snakeCaseKeys = ( obj: object ) =>
mapKeys( obj, ( _, key ) => snakeCase( key ) );
40 changes: 3 additions & 37 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@
"react-number-format": "4.9.3",
"react-transition-group": "^4.4.5",
"reakit": "1.3.11",
"snakecase-keys": "5.4.2",
"trim-html": "0.1.9",
"use-debounce": "7.0.1",
"wordpress-components": "npm:@wordpress/components@14.2.0"
Expand Down
4 changes: 2 additions & 2 deletions storybook/custom-controls/currency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* External dependencies
*/
import { Currency, CurrencyResponse } from '@woocommerce/types';
import snakecaseKeys from 'snakecase-keys';
import { snakeCaseKeys } from '@woocommerce/base-utils';

export const currencies: Record< string, Currency > = {
EUR: {
Expand All @@ -29,7 +29,7 @@ export const currenciesAPIShape: Record< string, CurrencyResponse > =
Object.fromEntries(
Object.entries( currencies ).map( ( [ key, value ] ) => [
key,
snakecaseKeys( value ),
snakeCaseKeys( value ),
] )
);

Expand Down

0 comments on commit c10bb11

Please sign in to comment.