As a a script kiddy, I used chatgpt to generate the following, it seem not to be working however certainly looks close to what we need perhaps someone can complete it?
$:/PSaT/modules/filters/slice.js
/*\
title: $:/core/modules/filters/slice.js
type: application/javascript
module-type: filteroperator
Filter operator for slicing a single title into pieces using integer parameters
Implementing the JavaScript SLICE function in inclusive/inclusive mode
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
// Adds the custom slice filter operator
exports.name = "slice";
exports.operator = function(operator,operand,context) {
var fromIndex = parseInt(operator.operand[0] || "0", 10);
var toIndex = parseInt(operator.operand[1] || operand.length.toString(), 10);
// Ensure inclusive slicing by adjusting the toIndex
toIndex = Math.min(operand.length, toIndex + 1);
// Slice the operand
return operand.slice(fromIndex, toIndex);
};
})();
Attached for your convenience.
modules_filters_slice.js.json (1.1 KB)