bare-script 3.8.19 → 3.8.20
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 +47 -0
- package/package.json +1 -1
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,48 @@ 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 builtins: Optional (default is true). If true, include the [built-in expression functions](expression.html).
|
|
402
|
+
// $return: The expression result
|
|
403
|
+
function barescriptEvaluateExpression(args, options) {
|
|
404
|
+
const [expr, locals_, builtins] = valueArgsValidate(barescriptEvaluateExpressionArgs, args);
|
|
405
|
+
validateExpression(expr);
|
|
406
|
+
return evaluateExpression(expr, options, locals_, builtins);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
const barescriptEvaluateExpressionArgs = valueArgsModel([
|
|
410
|
+
{'name': 'expr', 'type': 'object'},
|
|
411
|
+
{'name': 'locals', 'type': 'object', 'nullable': true},
|
|
412
|
+
{'name': 'builtins', 'type': 'boolean', 'default': true}
|
|
413
|
+
]);
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
// $function: barescriptParseExpression
|
|
417
|
+
// $group: barescript
|
|
418
|
+
// $doc: Parse a BareScript expression
|
|
419
|
+
// $arg exprStr: The expression string
|
|
420
|
+
// $arg arrayLiterals: Optional (default is true). If true, allow array literals.
|
|
421
|
+
// $return: The [BareScript expression model](../model/#var.vName='Expression')
|
|
422
|
+
function barescriptParseExpression(args) {
|
|
423
|
+
const [exprStr, arrayLiterals] = valueArgsValidate(barescriptParseExpressionArgs, args);
|
|
424
|
+
return parseExpression(exprStr, null, null, arrayLiterals);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
const barescriptParseExpressionArgs = valueArgsModel([
|
|
428
|
+
{'name': 'exprStr', 'type': 'string'},
|
|
429
|
+
{'name': 'arrayLiterals', 'type': 'boolean', 'default': true}
|
|
430
|
+
]);
|
|
431
|
+
|
|
432
|
+
|
|
388
433
|
//
|
|
389
434
|
// Coverage functions
|
|
390
435
|
//
|
|
@@ -2299,6 +2344,8 @@ export const scriptFunctions = {
|
|
|
2299
2344
|
arrayShift,
|
|
2300
2345
|
arraySlice,
|
|
2301
2346
|
arraySort,
|
|
2347
|
+
barescriptEvaluateExpression,
|
|
2348
|
+
barescriptParseExpression,
|
|
2302
2349
|
coverageGlobalGet,
|
|
2303
2350
|
'coverageGlobalName': coverageGlobalNameFn,
|
|
2304
2351
|
coverageStart,
|