Add new 'minlength' operator

Fixes #1493
This commit is contained in:
Jermolene 2016-10-11 09:26:20 +01:00
parent f1090d749e
commit ffcbcbfa82
3 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,29 @@
/*\
title: $:/core/modules/filters/minlength.js
type: application/javascript
module-type: filteroperator
Filter operator for filtering out titles that don't meet the minimum length in the operand
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Export our filter function
*/
exports.minlength = function(source,operator,options) {
var results = [],
minLength = parseInt(operator.operand || "",10) || 0;
source(function(tiddler,title) {
if(title.length >= minLength) {
results.push(title);
}
});
return results;
};
})();

View File

@ -0,0 +1,11 @@
created: 20161011074235805
modified: 20161011074235805
tags: [[Operator Examples]] [[minlength Operator]]
title: minlength Operator (Examples)
type: text/vnd.tiddlywiki
<<.using-days-of-week>>
<<.operator-example 1 "[list[Days of the Week]minlength[7]]">>
<<.operator-example 2 "[list[Days of the Week]minlength[1]]">>

View File

@ -0,0 +1,14 @@
caption: minlength
created: 20161011074235805
modified: 20161011074235805
op-input: a list of items
op-output: those items at least as long as the specified minimum length
op-parameter: the minimum length for items
op-parameter-name: minlength
op-purpose: filter items shorter than the specified minimum length
from-version: 5.1.14
tags: [[Filter Operators]]
title: minlength Operator
type: text/vnd.tiddlywiki
<<.operator-examples "minlength">>