From 5b23f789351d2f380d4170d1eed13a928db8e5f3 Mon Sep 17 00:00:00 2001 From: mbiggin Date: Sun, 17 May 2015 21:36:38 +0100 Subject: [PATCH] Avoid matching on single quotes --- .gitignore | 1 + README.md | 9 +++++++++ index.js | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/README.md b/README.md index c177d74..4a766d3 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,15 @@ test('Capitalize each word', function (t) { }) ``` +And ensure that quotes are handled within the string: + +```javascript +test('Capitalize each word ensuring that quotes do not confuse it', function(t) { + t.plan(1) + t.equal(capitalize.words("it's a nice day"), "It's A Nice Day") +}) +``` + ## Install npm install capitalize diff --git a/index.js b/index.js index 4206fef..301e79b 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ module.exports = function (string) { } module.exports.words = function (string) { - return string.replace(/(^|\W)(\w)/g, function (m) { + return string.replace(/(^|[^a-zA-Z0-9_'])(\w)/g, function (m) { return m.toUpperCase() }) }