mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-09-19 00:00:43 +00:00
Fix sentencecase operator, add titlecase operator (#4006)
This commit is contained in:
committed by
Jeremy Ruston
parent
2e2ed7902c
commit
9b27f82a80
@@ -30,6 +30,10 @@ exports.sentencecase = makeStringBinaryOperator(
|
||||
function(a) {return [$tw.utils.toSentenceCase(a)];}
|
||||
);
|
||||
|
||||
exports.titlecase = makeStringBinaryOperator(
|
||||
function(a) {return [$tw.utils.toTitleCase(a)];}
|
||||
);
|
||||
|
||||
exports.trim = makeStringBinaryOperator(
|
||||
function(a) {return [$tw.utils.trim(a)];}
|
||||
);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user