Add sentencecase operator

Fixes #4000
This commit is contained in:
Jeremy Ruston 2019-06-19 12:11:02 +01:00
parent 6099ec576c
commit 2e2ed7902c
7 changed files with 39 additions and 5 deletions

View file

@ -92,6 +92,13 @@ exports.trim = function(str) {
}
};
/*
Convert a string to sentence case (ie capitalise each initial letter)
*/
exports.toSentenceCase = function(str) {
return (str || "").toLowerCase().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