-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
Fix capitalizing words that start with numbers #346
Fix capitalizing words that start with numbers #346
Conversation
Fix issue where words like "1st" and "2nd" were capitalized as "1St" and "2Nd"
packages/title-case/src/index.ts
Outdated
@@ -4,6 +4,7 @@ const IS_MANUAL_CASE = /\p{Ll}(?=[\p{Lu}])/u; // iPhone, iOS, etc. | |||
const ALPHANUMERIC_PATTERN = /\p{Alphabetic}+/gu; | |||
const IS_ACRONYM = | |||
/^(\P{Alphabetic})*(?:\p{Alphabetic}\.){2,}(\P{Alphabetic})*$/u; | |||
const IS_DIGIT = /\d/u; |
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.
Can you change alphanumeric pattern instead? I think the bug is that it should consider numbers words too.
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.
Sure!
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.
@blakeembrey I've update the pattern and removed the check for a numeric digit I had added previously.
Thanks for taking the time to review this PR.
@@ -1,7 +1,7 @@ | |||
const TOKENS = /(\S+)|(.)/g; | |||
const IS_SPECIAL_CASE = /[\.#]\p{Alphabetic}/u; // #tag, example.com, etc. | |||
const IS_MANUAL_CASE = /\p{Ll}(?=[\p{Lu}])/u; // iPhone, iOS, etc. | |||
const ALPHANUMERIC_PATTERN = /\p{Alphabetic}+/gu; | |||
const ALPHANUMERIC_PATTERN = /[\p{Alphabetic}\p{Nd}]+/gu; |
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.
Any concerns with just doing \p{N}
?
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.
No concerns with changing to \p{N}
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.
Release yesterday, cheers! https://github.com/blakeembrey/change-case/releases/tag/title-case%404.3.2
Thanks for the catch, embarrassed I didn't have a test for this 😅 |
This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [title-case](https://github.com/blakeembrey/change-case/tree/master/packages/title-case#readme) ([source](https://github.com/blakeembrey/change-case)) | [`4.3.1` -> `4.3.2`](https://renovatebot.com/diffs/npm/title-case/4.3.1/4.3.2) | [![age](https://developer.mend.io/api/mc/badges/age/npm/title-case/4.3.2?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/title-case/4.3.2?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/title-case/4.3.1/4.3.2?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/title-case/4.3.1/4.3.2?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>blakeembrey/change-case (title-case)</summary> ### [`v4.3.2`](https://github.com/blakeembrey/change-case/releases/tag/title-case%404.3.2) [Compare Source](https://github.com/blakeembrey/change-case/compare/[email protected]) **Fixed** - Fix capitalization of words that start with a number [https://github.com/blakeembrey/change-case/pull/346](https://github.com/blakeembrey/change-case/pull/346) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/JoshuaKGoldberg/emoji-platform-data). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC44MC4wIiwidXBkYXRlZEluVmVyIjoiMzguODAuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiZGVwZW5kZW5jaWVzIl19--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Fix issue where words that start with numbers have the first non-numeric character capitalized incorrectly. Previously "1st" was being capitalized as "1St".