Fix sentencecase operator, add titlecase operator (#4006)

This commit is contained in:
Robin Munn
2019-06-21 08:24:02 +01:00
committed by Jeremy Ruston
parent 2e2ed7902c
commit 9b27f82a80
6 changed files with 49 additions and 7 deletions
+9 -2
View File
@@ -93,12 +93,19 @@ exports.trim = function(str) {
};
/*
Convert a string to sentence case (ie capitalise each initial letter)
Convert a string to sentence case (ie capitalise first letter)
*/
exports.toSentenceCase = function(str) {
return (str || "").toLowerCase().replace(/(^|\s)\S/g, function(c) {return c.toUpperCase();});
return (str || "").replace(/^\S/, function(c) {return c.toUpperCase();});
}
/*
Convert a string to title case (ie capitalise each initial letter)
*/
exports.toTitleCase = function(str) {
return (str || "").replace(/(^|\s)\S/g, function(c) {return c.toUpperCase();});
}
/*
Find the line break preceding a given position in a string
Returns position immediately after that line break, or the start of the string