mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-30 13:29:56 +00:00
Add suffix and removesuffix filters
This commit is contained in:
parent
798ed46469
commit
dcf4e93a32
28
core/modules/filters/removesuffix.js
Normal file
28
core/modules/filters/removesuffix.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/*\
|
||||||
|
title: $:/core/modules/filters/removesuffix.js
|
||||||
|
type: application/javascript
|
||||||
|
module-type: filteroperator
|
||||||
|
|
||||||
|
Filter operator for removing a suffix from each title in the list. Titles that do not end with the suffix are removed.
|
||||||
|
|
||||||
|
\*/
|
||||||
|
(function(){
|
||||||
|
|
||||||
|
/*jslint node: true, browser: true */
|
||||||
|
/*global $tw: false */
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
/*
|
||||||
|
Export our filter function
|
||||||
|
*/
|
||||||
|
exports.removesuffix = function(source,operator,options) {
|
||||||
|
var results = [];
|
||||||
|
source(function(tiddler,title) {
|
||||||
|
if(title.substr(-operator.operand.length).toLowerCase() === operator.operand.toLowerCase()) {
|
||||||
|
results.push(title.substr(operator.operand.length));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return results;
|
||||||
|
};
|
||||||
|
|
||||||
|
})();
|
36
core/modules/filters/suffix.js
Normal file
36
core/modules/filters/suffix.js
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/*\
|
||||||
|
title: $:/core/modules/filters/suffix.js
|
||||||
|
type: application/javascript
|
||||||
|
module-type: filteroperator
|
||||||
|
|
||||||
|
Filter operator for checking if a title ends with a suffix
|
||||||
|
|
||||||
|
\*/
|
||||||
|
(function(){
|
||||||
|
|
||||||
|
/*jslint node: true, browser: true */
|
||||||
|
/*global $tw: false */
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
/*
|
||||||
|
Export our filter function
|
||||||
|
*/
|
||||||
|
exports.suffix = function(source,operator,options) {
|
||||||
|
var results = [];
|
||||||
|
if(operator.prefix === "!") {
|
||||||
|
source(function(tiddler,title) {
|
||||||
|
if(title.substr(-operator.operand.length).toLowerCase() !== operator.operand.toLowerCase()) {
|
||||||
|
results.push(title);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
source(function(tiddler,title) {
|
||||||
|
if(title.substr(-operator.operand.length).toLowerCase() === operator.operand.toLowerCase()) {
|
||||||
|
results.push(title);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
};
|
||||||
|
|
||||||
|
})();
|
@ -12,4 +12,4 @@ For example:
|
|||||||
|`[tag[task]!prefix[hidden]]` |Returns tiddlers tagged `task` whose titles do not start with `hidden` |
|
|`[tag[task]!prefix[hidden]]` |Returns tiddlers tagged `task` whose titles do not start with `hidden` |
|
||||||
|`[prefix[$:/]]` |Equivalent to `[is[system]]` |
|
|`[prefix[$:/]]` |Equivalent to `[is[system]]` |
|
||||||
|
|
||||||
See also [[FilterOperator: removeprefix]].
|
See also [[FilterOperator: removeprefix]], [[FilterOperator: removesuffix]] and [[FilterOperator: removesuffix]].
|
||||||
|
@ -11,4 +11,4 @@ For example:
|
|||||||
|!Filter String |!Description |
|
|!Filter String |!Description |
|
||||||
|`tid-one tid-two three +[removeprefix[tid-]]` |Returns `one`, `two` |
|
|`tid-one tid-two three +[removeprefix[tid-]]` |Returns `one`, `two` |
|
||||||
|
|
||||||
See also [[FilterOperator: prefix]].
|
See also [[FilterOperator: prefix]], [[FilterOperator: suffix]] and [[FilterOperator: removesuffix]].
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
created: 20140828133830424
|
||||||
|
modified: 20140828133830424
|
||||||
|
tags: filters
|
||||||
|
title: FilterOperator: removesuffix
|
||||||
|
type: text/vnd.tiddlywiki
|
||||||
|
|
||||||
|
The ''removesuffix'' filter operator returns the titles in the current list that end with a specified suffix with the suffix removed.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
|!Filter String |!Description |
|
||||||
|
|`tid-one tid-two three +[removeprefix[tid-]]` |Returns `one`, `two` |
|
||||||
|
|
||||||
|
See also [[FilterOperator: suffix]], [[FilterOperator: prefix]] and [[FilterOperator: removeprefix]].
|
15
editions/tw5.com/tiddlers/filters/FilterOperator suffix.tid
Normal file
15
editions/tw5.com/tiddlers/filters/FilterOperator suffix.tid
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
created: 20140828133830424
|
||||||
|
modified: 20140828133830424
|
||||||
|
tags: filters
|
||||||
|
title: FilterOperator: suffix
|
||||||
|
type: text/vnd.tiddlywiki
|
||||||
|
|
||||||
|
The ''suffix'' filter operator returns the titles in the current list that end with a specified suffix. If the ''suffix'' operator is preceded by `!` then it returns the titles that do not end with the specified suffix.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
|!Filter String |!Description |
|
||||||
|
|`[tag[task]!suffix[hidden]]` |Returns tiddlers tagged `task` whose titles do not end with `hidden` |
|
||||||
|
|`[suffix[.jpg]]` |Returns tiddlers whose titles end with `.jpg` |
|
||||||
|
|
||||||
|
See also [[FilterOperator: removesuffix]], [[FilterOperator: prefix]] and [[FilterOperator: removeprefix]].
|
Loading…
Reference in New Issue
Block a user