bare-script 2.2.14 → 2.2.16

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/data.js CHANGED
@@ -376,6 +376,9 @@ enum AggregationFunction
376
376
  # The least of the measure's values
377
377
  min
378
378
 
379
+ # The standard deviation of the measure's values
380
+ stddev
381
+
379
382
  # The sum of the measure's values
380
383
  sum
381
384
  `);
@@ -434,7 +437,9 @@ export function aggregateData(data, aggregation) {
434
437
  if (!(field in aggregateRow)) {
435
438
  aggregateRow[field] = [];
436
439
  }
437
- aggregateRow[field].push(value);
440
+ if (value !== null) {
441
+ aggregateRow[field].push(value);
442
+ }
438
443
  }
439
444
  }
440
445
 
@@ -445,7 +450,9 @@ export function aggregateData(data, aggregation) {
445
450
  const field = measure.name ?? measure.field;
446
451
  const func = measure.function;
447
452
  const measureValues = aggregateRow[field];
448
- if (func === 'count') {
453
+ if (!measureValues.length) {
454
+ aggregateRow[field] = null;
455
+ } else if (func === 'count') {
449
456
  aggregateRow[field] = measureValues.length;
450
457
  } else if (func === 'max') {
451
458
  aggregateRow[field] = measureValues.reduce((max, val) => (val > max ? val : max));
@@ -453,7 +460,11 @@ export function aggregateData(data, aggregation) {
453
460
  aggregateRow[field] = measureValues.reduce((min, val) => (val < min ? val : min));
454
461
  } else if (func === 'sum') {
455
462
  aggregateRow[field] = measureValues.reduce((sum, val) => sum + val, 0);
463
+ } else if (func === 'stddev') {
464
+ const average = measureValues.reduce((sum, val) => sum + val, 0) / measureValues.length;
465
+ aggregateRow[field] = Math.sqrt(measureValues.reduce((sum, val) => sum + (val - average) ** 2, 0) / measureValues.length);
456
466
  } else {
467
+ // func === 'average'
457
468
  aggregateRow[field] = measureValues.reduce((sum, val) => sum + val, 0) / measureValues.length;
458
469
  }
459
470
  }
package/lib/library.js CHANGED
@@ -995,6 +995,28 @@ export const scriptFunctions = {
995
995
  // $return: The new function called with "args"
996
996
  'systemPartial': ([func, ...args]) => (argsExtra, options) => func([...args, ...argsExtra], options),
997
997
 
998
+ // $function: systemType
999
+ // $group: System
1000
+ // $doc: Get a value's type string
1001
+ // $arg value: The value
1002
+ // $return: The type string of the value.
1003
+ // $return: Valid values are: 'array', 'boolean', 'datetime', 'function', 'null', 'number', 'object', 'regex', 'string'.
1004
+ 'systemType': ([value]) => {
1005
+ const type = typeof value;
1006
+ if (type === 'object') {
1007
+ if (value === null) {
1008
+ return 'null';
1009
+ } else if (Array.isArray(value)) {
1010
+ return 'array';
1011
+ } else if (value instanceof Date) {
1012
+ return 'datetime';
1013
+ } else if (value instanceof RegExp) {
1014
+ return 'regex';
1015
+ }
1016
+ }
1017
+ return type;
1018
+ },
1019
+
998
1020
 
999
1021
  //
1000
1022
  // URL functions
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "bare-script",
4
- "version": "2.2.14",
4
+ "version": "2.2.16",
5
5
  "description": "BareScript; a lightweight scripting and expression language",
6
6
  "keywords": [
7
7
  "expression",