Should there be a substring filter operator?

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)

I think the concern expressed at: Should there be a substring filter operator? - #16 by Yaisog should be taken into account.

We do have some other filter operators that start with 1 or 0 based “indexes” eg: nth and zth.

We should aim for consistency.
-m

I agree but keep in mind the existing operators mostly operate on a list of titles so we need to first split then after the function join[]