-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Lodash: Refactor pascal case usages away from Lodash #42466
Conversation
Size Change: +784 B (0%) Total Size: 1.27 MB
ℹ️ View Unchanged
|
99f5352
to
7a64b73
Compare
7a64b73
to
2085236
Compare
This could still use a review - does anyone have a chance to take a look? |
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.
The code LGTM 👍 There might be some differences between the way both libraries handle some strings, but they should be easy enough to handle if they pop up. The tests look good, though!
What?
This PR removes a few
_.upperFirst( _.camelCase() )
usages in favor ofchange-case
'spascalCase()
. This leaves a few more usages of both functions that we'll be addressing in a separate PR.Why?
Lodash is known to unnecessarily inflate the bundle size of packages, and in most cases, it can be replaced with native language functionality. See these for more information and rationale:
@wordpress/api-fetch
package haslodash
as a dependency #39495How?
Similar to #42427, we're suggesting to use the
change-case
library, which offers modular functions for all the casing functions we use from Lodash (likesnakeCase
,capitalize
,startCase
,camelCase
,kebabCase
), at a small price (the methods are small themselves), and has TS support. The benefit of using that external library for all those case conversion functions is that we won't have to maintain our own versions of them, and those are already broadly used and tested.In particular, we replace a few of
_.upperFirst( _.camelCase() )
Lodash usages in favor of thechange-case
one (pascalCase
). We also replace a stray_.startCase()
with its correspondingcapitalCase()
.Testing Instructions
npm run docs:gen
runs and completes without problems.npx @wordpress/create-block test-block
still works well.