Skip to content
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

Bugfix/snake camel dash #114

Merged
merged 11 commits into from
Oct 20, 2022

Conversation

MarlonPassos-git
Copy link
Contributor

Description

Please provide a detailed description of the changes and the intent behind them :)

Checklist

  • Changes are covered by tests if behavior has been changed or added
  • Tests have 100% coverage
  • The version in package.json has been bumped according to the changes made and standard semantic versioning rules

Resolves

#96

I saw an interesting thread about things that are not 100% compared to lodash. I made this pr to fix these "bug"

*/
export const camel = (str: string): string => {
const parts = str?.split(/[\.\-\s_]/).map(x => x.toLowerCase()) ?? []
const parts = str
?.replace(/([A-Z])+/g, capitalize)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not know you could use a function as the replacement argument 🤯 ❤️

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that's pretty cool, in my service we use it this way with maps, filters, etc... It makes the code more readable

Copy link
Owner

@sodiray sodiray left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @MarlonPassos-git so much for this PR, I like the simple fix and how consistent it is with the existing code. I also ❤️ the added tests!

@sodiray sodiray merged commit 383a515 into sodiray:master Oct 20, 2022
@sodiray
Copy link
Owner

sodiray commented Oct 20, 2022

This PR has been published 🚀 to npm in version 8.0.3

@MarlonPassos-git MarlonPassos-git deleted the bugfix/snake-camel-dash branch October 20, 2022 23:44
@wouter-leistra
Copy link

Thanks @MarlonPassos-git so much for this PR, I like the simple fix and how consistent it is with the existing code. I also ❤️ the added tests!

Thanks so much for the fix!

Just want to point out that the usage of toLowercase may not function as expected when some other locale is used as input. I believe one should prefer the usage of to LocaleLowerCase to get 100% accuracy, but as the two functions mostly produce the same results I'm not sure if you feel it is worth the change and possibly additional optional parameter.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleLowerCase

@sodiray
Copy link
Owner

sodiray commented Oct 25, 2022

@wouter-leistra thanks for pointing this out, I've never had a need to work with i8 before so I've never used locale.

I'm down to add it or would accept a pr.

aleclarson referenced this pull request in radashi-org/radashi Jun 24, 2024
* test(string - snake function): has camelCase and dash

* feat(snake): now works with camal case

* docs(snake): add jsdoc with word with camalCase

* test(dast): handle with camel case and dash

* feat(dash): now works with camal case

* docs(dash): add jsdoc with word with camalCase

* test(camel): a word in camel case should remain in camel case

* feat(camel): now works with camal case

* test(camel): a word in camel case should remain in camel case

* release v8.0.1

Co-authored-by: marlon Felipe Passos <[email protected]>
Co-authored-by: Ray Epps <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants