-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New string package: add kebab-case utility and migrate private API calls
#81294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
oandregal
wants to merge
18
commits into
trunk
Choose a base branch
from
add/kebab-case-package
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
2504200
Introduce @wordpress/kebab-case package
oandregal a389708
Migrate all private kebabCase consumers to @wordpress/kebab-case
oandregal 585714a
Rename @wordpress/kebab-case to @wordpress/string
oandregal 2fbca7b
Remove dependency group comment blocks from test files
oandregal 0ae7af1
Bundle @wordpress/string in consumer builds
oandregal 3f1592b
Restore alphabetical dependency order for @wordpress/string
oandregal 2fc4c5a
Fix CHANGELOG entries for the string package migration
oandregal f98c055
Improve string package changelog
oandregal 0215503
Scope the @wordpress/string README claims to tested behavior
oandregal abaa240
Align @wordpress/string package.json with newest bundled packages
oandregal d2f0da5
Restore alphabetical order of packages/string in root tsconfig
oandregal 1fcb2c6
Update README
oandregal 010eb94
Regenerate package-lock.json
oandregal 653179c
Remove unnecessary dependency
oandregal c5932f7
Editor: vendor normalizeTextString instead of unlocking it from compo…
oandregal 9d361e7
Components: remove normalizeTextString from the private APIs
oandregal 7f0245e
Rename @wordpress/string to @wordpress/kebab-case
oandregal b6f4177
Restore platform-specific optional dependencies in package-lock.json
oandregal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| import removeAccents from 'remove-accents'; | ||
| import { paramCase } from 'change-case'; | ||
|
|
||
| /** | ||
| * All unicode characters that we consider "dash-like": | ||
|
|
@@ -22,33 +21,6 @@ export const normalizeTextString = ( value: string ): string => { | |
| .replace( ALL_UNICODE_DASH_CHARACTERS, '-' ); | ||
| }; | ||
|
|
||
| /** | ||
| * Converts any string to kebab case. | ||
| * Backwards compatible with Lodash's `_.kebabCase()`. | ||
| * Backwards compatible with `_wp_to_kebab_case()`. | ||
| * | ||
| * @see https://lodash.com/docs/4.17.15#kebabCase | ||
| * @see https://developer.wordpress.org/reference/functions/_wp_to_kebab_case/ | ||
| * | ||
| * @param str String to convert. | ||
| * @return Kebab-cased string | ||
| */ | ||
| export function kebabCase( str: unknown ) { | ||
| let input = str?.toString?.() ?? ''; | ||
|
|
||
| // See https://github.com/lodash/lodash/blob/b185fcee26b2133bd071f4aaca14b455c2ed1008/lodash.js#L4970 | ||
| input = input.replace( /['\u2019]/, '' ); | ||
|
|
||
| return paramCase( input, { | ||
| splitRegexp: [ | ||
| /(?!(?:1ST|2ND|3RD|[4-9]TH)(?![a-z]))([a-z0-9])([A-Z])/g, // fooBar => foo-bar, 3Bar => 3-bar | ||
| /(?!(?:1st|2nd|3rd|[4-9]th)(?![a-z]))([0-9])([a-z])/g, // 3bar => 3-bar | ||
| /([A-Za-z])([0-9])/g, // Foo3 => foo-3, foo3 => foo-3 | ||
| /([A-Z])([A-Z][a-z])/g, // FOOBar => foo-bar | ||
| ], | ||
| } ); | ||
| } | ||
|
Comment on lines
-36
to
-50
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has been migrated verbatim to |
||
|
|
||
| /** | ||
| * Escapes the RegExp special characters. | ||
| * | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the other functions here in this file, are they good candidates for the string package?