feat(string): add snakeCase, startCase, lowerCase, kebabCase in compat layer#517
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #517 +/- ##
=======================================
Coverage 99.59% 99.59%
=======================================
Files 195 199 +4
Lines 1484 1492 +8
Branches 389 388 -1
=======================================
+ Hits 1478 1486 +8
Misses 5 5
Partials 1 1 |
| export function normalizeForCase(str: string | object): string { | ||
| if (typeof str === 'object') { | ||
| str = str.toString(); | ||
| str = String(str); |
There was a problem hiding this comment.
Does this improve performance?
There was a problem hiding this comment.
in my computer it becomes slower
There was a problem hiding this comment.
Does this improve performance?
I changed this code for the case that str is null or undefined. Before codes throws error in this case.
But we already guided that shouldn't use with null and undefiend by typescript and I also found this changes makes 1.75x slower.
So I reverted! Thanks
There was a problem hiding this comment.
But Lodash don't throw error in that case. So I think String(str) is better way, because this function is for compatibility.
There was a problem hiding this comment.
Have you tried template strings? Is it faster?
There was a problem hiding this comment.
Template literals also use complex and safe toString. So I think that above result makes sense.
There was a problem hiding this comment.
Why not we just add a null and undefined check at the top?
There was a problem hiding this comment.
Yes we can do that, but I will compare with Lodash source codes for more compatible!
There was a problem hiding this comment.
I think that we have to implement estoolkit/compat/toString before merging this. So i'm going to implement it at first!
Description
I added these functions in compat layer
Benchmarks
snakeCasestartCaselowerCasekebabCaseclose #508
Additional
I found a bug in
startCasethat is also in lodash.(you can see a related comment in here.I think that we have to fix this bug in
es-toolkit