@almadar/evaluator 2.16.0 → 2.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -991,6 +991,22 @@ function evalArrayLen(args, evaluate2, ctx) {
991
991
  const arr = evaluate2(args[0], ctx);
992
992
  return arr?.length ?? 0;
993
993
  }
994
+ function evalArrayRange(args, evaluate2, ctx) {
995
+ const first = Number(evaluate2(args[0], ctx));
996
+ const start = args.length === 1 ? 0 : first;
997
+ const end = args.length === 1 ? first : Number(evaluate2(args[1], ctx));
998
+ const step = args.length > 2 ? Number(evaluate2(args[2], ctx)) : 1;
999
+ const out = [];
1000
+ if (!Number.isFinite(start) || !Number.isFinite(end) || !Number.isFinite(step) || step === 0) {
1001
+ return out;
1002
+ }
1003
+ if (step > 0) {
1004
+ for (let current = start; current < end; current += step) out.push(current);
1005
+ } else {
1006
+ for (let current = start; current > end; current += step) out.push(current);
1007
+ }
1008
+ return out;
1009
+ }
994
1010
  function evalArrayEmpty(args, evaluate2, ctx) {
995
1011
  const arr = evaluate2(args[0], ctx);
996
1012
  return !arr || arr.length === 0;
@@ -4013,6 +4029,8 @@ var SExpressionEvaluator = class {
4013
4029
  // ===============================
4014
4030
  case "array/len":
4015
4031
  return evalArrayLen(args, evaluate2, ctx);
4032
+ case "array/range":
4033
+ return evalArrayRange(args, evaluate2, ctx);
4016
4034
  case "array/empty?":
4017
4035
  return evalArrayEmpty(args, evaluate2, ctx);
4018
4036
  case "array/first":