From 22415f6cedab95a497cea824027c1bd53ef0319e Mon Sep 17 00:00:00 2001 From: Reece Daniels Date: Wed, 11 Mar 2020 10:54:32 +0000 Subject: [PATCH 1/3] excluding strings starting with numbers in regex --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 7002f89..1de9c3f 100644 --- a/index.js +++ b/index.js @@ -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() }) } From c03b217d152b9c1d98babcf60527eb3d82199dc4 Mon Sep 17 00:00:00 2001 From: Reece Daniels Date: Sat, 14 Mar 2020 21:38:34 +0000 Subject: [PATCH 2/3] adding a few lines to the documentation --- README.md | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 185172a..af9f4b2 100644 --- a/README.md +++ b/README.md @@ -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") }) - + }) ``` @@ -101,10 +101,19 @@ 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 - npm install capitalize +npm install capitalize ## License From 109406f4161af5eb894ea842213c4ac57e3d8de4 Mon Sep 17 00:00:00 2001 From: Stephen Sugden Date: Sun, 15 Mar 2020 09:33:38 +0100 Subject: [PATCH 3/3] Fix up readme indentation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index af9f4b2..0eccb8d 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ test('Capitalize words, handling shorthand ordinals (1st, 2nd, 3rd) correctly', ## Install -npm install capitalize + npm install capitalize ## License