bare-script 2.2.6 → 2.2.8

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/lib/library.js CHANGED
@@ -135,6 +135,13 @@ export const scriptFunctions = {
135
135
  return value;
136
136
  },
137
137
 
138
+ // $function: arrayShift
139
+ // $group: Array
140
+ // $doc: Remove the first element of the array and return it
141
+ // $arg array: The array
142
+ // $return: The first element of the array; null if the array is empty.
143
+ 'arrayShift': ([array]) => (Array.isArray(array) ? array.shift() ?? null : null),
144
+
138
145
  // $function: arraySlice
139
146
  // $group: Array
140
147
  // $doc: Copy a portion of an array
package/lib/runtime.js CHANGED
@@ -138,7 +138,11 @@ export function executeScriptHelper(statements, options, locals) {
138
138
  const ixArgLast = (statement.function.lastArgArray ?? null) && (funcArgsLength - 1);
139
139
  for (let ixArg = 0; ixArg < funcArgsLength; ixArg++) {
140
140
  const argName = statement.function.args[ixArg];
141
- funcLocals[argName] = (ixArg < argsLength ? (ixArg === ixArgLast ? args.slice(ixArg) : args[ixArg]) : null);
141
+ if (ixArg < argsLength) {
142
+ funcLocals[argName] = (ixArg === ixArgLast ? args.slice(ixArg) : args[ixArg]);
143
+ } else {
144
+ funcLocals[argName] = (ixArg === ixArgLast ? [] : null);
145
+ }
142
146
  }
143
147
  }
144
148
  return executeScriptHelper(statement.function.statements, fnOptions, funcLocals);
@@ -108,7 +108,11 @@ async function executeScriptHelperAsync(statements, options, locals) {
108
108
  const ixArgLast = (statement.function.lastArgArray ?? null) && (funcArgsLength - 1);
109
109
  for (let ixArg = 0; ixArg < funcArgsLength; ixArg++) {
110
110
  const argName = statement.function.args[ixArg];
111
- funcLocals[argName] = (ixArg < argsLength ? (ixArg === ixArgLast ? args.slice(ixArg) : args[ixArg]) : null);
111
+ if (ixArg < argsLength) {
112
+ funcLocals[argName] = (ixArg === ixArgLast ? args.slice(ixArg) : args[ixArg]);
113
+ } else {
114
+ funcLocals[argName] = (ixArg === ixArgLast ? [] : null);
115
+ }
112
116
  }
113
117
  }
114
118
  return executeScriptHelperAsync(statement.function.statements, fnOptions, funcLocals);
@@ -122,7 +126,11 @@ async function executeScriptHelperAsync(statements, options, locals) {
122
126
  const ixArgLast = (statement.function.lastArgArray ?? null) && (funcArgsLength - 1);
123
127
  for (let ixArg = 0; ixArg < funcArgsLength; ixArg++) {
124
128
  const argName = statement.function.args[ixArg];
125
- funcLocals[argName] = (ixArg < argsLength ? (ixArg === ixArgLast ? args.slice(ixArg) : args[ixArg]) : null);
129
+ if (ixArg < argsLength) {
130
+ funcLocals[argName] = (ixArg === ixArgLast ? args.slice(ixArg) : args[ixArg]);
131
+ } else {
132
+ funcLocals[argName] = (ixArg === ixArgLast ? [] : null);
133
+ }
126
134
  }
127
135
  }
128
136
  return executeScriptHelper(statement.function.statements, fnOptions, funcLocals);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "bare-script",
4
- "version": "2.2.6",
4
+ "version": "2.2.8",
5
5
  "description": "BareScript; a lightweight scripting and expression language",
6
6
  "keywords": [
7
7
  "expression",