From 6e30f08ffa28579a0a3a21daf1f7935414672c01 Mon Sep 17 00:00:00 2001 From: Aki Hamano <54422211+t-hamano@users.noreply.github.com> Date: Fri, 15 Dec 2023 11:11:53 +0900 Subject: [PATCH] Quality: Replace wpKebabCase function with kebabCase function from components package (#57038) --- .../font-library-modal/utils/index.js | 18 ++++-------- .../utils/test/wpKebabCase.spec.js | 28 ------------------- 2 files changed, 5 insertions(+), 41 deletions(-) delete mode 100644 packages/edit-site/src/components/global-styles/font-library-modal/utils/test/wpKebabCase.spec.js diff --git a/packages/edit-site/src/components/global-styles/font-library-modal/utils/index.js b/packages/edit-site/src/components/global-styles/font-library-modal/utils/index.js index f5723f5814e98..69db09d49a0ce 100644 --- a/packages/edit-site/src/components/global-styles/font-library-modal/utils/index.js +++ b/packages/edit-site/src/components/global-styles/font-library-modal/utils/index.js @@ -1,12 +1,13 @@ /** - * External dependencies + * WordPress dependencies */ -import { paramCase as kebabCase } from 'change-case'; +import { privateApis as componentsPrivateApis } from '@wordpress/components'; /** * Internal dependencies */ import { FONT_WEIGHTS, FONT_STYLES } from './constants'; +import { unlock } from '../../../../lock-unlock'; export function setUIValuesNeeded( font, extraValues = {} ) { if ( ! font.name && ( font.fontFamily || font.slug ) ) { @@ -129,20 +130,11 @@ export function getDisplaySrcFromFontFace( input, urlPrefix ) { return src; } -// This function replicates one behavior of _wp_to_kebab_case(). -// Additional context: https://github.com/WordPress/gutenberg/issues/53695 -export function wpKebabCase( str ) { - // If a string contains a digit followed by a number, insert a dash between them. - return kebabCase( str ).replace( - /([a-zA-Z])(\d)|(\d)([a-zA-Z])/g, - '$1$3-$2$4' - ); -} - export function makeFormDataFromFontFamilies( fontFamilies ) { const formData = new FormData(); const newFontFamilies = fontFamilies.map( ( family, familyIndex ) => { - family.slug = wpKebabCase( family.slug ); + const { kebabCase } = unlock( componentsPrivateApis ); + family.slug = kebabCase( family.slug ); if ( family?.fontFace ) { family.fontFace = family.fontFace.map( ( face, faceIndex ) => { if ( face.file ) { diff --git a/packages/edit-site/src/components/global-styles/font-library-modal/utils/test/wpKebabCase.spec.js b/packages/edit-site/src/components/global-styles/font-library-modal/utils/test/wpKebabCase.spec.js deleted file mode 100644 index d296117ff3a49..0000000000000 --- a/packages/edit-site/src/components/global-styles/font-library-modal/utils/test/wpKebabCase.spec.js +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Internal dependencies - */ -import { wpKebabCase } from '../index'; - -describe( 'wpKebabCase', () => { - it( 'should insert a dash between a letter and a digit', () => { - const input = 'abc1def'; - const expectedOutput = 'abc-1def'; - expect( wpKebabCase( input ) ).toEqual( expectedOutput ); - - const input2 = 'abc1def2ghi'; - const expectedOutput2 = 'abc-1def-2ghi'; - expect( wpKebabCase( input2 ) ).toEqual( expectedOutput2 ); - } ); - - it( 'should not insert a dash between two letters', () => { - const input = 'abcdef'; - const expectedOutput = 'abcdef'; - expect( wpKebabCase( input ) ).toEqual( expectedOutput ); - } ); - - it( 'should not insert a dash between a digit and a hyphen', () => { - const input = 'abc1-def'; - const expectedOutput = 'abc-1-def'; - expect( wpKebabCase( input ) ).toEqual( expectedOutput ); - } ); -} );