@reekon-tools/boldr-utils 1.4.15 → 1.4.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.
@@ -102,6 +102,24 @@ export const calculateFormula = (formula, formulas, columns, tableConfig, measur
102
102
  currentMappings[variable] = mapping;
103
103
  }
104
104
  }
105
+ // Validate that all required inputs are filled out
106
+ const missingInputs = [];
107
+ for (const [variable, mapping] of Object.entries(currentMappings)) {
108
+ const mappingObj = typeof mapping === 'string'
109
+ ? { id: mapping, type: 'column' }
110
+ : mapping;
111
+ // Only check column references (formula references are handled separately)
112
+ if (mappingObj.type === 'column' || !mappingObj.type) {
113
+ const columnId = mappingObj.id;
114
+ if (!(columnId in valueMap)) {
115
+ missingInputs.push(variable);
116
+ }
117
+ }
118
+ }
119
+ if (missingInputs.length > 0) {
120
+ console.warn(`Not all inputs are filled out. Missing values for: ${missingInputs.join(', ')}`);
121
+ return null;
122
+ }
105
123
  const result = evaluateFormula({
106
124
  expression: formula.expression,
107
125
  mappings: currentMappings,
@@ -1,5 +1,21 @@
1
1
  import { Units } from '../types/firestore.js';
2
- import { compile, unit as mathUnit } from 'mathjs';
2
+ import { create, all } from 'mathjs';
3
+ // Create a custom mathjs instance with degree-based trigonometric functions
4
+ const math = create(all);
5
+ // Helper to convert degrees to radians
6
+ const degToRad = (degrees) => (degrees * Math.PI) / 180;
7
+ // Import degree-based trigonometric functions
8
+ math.import({
9
+ sin: (x) => Math.sin(degToRad(x)),
10
+ cos: (x) => Math.cos(degToRad(x)),
11
+ tan: (x) => Math.tan(degToRad(x)),
12
+ asin: (x) => (Math.asin(x) * 180) / Math.PI,
13
+ acos: (x) => (Math.acos(x) * 180) / Math.PI,
14
+ atan: (x) => (Math.atan(x) * 180) / Math.PI,
15
+ atan2: (y, x) => (Math.atan2(y, x) * 180) / Math.PI,
16
+ }, { override: true });
17
+ const compile = math.compile.bind(math);
18
+ const mathUnit = math.unit.bind(math);
3
19
  // Cache for evaluated formulas to improve performance
4
20
  const formulaCache = new Map();
5
21
  function normalizeUnitForMathJS(unit) {
@@ -217,7 +233,7 @@ export function evaluateFormula({ expression, mappings, valueMap, unit, formulas
217
233
  return result;
218
234
  }
219
235
  catch (err) {
220
- console.error('❌ Formula evaluation failed:', err);
236
+ console.warn('❌ Formula evaluation failed:', err);
221
237
  return err instanceof Error ? err.message : 'Error';
222
238
  }
223
239
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reekon-tools/boldr-utils",
3
- "version": "1.4.15",
3
+ "version": "1.4.16",
4
4
  "description": "Shared utilities for formulas and measurement conversion used in Reekon apps",
5
5
  "author": "REEKON Tools",
6
6
  "license": "MIT",