1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 03:57:21 +00:00

Sortan filter for alpha-numeric filter (#3134)

* Sortan filter for alpha-numeric filter

* Removing Case sensitive option, Removing default value for isAlphanumeric parameter, updating formatting

* Formatting changes

* Formatting changes
This commit is contained in:
Rizwan 2018-03-05 16:39:25 +05:30 committed by Jeremy Ruston
parent cc39a86430
commit 2b0204422d
5 changed files with 43 additions and 1 deletions

View File

@ -27,6 +27,12 @@ exports.nsort = function(source,operator,options) {
return results;
};
exports.sortan = function(source, operator, options) {
var results = prepare_results(source);
options.wiki.sortTiddlers(results, operator.operand || "title", operator.prefix === "!",false,false,true);
return results;
};
exports.sortcs = function(source,operator,options) {
var results = prepare_results(source);
options.wiki.sortTiddlers(results,operator.operand || "title",operator.prefix === "!",true,false);

View File

@ -329,7 +329,7 @@ Sort an array of tiddler titles by a specified field
isDescending: true if the sort should be descending
isCaseSensitive: true if the sort should consider upper and lower case letters to be different
*/
exports.sortTiddlers = function(titles,sortField,isDescending,isCaseSensitive,isNumeric) {
exports.sortTiddlers = function(titles,sortField,isDescending,isCaseSensitive,isNumeric,isAlphaNumeric) {
var self = this;
titles.sort(function(a,b) {
var x,y,
@ -358,6 +358,8 @@ exports.sortTiddlers = function(titles,sortField,isDescending,isCaseSensitive,is
y = Number(b);
if(isNumeric && (!isNaN(x) || !isNaN(y))) {
return compareNumbers(x,y);
} else if(isAlphaNumeric) {
return isDescending ? b.localeCompare(a,undefined,{numeric: true,sensitivity:'base'}) : a.localeCompare(b,undefined,{numeric: true,sensitivity: 'base'});
} else if($tw.utils.isDate(a) && $tw.utils.isDate(b)) {
return isDescending ? b - a : a - b;
} else {

View File

@ -0,0 +1,6 @@
created: 20180222072026299
list: [[Apple 6]] [[Apple 7]] [[Apple 8]] [[Apple 9]] [[Apple 10]] [[Apple 20]] [[Apple 30]] [[Apple 100]]
modified: 20180222072215582
tags:
title: Apple

View File

@ -0,0 +1,12 @@
created: 20180222071947788
modified: 20180222072601161
tags: [[sortan Operator]] [[Operator Examples]]
title: sortan Operator (Examples)
type: text/vnd.tiddlywiki
These examples make use of the [[Apple]] tiddler.
<<.operator-example 1 "[list[Apple]sortan[]]">>
<<.operator-example 2 "[list[Apple]!sortan[]]">>
<<.operator-example 3 "App-10-A App-9-B App-10-B App-9-A +[sortan[]]">>

View File

@ -0,0 +1,16 @@
caption: sortan
created: 20180222071605739
modified: 20180223012553446
op-input: a [[selection of titles|Title Selection]]
op-neg-output: the input, likewise sorted into descending order
op-output: the input, sorted into ascending order by field <<.field F>>, treating field values as alphanumerics
op-parameter: the name of a [[field|TiddlerFields]], defaulting to <<.field title>>
op-parameter-name: F
op-purpose: sort the input by text field considering them as alphanumerics
tags: [[Filter Operators]] [[Common Operators]] [[Field Operators]] [[Order Operators]] [[Negatable Operators]]
title: sortan Operator
type: text/vnd.tiddlywiki
The difference between uppercase and lowercase letters is ignored.
<<.operator-examples "sortan">>