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

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

@ -26,6 +26,10 @@ exports.lowercase = makeStringBinaryOperator(
function(a) {return [("" + a).toLowerCase()];}
);
exports.sentencecase = makeStringBinaryOperator(
function(a) {return [$tw.utils.toSentenceCase(a)];}
);
exports.trim = makeStringBinaryOperator(
function(a) {return [$tw.utils.trim(a)];}
);

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

View File

@ -11,7 +11,7 @@ type: text/vnd.tiddlywiki
Added several new [[Mathematics Operators]] for working with numbers: [[negate|negate Operator]], [[abs|abs Operator]], [[ceil|ceil Operator]], [[floor|floor Operator]], [[round|round Operator]], [[trunc|trunc Operator]], [[untrunc|untrunc Operator]], [[sign|sign Operator]], [[add|add Operator]], [[subtract|subtract Operator]], [[multiply|multiply Operator]], [[divide|divide Operator]], [[remainder|remainder Operator]], [[max|max Operator]], [[min|min Operator]], [[fixed|fixed Operator]], [[precision|precision Operator]], [[exponential|exponential Operator]], [[sum|sum Operator]], [[product|product Operator]], [[maxall|maxall Operator]] and [[minall|minall Operator]].
Added several new string operators: [[length|length Operator]], [[uppercase|uppercase Operator]], [[lowercase|lowercase Operator]], [[trim|trim Operator]], [[split|split Operator]], [[splitregexp|splitregexp Operator]] and [[join|join Operator]].
Added several new string operators: [[length|length Operator]], [[uppercase|uppercase Operator]], [[lowercase|lowercase Operator]], [[sentencecase|sentencecase Operator]], [[trim|trim Operator]], [[split|split Operator]], [[splitregexp|splitregexp Operator]] and [[join|join Operator]].
There is now finer control over TiddlyWiki's default behaviour of removing duplicates from filter results, making it much easier to work with the new mathematics and string operators:

View File

@ -0,0 +1,8 @@
created: 20190619110741485
modified: 20190619110812080
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[]]">>

View File

@ -1,6 +1,6 @@
caption: lowercase
created: 20190613153650010
modified: 20190613153726427
modified: 20190619110848522
op-input: a [[selection of titles|Title Selection]]
op-output: the input titles with each uppercase letter replaced by the equivalent lowercase letter
op-purpose: returns each item in the list as lowercase
@ -10,6 +10,6 @@ type: text/vnd.tiddlywiki
<<.from-version "5.1.20">>
See also [[uppercase Operator]].
See also [[uppercase Operator]] and [[sentencecase Operator]].
<<.operator-examples "lowercase">>

View File

@ -0,0 +1,15 @@
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
tags: [[Filter Operators]]
title: sentencecase Operator
type: text/vnd.tiddlywiki
<<.from-version "5.1.20">>
See also [[lowercase Operator]], [[uppercase Operator]].
<<.operator-examples "sentencecase">>

View File

@ -1,6 +1,6 @@
caption: uppercase
created: 20190613153420821
modified: 20190613153538557
modified: 20190619110837473
op-input: a [[selection of titles|Title Selection]]
op-output: the input titles with each lowercase letter replaced by the equivalent uppercase letter
op-purpose: returns each item in the list as uppercase
@ -10,6 +10,6 @@ type: text/vnd.tiddlywiki
<<.from-version "5.1.20">>
See also [[lowercase Operator]].
See also [[lowercase Operator]] and [[sentencecase Operator]].
<<.operator-examples "uppercase">>