capitalize
Advanced tools
Comparing version 2.0.0 to 2.0.1
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 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
5
14
102
0