Skip to content

Commit 7a64b73

Browse files
committed
Lodash: Refactor pascal case usages
1 parent 2c23ebe commit 7a64b73

File tree

8 files changed

+20
-32
lines changed

8 files changed

+20
-32
lines changed

docs/tool/manifest.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* External dependencies
33
*/
4-
const { camelCase, upperFirst } = require( 'lodash' );
4+
const { pascalCase } = require( 'change-case' );
55
const fs = require( 'fs' );
66
const glob = require( 'glob' ).sync;
77
const { join } = require( 'path' );
@@ -54,7 +54,7 @@ function getComponentManifest( paths ) {
5454
const pathFragments = filePath.split( '/' );
5555
const slug = pathFragments[ pathFragments.length - 2 ];
5656
return {
57-
title: upperFirst( camelCase( slug ) ),
57+
title: pascalCase( slug ),
5858
slug,
5959
markdown_source: `${ baseRepoUrl }/${ filePath }`,
6060
parent: 'components',
@@ -85,7 +85,7 @@ function generateRootManifestFromTOCItems( items, parent = null ) {
8585
slug = 'handbook';
8686
}
8787
}
88-
let title = upperFirst( camelCase( slug ) );
88+
let title = pascalCase( slug );
8989
const markdownSource = fs.readFileSync( fileName, 'utf8' );
9090
const titleMarkdown = markdownSource.match( /^#\s(.+)$/m );
9191
if ( titleMarkdown ) {

package-lock.json

+2-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@
169169
"benchmark": "2.1.4",
170170
"browserslist": "4.17.6",
171171
"chalk": "4.1.1",
172+
"change-case": "4.1.2",
172173
"commander": "9.2.0",
173174
"concurrently": "3.5.0",
174175
"copy-webpack-plugin": "10.2.0",

packages/compose/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"@wordpress/is-shallow-equal": "file:../is-shallow-equal",
3939
"@wordpress/keycodes": "file:../keycodes",
4040
"@wordpress/priority-queue": "file:../priority-queue",
41+
"change-case": "^4.1.2",
4142
"clipboard": "^2.0.8",
4243
"lodash": "^4.17.21",
4344
"mousetrap": "^1.6.5",

packages/compose/src/utils/create-higher-order-component/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* External dependencies
33
*/
4-
import { camelCase, upperFirst } from 'lodash';
4+
import { pascalCase } from 'change-case';
55
import type { ComponentType } from 'react';
66

77
type GetProps< C > = C extends ComponentType< infer P > ? P : never;
@@ -45,7 +45,7 @@ export function createHigherOrderComponent<
4545
*/
4646
const hocName = ( name: string, Inner: ComponentType< any > ) => {
4747
const inner = Inner.displayName || Inner.name || 'Component';
48-
const outer = upperFirst( camelCase( name ) );
48+
const outer = pascalCase( name ?? '' );
4949

5050
return `${ outer }(${ inner })`;
5151
};

packages/core-data/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"@wordpress/i18n": "file:../i18n",
4040
"@wordpress/is-shallow-equal": "file:../is-shallow-equal",
4141
"@wordpress/url": "file:../url",
42+
"change-case": "^4.1.2",
4243
"equivalent-key-map": "^0.2.2",
4344
"lodash": "^4.17.21",
4445
"memize": "^1.1.0",

packages/core-data/src/entities.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/**
22
* External dependencies
33
*/
4-
import { upperFirst, camelCase, map, find, get, startCase } from 'lodash';
4+
import { capitalCase, pascalCase } from 'change-case';
5+
import { map, find, get } from 'lodash';
56

67
/**
78
* WordPress dependencies
@@ -457,7 +458,9 @@ async function loadPostTypeEntities() {
457458
getTitle: ( record ) =>
458459
record?.title?.rendered ||
459460
record?.title ||
460-
( isTemplate ? startCase( record.slug ) : String( record.id ) ),
461+
( isTemplate
462+
? capitalCase( record.slug ?? '' )
463+
: String( record.id ) ),
461464
__unstablePrePersist: isTemplate ? undefined : prePersistPostType,
462465
__unstable_rest_base: postType.rest_base,
463466
};
@@ -511,12 +514,11 @@ export const getMethodName = (
511514
usePlural = false
512515
) => {
513516
const entityConfig = find( rootEntitiesConfig, { kind, name } );
514-
const kindPrefix = kind === 'root' ? '' : upperFirst( camelCase( kind ) );
515-
const nameSuffix =
516-
upperFirst( camelCase( name ) ) + ( usePlural ? 's' : '' );
517+
const kindPrefix = kind === 'root' ? '' : pascalCase( kind );
518+
const nameSuffix = pascalCase( name ) + ( usePlural ? 's' : '' );
517519
const suffix =
518520
usePlural && 'plural' in entityConfig! && entityConfig?.plural
519-
? upperFirst( camelCase( entityConfig.plural ) )
521+
? pascalCase( entityConfig.plural )
520522
: nameSuffix;
521523
return `${ prefix }${ kindPrefix }${ suffix }`;
522524
};

packages/create-block/lib/scaffold.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* External dependencies
33
*/
4-
const { camelCase, snakeCase } = require( 'change-case' );
4+
const { pascalCase, snakeCase } = require( 'change-case' );
55

66
/**
77
* Internal dependencies
@@ -13,10 +13,6 @@ const initWPEnv = require( './init-wp-env' );
1313
const { code, info, success } = require( './log' );
1414
const { writeOutputAsset, writeOutputTemplate } = require( './output' );
1515

16-
function upperFirst( str ) {
17-
return str.charAt( 0 ).toUpperCase() + str.substr( 1 );
18-
}
19-
2016
module.exports = async (
2117
{ blockOutputTemplates, pluginOutputTemplates, outputAssets },
2218
{
@@ -61,7 +57,7 @@ module.exports = async (
6157
namespaceSnakeCase: snakeCase( namespace ),
6258
slug,
6359
slugSnakeCase: snakeCase( slug ),
64-
slugPascalCase: upperFirst( camelCase( slug ) ),
60+
slugPascalCase: pascalCase( slug ),
6561
title,
6662
description,
6763
dashicon,

0 commit comments

Comments
 (0)