capitalize
Advanced tools
Comparing version
13
index.js
@@ -1,10 +0,15 @@ | ||
module.exports = function (string) { | ||
string = string.toLowerCase(); | ||
module.exports = function (string, preserve) { | ||
if (!preserve) { | ||
string = string.toLowerCase(); | ||
} | ||
return string.charAt(0).toUpperCase() + string.substring(1); | ||
} | ||
module.exports.words = function (string) { | ||
return string.toLowerCase().replace(/(^|[^a-zA-Z\u00C0-\u017F'])([a-zA-Z\u00C0-\u017F])/g, function (m) { | ||
module.exports.words = function (string, preserve) { | ||
if (!preserve) { | ||
string = string.toLowerCase(); | ||
} | ||
return string.replace(/(^|[^a-zA-Z\u00C0-\u017F'])([a-zA-Z\u00C0-\u017F])/g, function (m) { | ||
return m.toUpperCase() | ||
}) | ||
} |
{ | ||
"name": "capitalize", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "capitalize the first letter of a string, or all words in a string", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -81,2 +81,16 @@ # capitalize | ||
and thanks to [@sergejkaravajnij](https://github.com/grncdr/js-capitalize/pull/9), capitalize also supports a second boolean parameter to preserve casing of the rest of the strings content: | ||
```javascript | ||
test('Capitalize a string, preserving the original case of other letters', function (t) { | ||
t.plan(1) | ||
t.equal(capitalize('canDoItRight', true), 'CanDoItRight') | ||
}) | ||
test('Capitalize words, preserving the case', function (t) { | ||
t.plan(1) | ||
t.equal(capitalize.words('on gitHub', true), 'On GitHub') | ||
}) | ||
``` | ||
## Install | ||
@@ -83,0 +97,0 @@ |
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
5251
26.81%5
25%14
55.56%102
15.91%0
-100%