1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 10:07:19 +00:00

Fix sentencecase operator, add titlecase operator (#4006)

This commit is contained in:
Robin Munn 2019-06-21 02:24:02 -05:00 committed by Jeremy Ruston
parent 2e2ed7902c
commit 9b27f82a80
6 changed files with 49 additions and 7 deletions

View File

@ -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)];}
);

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

View File

@ -1,8 +1,10 @@
created: 20190619110741485
modified: 20190619110812080
modified: 20190620140353983
tags: [[uppercase Operator]] [[Operator Examples]]
title: sentencecase Operator (Examples)
type: text/vnd.tiddlywiki
<<.operator-example 1 "[[abc def ghi jkl]sentencecase[]]">>
<<.operator-example 2 "[tag[HelloThere]sentencecase[]]">>
<<.operator-example 2 "[[abc deF gHi jKL]sentencecase[]]">>
<<.operator-example 3 "[[abc deF gHi jKL]lowercase[]sentencecase[]]">>
<<.operator-example 4 "[tag[HelloThere]sentencecase[]]">>

View File

@ -0,0 +1,10 @@
created: 20190620140005348
modified: 20190620140412655
tags: [[uppercase Operator]] [[Operator Examples]]
title: sentencecase Operator (Examples)
type: text/vnd.tiddlywiki
<<.operator-example 1 "[[abc def ghi jkl]titlecase[]]">>
<<.operator-example 2 "[[abc deF gHi jKL]titlecase[]]">>
<<.operator-example 3 "[[abc deF gHi jKL]lowercase[]titlecase[]]">>
<<.operator-example 4 "[tag[HelloThere]titlecase[]]">>

View File

@ -2,14 +2,16 @@ caption: sentencecase
created: 20190619110607457
modified: 20190619110736016
op-input: a [[selection of titles|Title Selection]]
op-output: the input titles with each word capitalised
op-purpose: returns each item in the list capitalised
op-output: the input titles with each first letter capitalised
op-purpose: returns each item in the list with the first letter capitalised
tags: [[Filter Operators]]
title: sentencecase Operator
type: text/vnd.tiddlywiki
<<.from-version "5.1.20">>
See also [[lowercase Operator]], [[uppercase Operator]].
See also [[lowercase Operator]], [[uppercase Operator]], [[titlecase Operator]].
<<.tip " This operator does not change anything except the first letter of each title, so `[[aBcD eFgH]]` would become `[[ABcD eFgH]]`. If you want `[[Abcd efgh]]`, then use a filter like `[lowercase[]sentencecase[]]`.">>
<<.operator-examples "sentencecase">>

View File

@ -0,0 +1,17 @@
caption: titlecase
created: 20190620135008529
modified: 20190620135008529
op-input: a [[selection of titles|Title Selection]]
op-output: the input titles with each word capitalised
op-purpose: returns each item in the list with each word capitalised
tags: [[Filter Operators]]
title: titlecase Operator
type: text/vnd.tiddlywiki
<<.from-version "5.1.20">>
See also [[lowercase Operator]], [[uppercase Operator]], [[sentencecase Operator]].
<<.tip " This operator does not change anything except the first letter of each word, so `[[aBcD eFgH]]` would become `[[ABcD EFgH]]`. If you want `[[Abcd Efgh]]`, then use a filter like `[lowercase[]titlecase[]]`.">>
<<.operator-examples "titlecase">>