bare-script 3.8.19 → 3.8.21

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.
Files changed (2) hide show
  1. package/lib/library.js +48 -0
  2. package/package.json +2 -2
package/lib/library.js CHANGED
@@ -9,8 +9,11 @@ import {
9
9
  addCalculatedField, aggregateData, filterData, joinData, parseCSV, sortData, topData, validateData
10
10
  } from './data.js';
11
11
  import {validateType, validateTypeModel} from 'schema-markdown/lib/schema.js';
12
+ import {evaluateExpression} from './runtime.js';
13
+ import {parseExpression} from './parser.js';
12
14
  import {parseSchemaMarkdown} from 'schema-markdown/lib/parser.js';
13
15
  import {typeModel} from 'schema-markdown/lib/typeModel.js';
16
+ import {validateExpression} from './model.js';
14
17
 
15
18
 
16
19
  /* eslint-disable id-length */
@@ -385,6 +388,49 @@ const arraySortArgs = valueArgsModel([
385
388
  ]);
386
389
 
387
390
 
391
+ //
392
+ // BareScript functions
393
+ //
394
+
395
+
396
+ // $function: barescriptEvaluateExpression
397
+ // $group: barescript
398
+ // $doc: Evaluate a [BareScript expression model](../model/#var.vName='Expression')
399
+ // $arg expr: The [BareScript expression model](../model/#var.vName='Expression')
400
+ // $arg locals: Optional (default is null). The local variables object.
401
+ // $arg globals: Optional (default is null). The global variables object.
402
+ // $return: The expression result
403
+ function barescriptEvaluateExpression(args, options) {
404
+ const [expr, locals_, globals] = valueArgsValidate(barescriptEvaluateExpressionArgs, args);
405
+ validateExpression(expr);
406
+ const evaluateOptions = (globals === null ? options : {...options, 'globals': globals});
407
+ return evaluateExpression(expr, evaluateOptions, locals_, false);
408
+ }
409
+
410
+ const barescriptEvaluateExpressionArgs = valueArgsModel([
411
+ {'name': 'expr', 'type': 'object'},
412
+ {'name': 'locals', 'type': 'object', 'nullable': true},
413
+ {'name': 'globals', 'type': 'object', 'nullable': true}
414
+ ]);
415
+
416
+
417
+ // $function: barescriptParseExpression
418
+ // $group: barescript
419
+ // $doc: Parse a BareScript expression
420
+ // $arg exprStr: The expression string
421
+ // $arg arrayLiterals: Optional (default is true). If true, allow array literals.
422
+ // $return: The [BareScript expression model](../model/#var.vName='Expression')
423
+ function barescriptParseExpression(args) {
424
+ const [exprStr, arrayLiterals] = valueArgsValidate(barescriptParseExpressionArgs, args);
425
+ return parseExpression(exprStr, null, null, arrayLiterals);
426
+ }
427
+
428
+ const barescriptParseExpressionArgs = valueArgsModel([
429
+ {'name': 'exprStr', 'type': 'string'},
430
+ {'name': 'arrayLiterals', 'type': 'boolean', 'default': true}
431
+ ]);
432
+
433
+
388
434
  //
389
435
  // Coverage functions
390
436
  //
@@ -2299,6 +2345,8 @@ export const scriptFunctions = {
2299
2345
  arrayShift,
2300
2346
  arraySlice,
2301
2347
  arraySort,
2348
+ barescriptEvaluateExpression,
2349
+ barescriptParseExpression,
2302
2350
  coverageGlobalGet,
2303
2351
  'coverageGlobalName': coverageGlobalNameFn,
2304
2352
  coverageStart,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "bare-script",
4
- "version": "3.8.19",
4
+ "version": "3.8.21",
5
5
  "description": "BareScript; a lightweight scripting and expression language",
6
6
  "keywords": [
7
7
  "expression",
@@ -33,7 +33,7 @@
33
33
  "devDependencies": {
34
34
  "@eslint/js": "~10.0",
35
35
  "c8": "~11.0",
36
- "eslint": "~10.0",
36
+ "eslint": "~10.1",
37
37
  "globals": "~17.4",
38
38
  "jsdoc": "~4.0"
39
39
  }