Skip to content

Commit

Permalink
Lodash: Refactor away from _.capitalize()
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla committed Aug 4, 2022
1 parent f929308 commit 939bae6
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Expand Up @@ -79,6 +79,7 @@ module.exports = {
{
name: 'lodash',
importNames: [
'capitalize',
'chunk',
'clamp',
'compact',
Expand Down
2 changes: 2 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions packages/e2e-test-utils-playwright/package.json
Expand Up @@ -34,6 +34,7 @@
"@wordpress/api-fetch": "file:../api-fetch",
"@wordpress/keycodes": "file:../keycodes",
"@wordpress/url": "file:../url",
"change-case": "^4.1.2",
"form-data": "^4.0.0",
"lodash": "^4.17.21"
},
Expand Down
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { capitalize } from 'lodash';
import { capitalCase } from 'change-case';
import type { Page } from '@playwright/test';

/**
Expand Down Expand Up @@ -123,7 +123,7 @@ export async function pressKeyWithModifier(
_isApple() ? [ SHIFT, ALT ] : [ SHIFT, CTRL ],
};
const mappedModifiers = overWrittenModifiers[ modifier ]( isAppleOS ).map(
( keycode ) => ( keycode === CTRL ? 'Control' : capitalize( keycode ) )
( keycode ) => ( keycode === CTRL ? 'Control' : capitalCase( keycode ) )
);

await this.page.keyboard.press(
Expand Down
6 changes: 3 additions & 3 deletions packages/e2e-test-utils/src/press-key-with-modifier.js
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { capitalize } from 'lodash';
import { capitalCase } from 'change-case';

/**
* WordPress dependencies
Expand Down Expand Up @@ -168,7 +168,7 @@ export async function pressKeyWithModifier( modifier, key ) {

await Promise.all(
mappedModifiers.map( async ( mod ) => {
const capitalizedMod = capitalize( ctrlSwap( mod ) );
const capitalizedMod = capitalCase( ctrlSwap( mod ) );
return page.keyboard.down( capitalizedMod );
} )
);
Expand All @@ -177,7 +177,7 @@ export async function pressKeyWithModifier( modifier, key ) {

await Promise.all(
mappedModifiers.map( async ( mod ) => {
const capitalizedMod = capitalize( ctrlSwap( mod ) );
const capitalizedMod = capitalCase( ctrlSwap( mod ) );
return page.keyboard.up( capitalizedMod );
} )
);
Expand Down
1 change: 1 addition & 0 deletions packages/keycodes/package.json
Expand Up @@ -29,6 +29,7 @@
"dependencies": {
"@babel/runtime": "^7.16.0",
"@wordpress/i18n": "file:../i18n",
"change-case": "^4.1.2",
"lodash": "^4.17.21"
},
"publishConfig": {
Expand Down
7 changes: 4 additions & 3 deletions packages/keycodes/src/index.js
Expand Up @@ -12,7 +12,8 @@
/**
* External dependencies
*/
import { get, mapValues, includes, capitalize, xor } from 'lodash';
import { capitalCase } from 'change-case';
import { get, mapValues, includes, xor } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -232,7 +233,7 @@ export const displayShortcutList = mapValues( modifiers, ( modifier ) => {
/** @type {string[]} */ ( [] )
);

const capitalizedCharacter = capitalize( character );
const capitalizedCharacter = capitalCase( character );
return [ ...modifierKeys, capitalizedCharacter ];
};
} );
Expand Down Expand Up @@ -294,7 +295,7 @@ export const shortcutAriaLabel = mapValues( modifiers, ( modifier ) => {
};

return [ ...modifier( _isApple ), character ]
.map( ( key ) => capitalize( get( replacementKeyMap, key, key ) ) )
.map( ( key ) => capitalCase( get( replacementKeyMap, key, key ) ) )
.join( isApple ? ' ' : ' + ' );
};
} );
Expand Down

0 comments on commit 939bae6

Please sign in to comment.