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

Excluding strings starting with numbers in regex #13

Merged
merged 3 commits into from
Mar 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,32 @@ No matter the original case:
```javascript
test('Capitalize first letter with original string...', function (t) {
t.plan(2)

t.test('...in upper case', function (t1) {
t1.plan(1)
t1.equal(capitalize.words("UNITED STATES"), "United States")
})

t.test('...in mixed case', function (t2) {
t2.plan(1)
t2.equal(capitalize.words("uNiTeD sTaTeS"), "United States")
})

})

test('Capitalize each word with original string...', function (t) {
t.plan(2)

t.test('...in upper case', function (t1) {
t1.plan(1)
t1.equal(capitalize.words("UNITED STATES"), "United States")
})

t.test('...in mixed case', function (t2) {
t2.plan(1)
t2.equal(capitalize.words("uNiTeD sTaTeS"), "United States")
})

})
```

Expand Down Expand Up @@ -101,6 +101,15 @@ test('Capitalize words, preserving the case', function (t) {
})
```

and thanks to [@rubengmurray](https://github.com/grncdr/js-capitalize/pull/13), capitalize now handles shorthand ordinal numbers as would be expected:

```javascript
test('Capitalize words, handling shorthand ordinals (1st, 2nd, 3rd) correctly', function (t) {
t.plan(1)
t.equal(capitalize.words('1st place'), '1st Place')
})
```


## Install

Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports.words = function (string, preserve) {
if (!preserve) {
string = string.toLowerCase();
}
return string.replace(/(^|[^a-zA-Z\u00C0-\u017F\u0400-\u04FF'])([a-zA-Z\u00C0-\u017F\u0400-\u04FF])/g, function (m) {
return string.replace(/(?!^[0-9])(^|[^a-zA-Z\u00C0-\u017F\u0400-\u04FF'])([a-zA-Z\u00C0-\u017F\u0400-\u04FF])/g, function (m) {
return m.toUpperCase()
})
}