@almadar/evaluator 2.15.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 +22 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -991,23 +991,39 @@ 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;
|
|
997
1013
|
}
|
|
998
1014
|
function evalArrayFirst(args, evaluate2, ctx) {
|
|
999
1015
|
const arr = evaluate2(args[0], ctx);
|
|
1000
|
-
return arr?.[0];
|
|
1016
|
+
return arr?.[0] ?? null;
|
|
1001
1017
|
}
|
|
1002
1018
|
function evalArrayLast(args, evaluate2, ctx) {
|
|
1003
1019
|
const arr = evaluate2(args[0], ctx);
|
|
1004
|
-
if (!Array.isArray(arr) || arr.length === 0) return
|
|
1020
|
+
if (!Array.isArray(arr) || arr.length === 0) return null;
|
|
1005
1021
|
return arr[arr.length - 1];
|
|
1006
1022
|
}
|
|
1007
1023
|
function evalArrayNth(args, evaluate2, ctx) {
|
|
1008
1024
|
const arr = evaluate2(args[0], ctx);
|
|
1009
1025
|
const index = evaluate2(args[1], ctx);
|
|
1010
|
-
return arr?.[index];
|
|
1026
|
+
return arr?.[index] ?? null;
|
|
1011
1027
|
}
|
|
1012
1028
|
function evalArraySlice(args, evaluate2, ctx) {
|
|
1013
1029
|
const arr = evaluate2(args[0], ctx);
|
|
@@ -1121,7 +1137,7 @@ function evalArrayIndexOf(args, evaluate2, ctx) {
|
|
|
1121
1137
|
function evalArrayFind(args, evaluate2, ctx) {
|
|
1122
1138
|
const arr = evaluate2(args[0], ctx);
|
|
1123
1139
|
const predExpr = args[1];
|
|
1124
|
-
return (arr ?? []).find((item, i) => evalWithItem(predExpr, evaluate2, ctx, item, i));
|
|
1140
|
+
return (arr ?? []).find((item, i) => evalWithItem(predExpr, evaluate2, ctx, item, i)) ?? null;
|
|
1125
1141
|
}
|
|
1126
1142
|
function evalArrayFindIndex(args, evaluate2, ctx) {
|
|
1127
1143
|
const arr = evaluate2(args[0], ctx);
|
|
@@ -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":
|