From a1e9389abba0add1550654cbe4c1c5bc844638ab Mon Sep 17 00:00:00 2001 From: Marin Atanasov Date: Mon, 6 Mar 2023 13:29:38 +0200 Subject: [PATCH 1/3] Lodash: Refactor away from _.kebabCase() in EditorHelpTopics --- packages/editor/src/components/editor-help/index.native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/editor/src/components/editor-help/index.native.js b/packages/editor/src/components/editor-help/index.native.js index 50b988b666d0af..953083d0f8f475 100644 --- a/packages/editor/src/components/editor-help/index.native.js +++ b/packages/editor/src/components/editor-help/index.native.js @@ -1,7 +1,7 @@ /** * External dependencies */ -import { kebabCase } from 'lodash'; +import { paramCase as kebabCase } from 'change-case'; import { SafeAreaView, ScrollView, StyleSheet, View } from 'react-native'; import { TransitionPresets } from '@react-navigation/stack'; From e002a14ed643e8db2efd8857b66f32b51c792bad Mon Sep 17 00:00:00 2001 From: Marin Atanasov Date: Mon, 6 Mar 2023 14:09:04 +0200 Subject: [PATCH 2/3] Add non-ASCII support --- .../src/components/editor-help/index.native.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/editor/src/components/editor-help/index.native.js b/packages/editor/src/components/editor-help/index.native.js index 953083d0f8f475..6b683422cc6181 100644 --- a/packages/editor/src/components/editor-help/index.native.js +++ b/packages/editor/src/components/editor-help/index.native.js @@ -1,7 +1,7 @@ /** * External dependencies */ -import { paramCase as kebabCase } from 'change-case'; +import { kebabCase } from 'lodash'; import { SafeAreaView, ScrollView, StyleSheet, View } from 'react-native'; import { TransitionPresets } from '@react-navigation/stack'; @@ -57,6 +57,14 @@ const HELP_TOPICS = [ }, ]; +const kebabCaseSettings = { + splitRegexp: [ + /([\p{Ll}\p{Lo}\p{N}])([\p{Lu}\p{Lt}])/gu, // One lowercase or digit, followed by one uppercase. + /([\p{Lu}\p{Lt}])([\p{Lu}\p{Lt}][\p{Ll}\p{Lo}])/gu, // One uppercase followed by one uppercase and one lowercase. + ], + stripRegexp: /(\p{C}|\p{P}|\p{S})+/giu, // Anything that's not a punctuation, symbol or control/format character. +}; + function EditorHelpTopics( { close, isVisible, onClose, showSupport } ) { const { postType } = useSelect( ( select ) => ( { postType: select( editorStore ).getEditedPostAttribute( 'type' ), @@ -145,7 +153,10 @@ function EditorHelpTopics( { close, isVisible, onClose, showSupport } ) { index ) => { const labelSlug = - kebabCase( label ); + kebabCase( + label, + kebabCaseSettings + ); const isLastItem = index === HELP_TOPICS.length - @@ -178,7 +189,7 @@ function EditorHelpTopics( { close, isVisible, onClose, showSupport } ) { { /* Print out help detail screens. */ } { HELP_TOPICS.map( ( { view, label } ) => { - const labelSlug = kebabCase( label ); + const labelSlug = kebabCase( label, kebabCaseSettings ); return ( Date: Mon, 6 Mar 2023 14:44:37 +0200 Subject: [PATCH 3/3] Abstract settings to a separate fn --- .../src/components/editor-help/index.native.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/editor/src/components/editor-help/index.native.js b/packages/editor/src/components/editor-help/index.native.js index 6b683422cc6181..306bfd229aed82 100644 --- a/packages/editor/src/components/editor-help/index.native.js +++ b/packages/editor/src/components/editor-help/index.native.js @@ -1,7 +1,7 @@ /** * External dependencies */ -import { kebabCase } from 'lodash'; +import { paramCase } from 'change-case'; import { SafeAreaView, ScrollView, StyleSheet, View } from 'react-native'; import { TransitionPresets } from '@react-navigation/stack'; @@ -65,6 +65,10 @@ const kebabCaseSettings = { stripRegexp: /(\p{C}|\p{P}|\p{S})+/giu, // Anything that's not a punctuation, symbol or control/format character. }; +function kebabCase( string ) { + return paramCase( string, kebabCaseSettings ); +} + function EditorHelpTopics( { close, isVisible, onClose, showSupport } ) { const { postType } = useSelect( ( select ) => ( { postType: select( editorStore ).getEditedPostAttribute( 'type' ), @@ -153,10 +157,7 @@ function EditorHelpTopics( { close, isVisible, onClose, showSupport } ) { index ) => { const labelSlug = - kebabCase( - label, - kebabCaseSettings - ); + kebabCase( label ); const isLastItem = index === HELP_TOPICS.length - @@ -189,7 +190,7 @@ function EditorHelpTopics( { close, isVisible, onClose, showSupport } ) { { /* Print out help detail screens. */ } { HELP_TOPICS.map( ( { view, label } ) => { - const labelSlug = kebabCase( label, kebabCaseSettings ); + const labelSlug = kebabCase( label ); return (