Skip to content

Commit

Permalink
Lodash: Refactor pascal case usages (#42466)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla authored Aug 10, 2022
1 parent a5704d7 commit 9053384
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 17 deletions.
6 changes: 3 additions & 3 deletions docs/tool/manifest.js
Original file line number Diff line number Diff line change
@@ -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' );
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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 ) {
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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions packages/compose/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 })`;
};
1 change: 1 addition & 0 deletions packages/core-data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 8 additions & 6 deletions packages/core-data/src/entities.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
};
Expand Down Expand Up @@ -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 }`;
};
Expand Down
8 changes: 2 additions & 6 deletions packages/create-block/lib/scaffold.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
const { camelCase, snakeCase } = require( 'change-case' );
const { pascalCase, snakeCase } = require( 'change-case' );

/**
* Internal dependencies
Expand All @@ -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 },
{
Expand Down Expand Up @@ -61,7 +57,7 @@ module.exports = async (
namespaceSnakeCase: snakeCase( namespace ),
slug,
slugSnakeCase: snakeCase( slug ),
slugPascalCase: upperFirst( camelCase( slug ) ),
slugPascalCase: pascalCase( slug ),
title,
description,
dashicon,
Expand Down

0 comments on commit 9053384

Please sign in to comment.