sentence-case
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "sentence-case", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Sentence case a string", | ||
@@ -5,0 +5,0 @@ "main": "sentence-case.js", |
@@ -8,3 +8,3 @@ # Sentence Case | ||
Sentence case a string. | ||
Sentence case a string. Also handles non-string entities, such as objects with a `toString` property, numbers and booleans. Empty values (`null` and `undefined`) will come out as an empty string. | ||
@@ -22,2 +22,3 @@ ## Installation | ||
sentenceCase(null); //=> "" | ||
sentenceCase('string'); //=> "string" | ||
@@ -24,0 +25,0 @@ sentenceCase('dot.case'); //=> "dot case" |
/** | ||
* Sentence case a string. | ||
* | ||
* @param {String} string | ||
* @param {String} str | ||
* @return {String} | ||
*/ | ||
module.exports = function (string) { | ||
return String(string) | ||
module.exports = function (str) { | ||
if (str == null) { | ||
return ''; | ||
} | ||
return String(str) | ||
// Add camel case support. | ||
@@ -10,0 +14,0 @@ .replace(/([a-z])([A-Z0-9])/g, '$1 $2') |
@@ -33,6 +33,11 @@ /* global describe, it */ | ||
it('should not fail with odd input', function () { | ||
assert.equal(sentenceCase(null), 'null'); | ||
assert.equal(sentenceCase(null), ''); | ||
assert.equal(sentenceCase(undefined), ''); | ||
assert.equal(sentenceCase(10), '10'); | ||
assert.equal(sentenceCase(undefined), 'undefined'); | ||
assert.equal(sentenceCase({ toString: function () { return 'test'; } }), 'test'); | ||
}); | ||
it('should trim whitespace', function () { | ||
assert.equal(sentenceCase(' test '), 'test'); | ||
}); | ||
}); |
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
5412
57
39