string-title-case
Advanced tools
Comparing version 2.0.0 to 3.0.0
19
index.js
/** | ||
* Valid word starting characters | ||
* @type {[string,string,string,string]} | ||
*/ | ||
const CONTAINERS = ['(', '[', '{']; | ||
/** | ||
* Title Case a String whilst Excluding Certain Words | ||
@@ -12,3 +18,3 @@ * @param {string} title String to be "title cased" | ||
.split(' ') | ||
.map(function filterWords(word) { | ||
.map((word) => { | ||
if (exclusions.includes(word)) | ||
@@ -28,7 +34,12 @@ return word; | ||
const capitaliseFirstChar = (word) => { | ||
return word.split('').map(function(w,i) { | ||
return i == 0 ? w.toUpperCase() : w; | ||
}).join(''); | ||
return word | ||
.split('') | ||
.map((letter, index, array) => { | ||
return index === 0 || CONTAINERS.includes(array[index - 1]) ? letter.toUpperCase() : letter; | ||
}) | ||
.join(''); | ||
}; | ||
module.exports = titleCase; |
{ | ||
"name": "string-title-case", | ||
"version": "2.0.0", | ||
"version": "3.0.0", | ||
"description": "Capitalises first character of each word in string except words from an exclusion array.", | ||
@@ -24,3 +24,4 @@ "main": "index.js", | ||
}, | ||
"homepage": "https://github.com/bradleyflood/string-title-case#readme" | ||
"homepage": "https://github.com/bradleyflood/string-title-case#readme", | ||
"dependencies": {} | ||
} |
@@ -6,3 +6,3 @@ const titleCase = require('./index.js'); | ||
if (titleCase("g'day mate ") !== "G'day Mate") | ||
if (titleCase("g'day (mate) ") !== "G'day (Mate)") | ||
process.exit(1); | ||
@@ -9,0 +9,0 @@ |
Sorry, the diff of this file is not supported yet
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
46
16911