diff --git a/docs/tool/manifest.js b/docs/tool/manifest.js index 626ed98651b956..256ba292de476a 100644 --- a/docs/tool/manifest.js +++ b/docs/tool/manifest.js @@ -1,7 +1,7 @@ /** * External dependencies */ -const { camelCase, upperFirst } = require( 'lodash' ); +const { pascalCase } = require( 'change-case' ); const fs = require( 'fs' ); const glob = require( 'glob' ).sync; const { join } = require( 'path' ); @@ -54,7 +54,7 @@ function getComponentManifest( paths ) { const pathFragments = filePath.split( '/' ); const slug = pathFragments[ pathFragments.length - 2 ]; return { - title: upperFirst( camelCase( slug ) ), + title: pascalCase( slug ), slug, markdown_source: `${ baseRepoUrl }/${ filePath }`, parent: 'components', @@ -85,7 +85,7 @@ function generateRootManifestFromTOCItems( items, parent = null ) { slug = 'handbook'; } } - let title = upperFirst( camelCase( slug ) ); + let title = pascalCase( slug ); const markdownSource = fs.readFileSync( fileName, 'utf8' ); const titleMarkdown = markdownSource.match( /^#\s(.+)$/m ); if ( titleMarkdown ) { diff --git a/package-lock.json b/package-lock.json index 3ab747322efb4c..186d5a470238c8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16801,6 +16801,7 @@ "@wordpress/is-shallow-equal": "file:packages/is-shallow-equal", "@wordpress/keycodes": "file:packages/keycodes", "@wordpress/priority-queue": "file:packages/priority-queue", + "change-case": "^4.1.2", "clipboard": "^2.0.8", "lodash": "^4.17.21", "mousetrap": "^1.6.5", @@ -16820,6 +16821,7 @@ "@wordpress/i18n": "file:packages/i18n", "@wordpress/is-shallow-equal": "file:packages/is-shallow-equal", "@wordpress/url": "file:packages/url", + "change-case": "^4.1.2", "equivalent-key-map": "^0.2.2", "lodash": "^4.17.21", "memize": "^1.1.0", diff --git a/package.json b/package.json index 17fef1357971e0..feb6815fc7f2b8 100755 --- a/package.json +++ b/package.json @@ -169,6 +169,7 @@ "benchmark": "2.1.4", "browserslist": "4.17.6", "chalk": "4.1.1", + "change-case": "4.1.2", "commander": "9.2.0", "concurrently": "3.5.0", "copy-webpack-plugin": "10.2.0", diff --git a/packages/compose/package.json b/packages/compose/package.json index 8154271edb5a27..7afa2c5e976894 100644 --- a/packages/compose/package.json +++ b/packages/compose/package.json @@ -38,6 +38,7 @@ "@wordpress/is-shallow-equal": "file:../is-shallow-equal", "@wordpress/keycodes": "file:../keycodes", "@wordpress/priority-queue": "file:../priority-queue", + "change-case": "^4.1.2", "clipboard": "^2.0.8", "lodash": "^4.17.21", "mousetrap": "^1.6.5", diff --git a/packages/compose/src/utils/create-higher-order-component/index.ts b/packages/compose/src/utils/create-higher-order-component/index.ts index ca38ea51d2e0c1..90f9787f3149ee 100644 --- a/packages/compose/src/utils/create-higher-order-component/index.ts +++ b/packages/compose/src/utils/create-higher-order-component/index.ts @@ -1,7 +1,7 @@ /** * External dependencies */ -import { camelCase, upperFirst } from 'lodash'; +import { pascalCase } from 'change-case'; import type { ComponentType } from 'react'; type GetProps< C > = C extends ComponentType< infer P > ? P : never; @@ -45,7 +45,7 @@ export function createHigherOrderComponent< */ const hocName = ( name: string, Inner: ComponentType< any > ) => { const inner = Inner.displayName || Inner.name || 'Component'; - const outer = upperFirst( camelCase( name ) ); + const outer = pascalCase( name ?? '' ); return `${ outer }(${ inner })`; }; diff --git a/packages/core-data/package.json b/packages/core-data/package.json index 259004d141589f..9c4705f50063a3 100644 --- a/packages/core-data/package.json +++ b/packages/core-data/package.json @@ -39,6 +39,7 @@ "@wordpress/i18n": "file:../i18n", "@wordpress/is-shallow-equal": "file:../is-shallow-equal", "@wordpress/url": "file:../url", + "change-case": "^4.1.2", "equivalent-key-map": "^0.2.2", "lodash": "^4.17.21", "memize": "^1.1.0", diff --git a/packages/core-data/src/entities.ts b/packages/core-data/src/entities.ts index a73a27dc2c2e7c..3637563adceaa5 100644 --- a/packages/core-data/src/entities.ts +++ b/packages/core-data/src/entities.ts @@ -1,7 +1,8 @@ /** * External dependencies */ -import { upperFirst, camelCase, map, find, get, startCase } from 'lodash'; +import { capitalCase, pascalCase } from 'change-case'; +import { map, find, get } from 'lodash'; /** * WordPress dependencies @@ -457,7 +458,9 @@ async function loadPostTypeEntities() { getTitle: ( record ) => record?.title?.rendered || record?.title || - ( isTemplate ? startCase( record.slug ) : String( record.id ) ), + ( isTemplate + ? capitalCase( record.slug ?? '' ) + : String( record.id ) ), __unstablePrePersist: isTemplate ? undefined : prePersistPostType, __unstable_rest_base: postType.rest_base, }; @@ -511,12 +514,11 @@ export const getMethodName = ( usePlural = false ) => { const entityConfig = find( rootEntitiesConfig, { kind, name } ); - const kindPrefix = kind === 'root' ? '' : upperFirst( camelCase( kind ) ); - const nameSuffix = - upperFirst( camelCase( name ) ) + ( usePlural ? 's' : '' ); + const kindPrefix = kind === 'root' ? '' : pascalCase( kind ); + const nameSuffix = pascalCase( name ) + ( usePlural ? 's' : '' ); const suffix = usePlural && 'plural' in entityConfig! && entityConfig?.plural - ? upperFirst( camelCase( entityConfig.plural ) ) + ? pascalCase( entityConfig.plural ) : nameSuffix; return `${ prefix }${ kindPrefix }${ suffix }`; }; diff --git a/packages/create-block/lib/scaffold.js b/packages/create-block/lib/scaffold.js index 30b173c5dcb0e7..a342a807eec2fc 100644 --- a/packages/create-block/lib/scaffold.js +++ b/packages/create-block/lib/scaffold.js @@ -1,7 +1,7 @@ /** * External dependencies */ -const { camelCase, snakeCase } = require( 'change-case' ); +const { pascalCase, snakeCase } = require( 'change-case' ); /** * Internal dependencies @@ -13,10 +13,6 @@ const initWPEnv = require( './init-wp-env' ); const { code, info, success } = require( './log' ); const { writeOutputAsset, writeOutputTemplate } = require( './output' ); -function upperFirst( str ) { - return str.charAt( 0 ).toUpperCase() + str.substr( 1 ); -} - module.exports = async ( { blockOutputTemplates, pluginOutputTemplates, outputAssets }, { @@ -61,7 +57,7 @@ module.exports = async ( namespaceSnakeCase: snakeCase( namespace ), slug, slugSnakeCase: snakeCase( slug ), - slugPascalCase: upperFirst( camelCase( slug ) ), + slugPascalCase: pascalCase( slug ), title, description, dashicon,