@reekon-tools/boldr-utils 1.0.11 → 1.0.13
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/package.json +6 -10
- package/src/formulas/createFormulaScope.ts +47 -0
- package/src/formulas/evaluateColumnValue.ts +70 -0
- package/src/formulas/mathUnitMap.ts +26 -0
- package/src/hooks/useParseMeasurement.ts +18 -0
- package/src/types/firestore.ts +202 -0
- package/src/utils/evaluateFormula.ts +57 -0
- package/src/utils/micrometersToUnit.ts +75 -0
- package/src/utils/parseMeasurement.ts +54 -0
- package/dist/formulas/createFormulaScope.d.ts +0 -7
- package/dist/formulas/createFormulaScope.js +0 -27
- package/dist/formulas/createFormulaScope.js.map +0 -1
- package/dist/formulas/evaluateColumnValue.d.ts +0 -9
- package/dist/formulas/evaluateColumnValue.js +0 -47
- package/dist/formulas/evaluateColumnValue.js.map +0 -1
- package/dist/formulas/mathUnitMap.d.ts +0 -2
- package/dist/formulas/mathUnitMap.js +0 -26
- package/dist/formulas/mathUnitMap.js.map +0 -1
- package/dist/hooks/useParseMeasurement.d.ts +0 -4
- package/dist/hooks/useParseMeasurement.js +0 -15
- package/dist/hooks/useParseMeasurement.js.map +0 -1
- package/dist/index.js +0 -3
- package/dist/index.js.map +0 -1
- package/dist/types/firestore.d.ts +0 -159
- package/dist/types/firestore.js +0 -77
- package/dist/types/firestore.js.map +0 -1
- package/dist/utils/evaluateFormula.d.ts +0 -20
- package/dist/utils/evaluateFormula.js +0 -32
- package/dist/utils/evaluateFormula.js.map +0 -1
- package/dist/utils/micrometersToUnit.d.ts +0 -5
- package/dist/utils/micrometersToUnit.js +0 -67
- package/dist/utils/micrometersToUnit.js.map +0 -1
- package/dist/utils/parseMeasurement.d.ts +0 -2
- package/dist/utils/parseMeasurement.js +0 -41
- package/dist/utils/parseMeasurement.js.map +0 -1
- /package/{dist/index.d.ts → src/index.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reekon-tools/boldr-utils",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"main": "./dist/index.js",
|
|
7
|
-
"types": "./dist/index.d.ts",
|
|
3
|
+
"version": "1.0.13",
|
|
4
|
+
"main": "src/index.ts",
|
|
5
|
+
"types": "src/index.ts",
|
|
8
6
|
"exports": {
|
|
9
7
|
".": {
|
|
10
|
-
"import": "./
|
|
11
|
-
"types": "./
|
|
8
|
+
"import": "./src/index.ts",
|
|
9
|
+
"types": "./src/index.ts"
|
|
12
10
|
}
|
|
13
11
|
},
|
|
14
|
-
"files": [
|
|
15
|
-
"dist"
|
|
16
|
-
],
|
|
12
|
+
"files": ["src"],
|
|
17
13
|
"scripts": {
|
|
18
14
|
"build": "tsc",
|
|
19
15
|
"test": "jest"
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { FractionalTolerance, DecimalTolerance, Units } from '..';
|
|
2
|
+
import { ColumnType } from '..';
|
|
3
|
+
import { convertMicrometers } from '../utils/micrometersToUnit';
|
|
4
|
+
|
|
5
|
+
export function createFormulaScope({
|
|
6
|
+
group,
|
|
7
|
+
mappings,
|
|
8
|
+
columns,
|
|
9
|
+
measurementMap,
|
|
10
|
+
unit, // user preferred unit, e.g., 'in' or 'cm'
|
|
11
|
+
}: {
|
|
12
|
+
group: any;
|
|
13
|
+
mappings: Record<string, string>;
|
|
14
|
+
columns: any[];
|
|
15
|
+
measurementMap: Map<string, any[]>;
|
|
16
|
+
unit: string;
|
|
17
|
+
}): Record<string, number> {
|
|
18
|
+
const scope: Record<string, number> = {};
|
|
19
|
+
|
|
20
|
+
for (const [variable, columnId] of Object.entries(mappings)) {
|
|
21
|
+
const rawValue = group.columns.get(columnId);
|
|
22
|
+
const columnDef = columns.find((c) => c.id === columnId);
|
|
23
|
+
|
|
24
|
+
let parsedValue: number | undefined;
|
|
25
|
+
|
|
26
|
+
if (columnDef?.type === ColumnType.Measurement) {
|
|
27
|
+
const groupMeasurements = measurementMap.get(group.id) || [];
|
|
28
|
+
const measurement = groupMeasurements.find((m) => m.id === rawValue);
|
|
29
|
+
if (measurement?.value !== undefined) {
|
|
30
|
+
// Here, the unit
|
|
31
|
+
parsedValue = parseFloat(convertMicrometers(
|
|
32
|
+
measurement.value,
|
|
33
|
+
unit as Units,
|
|
34
|
+
FractionalTolerance.Sixteenth,
|
|
35
|
+
DecimalTolerance.Hundredth
|
|
36
|
+
).value);
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
parsedValue =
|
|
40
|
+
typeof rawValue === 'number' ? rawValue : parseFloat(rawValue || '');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
scope[variable] = isNaN(parsedValue!) ? 0 : parsedValue!;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return scope;
|
|
47
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { ColumnConfig, ColumnType, Group, Units } from '..';
|
|
2
|
+
import { createFormulaScope } from './createFormulaScope';
|
|
3
|
+
import { compile, unit as mathUnit } from 'mathjs';
|
|
4
|
+
import { normalizeUnitForMathJS } from './mathUnitMap';
|
|
5
|
+
|
|
6
|
+
export function evaluateColumnValue({
|
|
7
|
+
group,
|
|
8
|
+
col,
|
|
9
|
+
formulas,
|
|
10
|
+
columns,
|
|
11
|
+
measurementMap,
|
|
12
|
+
userUnit,
|
|
13
|
+
}: {
|
|
14
|
+
group: Group;
|
|
15
|
+
col: ColumnConfig;
|
|
16
|
+
formulas: any[];
|
|
17
|
+
columns: any[];
|
|
18
|
+
measurementMap: Map<string, any[]>;
|
|
19
|
+
userUnit: Units;
|
|
20
|
+
}): any {
|
|
21
|
+
// Normalize immediately
|
|
22
|
+
const normalizedUnit = normalizeUnitForMathJS(userUnit);
|
|
23
|
+
|
|
24
|
+
if (col.type === ColumnType.Measurement) {
|
|
25
|
+
const value = group.columns.get(col.id);
|
|
26
|
+
const groupMeasurements = measurementMap.get(group.id) || [];
|
|
27
|
+
const measurement = groupMeasurements.find((m) => m.id === value);
|
|
28
|
+
return measurement ?? value;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (col.type === ColumnType.Formula) {
|
|
32
|
+
const formula = formulas.find((f) => f.id === col.formulaId);
|
|
33
|
+
if (!formula) {
|
|
34
|
+
console.warn(`Missing formula with id ${col.formulaId}`);
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (col.mappings === undefined) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
const scope = createFormulaScope({
|
|
44
|
+
group,
|
|
45
|
+
mappings: col.mappings,
|
|
46
|
+
columns,
|
|
47
|
+
measurementMap,
|
|
48
|
+
unit: normalizedUnit, // ✅ normalized!
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
console.log('Evaluating:', formula.expression, scope);
|
|
52
|
+
|
|
53
|
+
const compiled = compile(formula.expression);
|
|
54
|
+
const result = compiled.evaluate(scope);
|
|
55
|
+
|
|
56
|
+
const asUnit = mathUnit(result, normalizedUnit);
|
|
57
|
+
|
|
58
|
+
if (!asUnit.equalBase(mathUnit('1 um'))) {
|
|
59
|
+
throw new Error(`Incompatible unit: ${asUnit.formatUnits()} is not compatible with ${normalizedUnit}`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return Math.round(asUnit.toNumber('um'));
|
|
63
|
+
} catch (error) {
|
|
64
|
+
console.error(`Failed to evaluate formula: ${col.name}`, error);
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return group.columns.get(col.id) ?? '';
|
|
70
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Units } from "..";
|
|
2
|
+
|
|
3
|
+
// Must convert our custom unit types
|
|
4
|
+
export function normalizeUnitForMathJS(unit: Units | string): string {
|
|
5
|
+
switch (unit) {
|
|
6
|
+
case Units.Centimeters:
|
|
7
|
+
case 'cm':
|
|
8
|
+
return 'cm';
|
|
9
|
+
case Units.Millimeters:
|
|
10
|
+
case 'mm':
|
|
11
|
+
return 'mm';
|
|
12
|
+
case Units.Meters:
|
|
13
|
+
case 'm':
|
|
14
|
+
return 'm';
|
|
15
|
+
case Units.Inches:
|
|
16
|
+
case Units.FractionalInches:
|
|
17
|
+
return 'in';
|
|
18
|
+
case Units.Feet:
|
|
19
|
+
case Units.FeetInchesDecimal:
|
|
20
|
+
case Units.FeetInchesFractional:
|
|
21
|
+
return 'ft';
|
|
22
|
+
default:
|
|
23
|
+
console.warn(`Unknown or unsupported unit: ${unit}, falling back to 'mm'`);
|
|
24
|
+
return 'mm'; // fallback
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { parseMeasurement } from '../utils/parseMeasurement';
|
|
4
|
+
|
|
5
|
+
export const useParseMeasurement = () => {
|
|
6
|
+
const [error, setError] = useState<string | null>(null);
|
|
7
|
+
|
|
8
|
+
const parseMeasurementInput = (input: string, defaultUnit: string = 'mm') => {
|
|
9
|
+
setError(null);
|
|
10
|
+
const result = parseMeasurement(input, defaultUnit);
|
|
11
|
+
if (result === null) {
|
|
12
|
+
setError('Invalid measurement. Please provide a valid number and unit.');
|
|
13
|
+
}
|
|
14
|
+
return result;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
return { parseMeasurementInput, error };
|
|
18
|
+
};
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
interface FirestoreDoc {
|
|
2
|
+
id: string;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
interface Timestamps {
|
|
6
|
+
createdAt: Date;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface CreatedBy {
|
|
10
|
+
firstName: string;
|
|
11
|
+
lastName: string;
|
|
12
|
+
userId: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface Organization extends FirestoreDoc, Timestamps {
|
|
16
|
+
name: string;
|
|
17
|
+
createdBy: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export enum OrganizationRole {
|
|
21
|
+
Admin = 'admin',
|
|
22
|
+
Member = 'member',
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export enum InvitationStatus {
|
|
26
|
+
Pending = 'pending',
|
|
27
|
+
Accepted = 'accepted',
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface Invitation extends FirestoreDoc, Timestamps {
|
|
31
|
+
delivery?: unknown;
|
|
32
|
+
invitationCode: string;
|
|
33
|
+
inviteeEmail: string;
|
|
34
|
+
inviteeUid: string;
|
|
35
|
+
inviterId: string;
|
|
36
|
+
message: {
|
|
37
|
+
subject: string;
|
|
38
|
+
text: string;
|
|
39
|
+
};
|
|
40
|
+
organizationId: string;
|
|
41
|
+
role: OrganizationRole;
|
|
42
|
+
status: InvitationStatus
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export interface OrganizationMember extends FirestoreDoc {
|
|
46
|
+
email: string;
|
|
47
|
+
firstName: string;
|
|
48
|
+
lastName: string;
|
|
49
|
+
joinedAt: Date;
|
|
50
|
+
role: OrganizationRole;
|
|
51
|
+
userId: string;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export interface Project extends FirestoreDoc, Timestamps {
|
|
55
|
+
name: string;
|
|
56
|
+
description: string;
|
|
57
|
+
imageUrl: string | null;
|
|
58
|
+
streetAddress: string;
|
|
59
|
+
city: string;
|
|
60
|
+
zipCode: string;
|
|
61
|
+
state: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export enum FolderType {
|
|
65
|
+
Project = 'project',
|
|
66
|
+
Job = 'job',
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface Folder extends FirestoreDoc {
|
|
70
|
+
name: string;
|
|
71
|
+
index: number;
|
|
72
|
+
parentFolderId?: string | null;
|
|
73
|
+
projectId: string | null;
|
|
74
|
+
type: FolderType;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface Job extends FirestoreDoc, Timestamps {
|
|
78
|
+
name: string;
|
|
79
|
+
folderId: string;
|
|
80
|
+
progress: number;
|
|
81
|
+
projectId: string;
|
|
82
|
+
totalTasks: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface Section {
|
|
86
|
+
id: string;
|
|
87
|
+
name: string;
|
|
88
|
+
tableConfig: ColumnConfig[];
|
|
89
|
+
measurements: string[];
|
|
90
|
+
projectId: string;
|
|
91
|
+
jobId: string;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface Group extends FirestoreDoc, Timestamps {
|
|
95
|
+
projectId: string;
|
|
96
|
+
jobId: string;
|
|
97
|
+
sectionId: string;
|
|
98
|
+
name: string;
|
|
99
|
+
sortIndex: number;
|
|
100
|
+
columns: Record<string, any>;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export enum ColumnType {
|
|
104
|
+
Text = 'text',
|
|
105
|
+
Number = 'number',
|
|
106
|
+
Measurement = 'measurement',
|
|
107
|
+
Boolean = 'boolean',
|
|
108
|
+
Formula = 'formula',
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface Formula extends FirestoreDoc, Timestamps {
|
|
112
|
+
expression: string;
|
|
113
|
+
name: string;
|
|
114
|
+
varaibles: string[];
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface ColumnConfig {
|
|
118
|
+
id: string;
|
|
119
|
+
name: string;
|
|
120
|
+
type: ColumnType;
|
|
121
|
+
formulaId?: string;
|
|
122
|
+
mappings?: Record<string, string> // Used for formula mapping
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface Row {
|
|
126
|
+
[key: string]: any; // Dynamic keys representing column IDs, with their respective data
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface Measurement extends FirestoreDoc, Timestamps, CreatedBy {
|
|
130
|
+
projectId:string;
|
|
131
|
+
jobId:string;
|
|
132
|
+
groupId:string;
|
|
133
|
+
sectionId:string;
|
|
134
|
+
value: number;
|
|
135
|
+
index: number;
|
|
136
|
+
label: string;
|
|
137
|
+
measurementIndex: number;
|
|
138
|
+
unit: Units;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export enum Units {
|
|
142
|
+
Centimeters = 'cm',
|
|
143
|
+
Millimeters = 'mm',
|
|
144
|
+
Meters = 'm',
|
|
145
|
+
Inches = 'in',
|
|
146
|
+
FractionalInches = 'in_frac',
|
|
147
|
+
Feet = 'ft',
|
|
148
|
+
FeetInchesDecimal = 'ft_in_decimal',
|
|
149
|
+
FeetInchesFractional = 'ft_in_frac',
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export const convertUnitsToReadable = (targetUnit: Units) => {
|
|
153
|
+
switch (targetUnit) {
|
|
154
|
+
case Units.Meters:
|
|
155
|
+
return 'm';
|
|
156
|
+
case Units.Millimeters:
|
|
157
|
+
return 'mm';
|
|
158
|
+
case Units.Centimeters:
|
|
159
|
+
return 'cm';
|
|
160
|
+
case Units.Feet:
|
|
161
|
+
return 'ft';
|
|
162
|
+
case Units.FractionalInches:
|
|
163
|
+
return 'in (fractional)';
|
|
164
|
+
case Units.Inches:
|
|
165
|
+
return 'in';
|
|
166
|
+
case Units.FeetInchesDecimal:
|
|
167
|
+
return 'ft-in (decimal)';
|
|
168
|
+
case Units.FeetInchesFractional:
|
|
169
|
+
return 'ft-in (fractional)';
|
|
170
|
+
default:
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
export enum FractionalTolerance {
|
|
176
|
+
Fourth = '4',
|
|
177
|
+
Eighth = '8',
|
|
178
|
+
Sixteenth = '16',
|
|
179
|
+
ThirtySecond = '32',
|
|
180
|
+
SixtyFourth = '64',
|
|
181
|
+
OneTwentyEighth = '128',
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export enum DecimalTolerance {
|
|
185
|
+
Half = '0.5',
|
|
186
|
+
Tenth = '0.1',
|
|
187
|
+
Hundredth = '0.01',
|
|
188
|
+
Thousandth = '0.001',
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export interface UserDocument extends FirestoreDoc, Timestamps {
|
|
192
|
+
defaultOrganization: string;
|
|
193
|
+
displayName: string;
|
|
194
|
+
email: string;
|
|
195
|
+
firstName: string;
|
|
196
|
+
lastName: string;
|
|
197
|
+
defaultUnit: Units;
|
|
198
|
+
decimalTolerance: DecimalTolerance;
|
|
199
|
+
fractionalTolerance: FractionalTolerance;
|
|
200
|
+
showWizard: boolean; // The onboarding screen displayed on web
|
|
201
|
+
printLabelSize: string;
|
|
202
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { create, all, Unit } from 'mathjs';
|
|
2
|
+
|
|
3
|
+
const math = create(all);
|
|
4
|
+
|
|
5
|
+
type MeasurementMap = Map<string, { id: string; value: number }[]>;
|
|
6
|
+
|
|
7
|
+
interface FormulaEvaluationOptions {
|
|
8
|
+
expression: string;
|
|
9
|
+
mappings: Record<string, string>;
|
|
10
|
+
group: { id: string; columns: Map<string, any> };
|
|
11
|
+
columns: { id: string; type: string }[];
|
|
12
|
+
measurementMap: MeasurementMap;
|
|
13
|
+
defaultUnit?: string; // 'um' by default
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function evaluateFormula({
|
|
17
|
+
expression,
|
|
18
|
+
mappings,
|
|
19
|
+
group,
|
|
20
|
+
columns,
|
|
21
|
+
measurementMap,
|
|
22
|
+
defaultUnit = 'um',
|
|
23
|
+
}: FormulaEvaluationOptions): number | string {
|
|
24
|
+
const scope: Record<string, any> = {};
|
|
25
|
+
|
|
26
|
+
for (const [variable, columnId] of Object.entries(mappings)) {
|
|
27
|
+
const rawValue = group.columns.get(columnId);
|
|
28
|
+
const columnDef = columns.find((c) => c.id === columnId);
|
|
29
|
+
|
|
30
|
+
if (columnDef?.type === 'Measurement') {
|
|
31
|
+
const groupMeasurements = measurementMap.get(group.id) || [];
|
|
32
|
+
const measurement = groupMeasurements.find((m) => m.id === rawValue);
|
|
33
|
+
if (measurement?.value !== undefined) {
|
|
34
|
+
scope[variable] = math.unit(measurement.value, defaultUnit);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const parsedValue =
|
|
40
|
+
typeof rawValue === 'number' ? rawValue : parseFloat(rawValue || '');
|
|
41
|
+
scope[variable] = isNaN(parsedValue) ? 0 : parsedValue;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
const compiled = math.compile(expression);
|
|
46
|
+
const result = compiled.evaluate(scope);
|
|
47
|
+
|
|
48
|
+
if (math.typeOf(result) === 'Unit') {
|
|
49
|
+
return result.toNumber(defaultUnit);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return result;
|
|
53
|
+
} catch (err) {
|
|
54
|
+
console.error(`Formula evaluation failed:`, err);
|
|
55
|
+
return 'Error';
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { convertUnitsToReadable, DecimalTolerance, FractionalTolerance, Units } from '../index';
|
|
2
|
+
import { create, all } from 'mathjs';
|
|
3
|
+
|
|
4
|
+
const math = create(all);
|
|
5
|
+
|
|
6
|
+
export const convertMicrometers = (
|
|
7
|
+
micrometers: number,
|
|
8
|
+
unit: Units,
|
|
9
|
+
fractionalTolerance: FractionalTolerance,
|
|
10
|
+
decimalTolerance: DecimalTolerance
|
|
11
|
+
): { value: string; unit: string | null } => {
|
|
12
|
+
const converted = math.unit(micrometers, 'um');
|
|
13
|
+
let value: number | string = 0;
|
|
14
|
+
let displayUnit: string | null = '';
|
|
15
|
+
|
|
16
|
+
switch (unit) {
|
|
17
|
+
case Units.Inches:
|
|
18
|
+
case Units.FractionalInches: {
|
|
19
|
+
const inches = converted.toNumber('in');
|
|
20
|
+
displayUnit = 'in';
|
|
21
|
+
if (unit === Units.FractionalInches) {
|
|
22
|
+
const denominator = parseInt(fractionalTolerance, 10);
|
|
23
|
+
const whole = Math.floor(inches);
|
|
24
|
+
const fractional = inches - whole;
|
|
25
|
+
const numerator = Math.round(fractional * denominator);
|
|
26
|
+
|
|
27
|
+
value =
|
|
28
|
+
numerator === 0
|
|
29
|
+
? `${whole}`
|
|
30
|
+
: `${whole} ${numerator}/${denominator}`;
|
|
31
|
+
} else {
|
|
32
|
+
value = inches.toFixed(decimalTolerance.length - 2); // Match decimal places to tolerance
|
|
33
|
+
}
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
case Units.Feet:
|
|
37
|
+
case Units.FeetInchesFractional:
|
|
38
|
+
case Units.FeetInchesDecimal: {
|
|
39
|
+
const feet = converted.toNumber('ft');
|
|
40
|
+
const wholeFeet = Math.floor(feet);
|
|
41
|
+
const fractionalFeet = feet - wholeFeet;
|
|
42
|
+
displayUnit = 'ft';
|
|
43
|
+
|
|
44
|
+
if (unit === Units.FeetInchesFractional) {
|
|
45
|
+
const inches = fractionalFeet * 12;
|
|
46
|
+
const wholeInches = Math.floor(inches);
|
|
47
|
+
const fractional = inches - wholeInches;
|
|
48
|
+
const denominator = parseInt(fractionalTolerance, 10);
|
|
49
|
+
const numerator = Math.round(fractional * denominator);
|
|
50
|
+
|
|
51
|
+
value =
|
|
52
|
+
numerator === 0
|
|
53
|
+
? `${wholeFeet}' ${wholeInches}"`
|
|
54
|
+
: `${wholeFeet}' ${wholeInches} ${numerator}/${denominator}"`;
|
|
55
|
+
} else if (unit === Units.FeetInchesDecimal) {
|
|
56
|
+
const inches = (fractionalFeet * 12).toFixed(decimalTolerance.length - 2);
|
|
57
|
+
value = `${wholeFeet}' ${inches}"`;
|
|
58
|
+
} else {
|
|
59
|
+
value = feet.toFixed(decimalTolerance.length - 2);
|
|
60
|
+
}
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
case Units.Meters:
|
|
64
|
+
case Units.Centimeters:
|
|
65
|
+
case Units.Millimeters: {
|
|
66
|
+
displayUnit = convertUnitsToReadable(unit);
|
|
67
|
+
value = converted.toNumber(unit).toFixed(decimalTolerance.length - 2);
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
default:
|
|
71
|
+
throw new Error('Unsupported unit');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return { value, unit: displayUnit };
|
|
75
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { all, create } from 'mathjs';
|
|
2
|
+
|
|
3
|
+
const math = create(all);
|
|
4
|
+
|
|
5
|
+
export const parseMeasurement = (
|
|
6
|
+
input: string,
|
|
7
|
+
defaultUnit: string = 'mm'
|
|
8
|
+
): number | null => {
|
|
9
|
+
try {
|
|
10
|
+
// Trim and normalize spaces
|
|
11
|
+
const normalizedInput = input.trim().replace(/\s+/g, ' ');
|
|
12
|
+
|
|
13
|
+
// Preprocess mixed fractions (e.g., "12 1/2" -> "12 + 1/2")
|
|
14
|
+
const processedInput = normalizedInput.replace(
|
|
15
|
+
/(\d+)\s+(\d+\/\d+)/g,
|
|
16
|
+
'$1 + $2'
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
// Match numeric value and optional unit
|
|
20
|
+
const match = processedInput.match(/^([\d.+\-*/\s]+)\s*(\w+)?$/);
|
|
21
|
+
|
|
22
|
+
if (!match) {
|
|
23
|
+
throw new Error('Invalid input format');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const [_, value, unit] = match;
|
|
27
|
+
|
|
28
|
+
// Evaluate the numeric value (e.g., "12 + 1/2")
|
|
29
|
+
const numericValue = math.evaluate(value.trim());
|
|
30
|
+
|
|
31
|
+
// Use the provided unit or fallback to the default unit
|
|
32
|
+
const targetUnit = unit || defaultUnit;
|
|
33
|
+
|
|
34
|
+
// Convert to micrometers
|
|
35
|
+
return math.unit(numericValue, targetUnit).toNumber('um');
|
|
36
|
+
} catch (err) {
|
|
37
|
+
if (err instanceof Error) {
|
|
38
|
+
console.error('Invalid measurement:', err.message);
|
|
39
|
+
} else {
|
|
40
|
+
console.error('An unknown error occurred:', err);
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const numberToLetterIndex = (index: number): string => {
|
|
47
|
+
let result = '';
|
|
48
|
+
while (index > 0) {
|
|
49
|
+
index--; // Adjust for 0-based index
|
|
50
|
+
result = String.fromCharCode((index % 26) + 65) + result;
|
|
51
|
+
index = Math.floor(index / 26);
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { FractionalTolerance, DecimalTolerance } from '..';
|
|
2
|
-
import { ColumnType } from '..';
|
|
3
|
-
import { convertMicrometers } from '../utils/micrometersToUnit';
|
|
4
|
-
export function createFormulaScope({ group, mappings, columns, measurementMap, unit, // user preferred unit, e.g., 'in' or 'cm'
|
|
5
|
-
}) {
|
|
6
|
-
const scope = {};
|
|
7
|
-
for (const [variable, columnId] of Object.entries(mappings)) {
|
|
8
|
-
const rawValue = group.columns.get(columnId);
|
|
9
|
-
const columnDef = columns.find((c) => c.id === columnId);
|
|
10
|
-
let parsedValue;
|
|
11
|
-
if (columnDef?.type === ColumnType.Measurement) {
|
|
12
|
-
const groupMeasurements = measurementMap.get(group.id) || [];
|
|
13
|
-
const measurement = groupMeasurements.find((m) => m.id === rawValue);
|
|
14
|
-
if (measurement?.value !== undefined) {
|
|
15
|
-
// Here, the unit
|
|
16
|
-
parsedValue = parseFloat(convertMicrometers(measurement.value, unit, FractionalTolerance.Sixteenth, DecimalTolerance.Hundredth).value);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
parsedValue =
|
|
21
|
-
typeof rawValue === 'number' ? rawValue : parseFloat(rawValue || '');
|
|
22
|
-
}
|
|
23
|
-
scope[variable] = isNaN(parsedValue) ? 0 : parsedValue;
|
|
24
|
-
}
|
|
25
|
-
return scope;
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=createFormulaScope.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createFormulaScope.js","sourceRoot":"","sources":["../../src/formulas/createFormulaScope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAS,MAAM,IAAI,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAEhE,MAAM,UAAU,kBAAkB,CAAC,EACjC,KAAK,EACL,QAAQ,EACR,OAAO,EACP,cAAc,EACd,IAAI,EAAE,0CAA0C;EAOjD;IACC,MAAM,KAAK,GAA2B,EAAE,CAAC;IAEzC,KAAK,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5D,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC7C,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,QAAQ,CAAC,CAAC;QAEzD,IAAI,WAA+B,CAAC;QAEpC,IAAI,SAAS,EAAE,IAAI,KAAK,UAAU,CAAC,WAAW,EAAE,CAAC;YAC/C,MAAM,iBAAiB,GAAG,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC;YAC7D,MAAM,WAAW,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,QAAQ,CAAC,CAAC;YACrE,IAAI,WAAW,EAAE,KAAK,KAAK,SAAS,EAAE,CAAC;gBACrC,kBAAkB;gBAClB,WAAW,GAAG,UAAU,CAAC,kBAAkB,CACvC,WAAW,CAAC,KAAK,EACjB,IAAa,EACb,mBAAmB,CAAC,SAAS,EAC7B,gBAAgB,CAAC,SAAS,CAC3B,CAAC,KAAK,CAAC,CAAC;YACb,CAAC;QACH,CAAC;aAAM,CAAC;YACN,WAAW;gBACT,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;QACzE,CAAC;QAED,KAAK,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC,WAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAY,CAAC;IAC3D,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ColumnConfig, Group, Units } from '..';
|
|
2
|
-
export declare function evaluateColumnValue({ group, col, formulas, columns, measurementMap, userUnit, }: {
|
|
3
|
-
group: Group;
|
|
4
|
-
col: ColumnConfig;
|
|
5
|
-
formulas: any[];
|
|
6
|
-
columns: any[];
|
|
7
|
-
measurementMap: Map<string, any[]>;
|
|
8
|
-
userUnit: Units;
|
|
9
|
-
}): any;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { ColumnType } from '..';
|
|
2
|
-
import { createFormulaScope } from './createFormulaScope';
|
|
3
|
-
import { compile, unit as mathUnit } from 'mathjs';
|
|
4
|
-
import { normalizeUnitForMathJS } from './mathUnitMap';
|
|
5
|
-
export function evaluateColumnValue({ group, col, formulas, columns, measurementMap, userUnit, }) {
|
|
6
|
-
// Normalize immediately
|
|
7
|
-
const normalizedUnit = normalizeUnitForMathJS(userUnit);
|
|
8
|
-
if (col.type === ColumnType.Measurement) {
|
|
9
|
-
const value = group.columns.get(col.id);
|
|
10
|
-
const groupMeasurements = measurementMap.get(group.id) || [];
|
|
11
|
-
const measurement = groupMeasurements.find((m) => m.id === value);
|
|
12
|
-
return measurement ?? value;
|
|
13
|
-
}
|
|
14
|
-
if (col.type === ColumnType.Formula) {
|
|
15
|
-
const formula = formulas.find((f) => f.id === col.formulaId);
|
|
16
|
-
if (!formula) {
|
|
17
|
-
console.warn(`Missing formula with id ${col.formulaId}`);
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
if (col.mappings === undefined) {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
try {
|
|
24
|
-
const scope = createFormulaScope({
|
|
25
|
-
group,
|
|
26
|
-
mappings: col.mappings,
|
|
27
|
-
columns,
|
|
28
|
-
measurementMap,
|
|
29
|
-
unit: normalizedUnit, // ✅ normalized!
|
|
30
|
-
});
|
|
31
|
-
console.log('Evaluating:', formula.expression, scope);
|
|
32
|
-
const compiled = compile(formula.expression);
|
|
33
|
-
const result = compiled.evaluate(scope);
|
|
34
|
-
const asUnit = mathUnit(result, normalizedUnit);
|
|
35
|
-
if (!asUnit.equalBase(mathUnit('1 um'))) {
|
|
36
|
-
throw new Error(`Incompatible unit: ${asUnit.formatUnits()} is not compatible with ${normalizedUnit}`);
|
|
37
|
-
}
|
|
38
|
-
return Math.round(asUnit.toNumber('um'));
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
console.error(`Failed to evaluate formula: ${col.name}`, error);
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return group.columns.get(col.id) ?? '';
|
|
46
|
-
}
|
|
47
|
-
//# sourceMappingURL=evaluateColumnValue.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"evaluateColumnValue.js","sourceRoot":"","sources":["../../src/formulas/evaluateColumnValue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,UAAU,EAAgB,MAAM,IAAI,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,QAAQ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IAAI,EAAE,cAAc,EAAE,gBAAgB;aACvC,CAAC,CAAC;YAEH,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;YAEtD,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;YAC7C,MAAM,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YAExC,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;YAEhD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;gBACxC,MAAM,IAAI,KAAK,CAAC,sBAAsB,MAAM,CAAC,WAAW,EAAE,2BAA2B,cAAc,EAAE,CAAC,CAAC;YACzG,CAAC;YAED,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;QAC3C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,+BAA+B,GAAG,CAAC,IAAI,EAAE,EAAE,KAAK,CAAC,CAAC;YAChE,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC;AACzC,CAAC"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Units } from "..";
|
|
2
|
-
// Must convert our custom unit types
|
|
3
|
-
export function normalizeUnitForMathJS(unit) {
|
|
4
|
-
switch (unit) {
|
|
5
|
-
case Units.Centimeters:
|
|
6
|
-
case 'cm':
|
|
7
|
-
return 'cm';
|
|
8
|
-
case Units.Millimeters:
|
|
9
|
-
case 'mm':
|
|
10
|
-
return 'mm';
|
|
11
|
-
case Units.Meters:
|
|
12
|
-
case 'm':
|
|
13
|
-
return 'm';
|
|
14
|
-
case Units.Inches:
|
|
15
|
-
case Units.FractionalInches:
|
|
16
|
-
return 'in';
|
|
17
|
-
case Units.Feet:
|
|
18
|
-
case Units.FeetInchesDecimal:
|
|
19
|
-
case Units.FeetInchesFractional:
|
|
20
|
-
return 'ft';
|
|
21
|
-
default:
|
|
22
|
-
console.warn(`Unknown or unsupported unit: ${unit}, falling back to 'mm'`);
|
|
23
|
-
return 'mm'; // fallback
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=mathUnitMap.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mathUnitMap.js","sourceRoot":"","sources":["../../src/formulas/mathUnitMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,IAAI,CAAC;AAE3B,sCAAsC;AACtC,MAAM,UAAU,sBAAsB,CAAC,IAAoB;IACzD,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,KAAK,CAAC,WAAW,CAAC;QACvB,KAAK,IAAI;YACP,OAAO,IAAI,CAAC;QACd,KAAK,KAAK,CAAC,WAAW,CAAC;QACvB,KAAK,IAAI;YACP,OAAO,IAAI,CAAC;QACd,KAAK,KAAK,CAAC,MAAM,CAAC;QAClB,KAAK,GAAG;YACN,OAAO,GAAG,CAAC;QACb,KAAK,KAAK,CAAC,MAAM,CAAC;QAClB,KAAK,KAAK,CAAC,gBAAgB;YACzB,OAAO,IAAI,CAAC;QACd,KAAK,KAAK,CAAC,IAAI,CAAC;QAChB,KAAK,KAAK,CAAC,iBAAiB,CAAC;QAC7B,KAAK,KAAK,CAAC,oBAAoB;YAC7B,OAAO,IAAI,CAAC;QACd;YACE,OAAO,CAAC,IAAI,CAAC,gCAAgC,IAAI,wBAAwB,CAAC,CAAC;YAC3E,OAAO,IAAI,CAAC,CAAC,WAAW;IAC5B,CAAC;AACH,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { useState } from 'react';
|
|
2
|
-
import { parseMeasurement } from '../utils/parseMeasurement';
|
|
3
|
-
export const useParseMeasurement = () => {
|
|
4
|
-
const [error, setError] = useState(null);
|
|
5
|
-
const parseMeasurementInput = (input, defaultUnit = 'mm') => {
|
|
6
|
-
setError(null);
|
|
7
|
-
const result = parseMeasurement(input, defaultUnit);
|
|
8
|
-
if (result === null) {
|
|
9
|
-
setError('Invalid measurement. Please provide a valid number and unit.');
|
|
10
|
-
}
|
|
11
|
-
return result;
|
|
12
|
-
};
|
|
13
|
-
return { parseMeasurementInput, error };
|
|
14
|
-
};
|
|
15
|
-
//# sourceMappingURL=useParseMeasurement.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useParseMeasurement.js","sourceRoot":"","sources":["../../src/hooks/useParseMeasurement.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,EAAE;IACtC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAgB,IAAI,CAAC,CAAC;IAExD,MAAM,qBAAqB,GAAG,CAAC,KAAa,EAAE,cAAsB,IAAI,EAAE,EAAE;QAC1E,QAAQ,CAAC,IAAI,CAAC,CAAC;QACf,MAAM,MAAM,GAAG,gBAAgB,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;QACpD,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YACpB,QAAQ,CAAC,8DAA8D,CAAC,CAAC;QAC3E,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;IAEF,OAAO,EAAE,qBAAqB,EAAE,KAAK,EAAE,CAAC;AAC1C,CAAC,CAAC"}
|
package/dist/index.js
DELETED
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC"}
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
interface FirestoreDoc {
|
|
2
|
-
id: string;
|
|
3
|
-
}
|
|
4
|
-
interface Timestamps {
|
|
5
|
-
createdAt: Date;
|
|
6
|
-
}
|
|
7
|
-
interface CreatedBy {
|
|
8
|
-
firstName: string;
|
|
9
|
-
lastName: string;
|
|
10
|
-
userId: string;
|
|
11
|
-
}
|
|
12
|
-
export interface Organization extends FirestoreDoc, Timestamps {
|
|
13
|
-
name: string;
|
|
14
|
-
createdBy: string;
|
|
15
|
-
}
|
|
16
|
-
export declare enum OrganizationRole {
|
|
17
|
-
Admin = "admin",
|
|
18
|
-
Member = "member"
|
|
19
|
-
}
|
|
20
|
-
export declare enum InvitationStatus {
|
|
21
|
-
Pending = "pending",
|
|
22
|
-
Accepted = "accepted"
|
|
23
|
-
}
|
|
24
|
-
export interface Invitation extends FirestoreDoc, Timestamps {
|
|
25
|
-
delivery?: unknown;
|
|
26
|
-
invitationCode: string;
|
|
27
|
-
inviteeEmail: string;
|
|
28
|
-
inviteeUid: string;
|
|
29
|
-
inviterId: string;
|
|
30
|
-
message: {
|
|
31
|
-
subject: string;
|
|
32
|
-
text: string;
|
|
33
|
-
};
|
|
34
|
-
organizationId: string;
|
|
35
|
-
role: OrganizationRole;
|
|
36
|
-
status: InvitationStatus;
|
|
37
|
-
}
|
|
38
|
-
export interface OrganizationMember extends FirestoreDoc {
|
|
39
|
-
email: string;
|
|
40
|
-
firstName: string;
|
|
41
|
-
lastName: string;
|
|
42
|
-
joinedAt: Date;
|
|
43
|
-
role: OrganizationRole;
|
|
44
|
-
userId: string;
|
|
45
|
-
}
|
|
46
|
-
export interface Project extends FirestoreDoc, Timestamps {
|
|
47
|
-
name: string;
|
|
48
|
-
description: string;
|
|
49
|
-
imageUrl: string | null;
|
|
50
|
-
streetAddress: string;
|
|
51
|
-
city: string;
|
|
52
|
-
zipCode: string;
|
|
53
|
-
state: string;
|
|
54
|
-
}
|
|
55
|
-
export declare enum FolderType {
|
|
56
|
-
Project = "project",
|
|
57
|
-
Job = "job"
|
|
58
|
-
}
|
|
59
|
-
export interface Folder extends FirestoreDoc {
|
|
60
|
-
name: string;
|
|
61
|
-
index: number;
|
|
62
|
-
parentFolderId?: string | null;
|
|
63
|
-
projectId: string | null;
|
|
64
|
-
type: FolderType;
|
|
65
|
-
}
|
|
66
|
-
export interface Job extends FirestoreDoc, Timestamps {
|
|
67
|
-
name: string;
|
|
68
|
-
folderId: string;
|
|
69
|
-
progress: number;
|
|
70
|
-
projectId: string;
|
|
71
|
-
totalTasks: string;
|
|
72
|
-
}
|
|
73
|
-
export interface Section {
|
|
74
|
-
id: string;
|
|
75
|
-
name: string;
|
|
76
|
-
tableConfig: ColumnConfig[];
|
|
77
|
-
measurements: string[];
|
|
78
|
-
projectId: string;
|
|
79
|
-
jobId: string;
|
|
80
|
-
}
|
|
81
|
-
export interface Group extends FirestoreDoc, Timestamps {
|
|
82
|
-
projectId: string;
|
|
83
|
-
jobId: string;
|
|
84
|
-
sectionId: string;
|
|
85
|
-
name: string;
|
|
86
|
-
sortIndex: number;
|
|
87
|
-
columns: Record<string, any>;
|
|
88
|
-
}
|
|
89
|
-
export declare enum ColumnType {
|
|
90
|
-
Text = "text",
|
|
91
|
-
Number = "number",
|
|
92
|
-
Measurement = "measurement",
|
|
93
|
-
Boolean = "boolean",
|
|
94
|
-
Formula = "formula"
|
|
95
|
-
}
|
|
96
|
-
export interface Formula extends FirestoreDoc, Timestamps {
|
|
97
|
-
expression: string;
|
|
98
|
-
name: string;
|
|
99
|
-
varaibles: string[];
|
|
100
|
-
}
|
|
101
|
-
export interface ColumnConfig {
|
|
102
|
-
id: string;
|
|
103
|
-
name: string;
|
|
104
|
-
type: ColumnType;
|
|
105
|
-
formulaId?: string;
|
|
106
|
-
mappings?: Record<string, string>;
|
|
107
|
-
}
|
|
108
|
-
export interface Row {
|
|
109
|
-
[key: string]: any;
|
|
110
|
-
}
|
|
111
|
-
export interface Measurement extends FirestoreDoc, Timestamps, CreatedBy {
|
|
112
|
-
projectId: string;
|
|
113
|
-
jobId: string;
|
|
114
|
-
groupId: string;
|
|
115
|
-
sectionId: string;
|
|
116
|
-
value: number;
|
|
117
|
-
index: number;
|
|
118
|
-
label: string;
|
|
119
|
-
measurementIndex: number;
|
|
120
|
-
unit: Units;
|
|
121
|
-
}
|
|
122
|
-
export declare enum Units {
|
|
123
|
-
Centimeters = "cm",
|
|
124
|
-
Millimeters = "mm",
|
|
125
|
-
Meters = "m",
|
|
126
|
-
Inches = "in",
|
|
127
|
-
FractionalInches = "in_frac",
|
|
128
|
-
Feet = "ft",
|
|
129
|
-
FeetInchesDecimal = "ft_in_decimal",
|
|
130
|
-
FeetInchesFractional = "ft_in_frac"
|
|
131
|
-
}
|
|
132
|
-
export declare const convertUnitsToReadable: (targetUnit: Units) => "cm" | "mm" | "m" | "in" | "ft" | "in (fractional)" | "ft-in (decimal)" | "ft-in (fractional)" | null;
|
|
133
|
-
export declare enum FractionalTolerance {
|
|
134
|
-
Fourth = "4",
|
|
135
|
-
Eighth = "8",
|
|
136
|
-
Sixteenth = "16",
|
|
137
|
-
ThirtySecond = "32",
|
|
138
|
-
SixtyFourth = "64",
|
|
139
|
-
OneTwentyEighth = "128"
|
|
140
|
-
}
|
|
141
|
-
export declare enum DecimalTolerance {
|
|
142
|
-
Half = "0.5",
|
|
143
|
-
Tenth = "0.1",
|
|
144
|
-
Hundredth = "0.01",
|
|
145
|
-
Thousandth = "0.001"
|
|
146
|
-
}
|
|
147
|
-
export interface UserDocument extends FirestoreDoc, Timestamps {
|
|
148
|
-
defaultOrganization: string;
|
|
149
|
-
displayName: string;
|
|
150
|
-
email: string;
|
|
151
|
-
firstName: string;
|
|
152
|
-
lastName: string;
|
|
153
|
-
defaultUnit: Units;
|
|
154
|
-
decimalTolerance: DecimalTolerance;
|
|
155
|
-
fractionalTolerance: FractionalTolerance;
|
|
156
|
-
showWizard: boolean;
|
|
157
|
-
printLabelSize: string;
|
|
158
|
-
}
|
|
159
|
-
export {};
|
package/dist/types/firestore.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
;
|
|
2
|
-
export var OrganizationRole;
|
|
3
|
-
(function (OrganizationRole) {
|
|
4
|
-
OrganizationRole["Admin"] = "admin";
|
|
5
|
-
OrganizationRole["Member"] = "member";
|
|
6
|
-
})(OrganizationRole || (OrganizationRole = {}));
|
|
7
|
-
export var InvitationStatus;
|
|
8
|
-
(function (InvitationStatus) {
|
|
9
|
-
InvitationStatus["Pending"] = "pending";
|
|
10
|
-
InvitationStatus["Accepted"] = "accepted";
|
|
11
|
-
})(InvitationStatus || (InvitationStatus = {}));
|
|
12
|
-
;
|
|
13
|
-
;
|
|
14
|
-
export var FolderType;
|
|
15
|
-
(function (FolderType) {
|
|
16
|
-
FolderType["Project"] = "project";
|
|
17
|
-
FolderType["Job"] = "job";
|
|
18
|
-
})(FolderType || (FolderType = {}));
|
|
19
|
-
export var ColumnType;
|
|
20
|
-
(function (ColumnType) {
|
|
21
|
-
ColumnType["Text"] = "text";
|
|
22
|
-
ColumnType["Number"] = "number";
|
|
23
|
-
ColumnType["Measurement"] = "measurement";
|
|
24
|
-
ColumnType["Boolean"] = "boolean";
|
|
25
|
-
ColumnType["Formula"] = "formula";
|
|
26
|
-
})(ColumnType || (ColumnType = {}));
|
|
27
|
-
export var Units;
|
|
28
|
-
(function (Units) {
|
|
29
|
-
Units["Centimeters"] = "cm";
|
|
30
|
-
Units["Millimeters"] = "mm";
|
|
31
|
-
Units["Meters"] = "m";
|
|
32
|
-
Units["Inches"] = "in";
|
|
33
|
-
Units["FractionalInches"] = "in_frac";
|
|
34
|
-
Units["Feet"] = "ft";
|
|
35
|
-
Units["FeetInchesDecimal"] = "ft_in_decimal";
|
|
36
|
-
Units["FeetInchesFractional"] = "ft_in_frac";
|
|
37
|
-
})(Units || (Units = {}));
|
|
38
|
-
export const convertUnitsToReadable = (targetUnit) => {
|
|
39
|
-
switch (targetUnit) {
|
|
40
|
-
case Units.Meters:
|
|
41
|
-
return 'm';
|
|
42
|
-
case Units.Millimeters:
|
|
43
|
-
return 'mm';
|
|
44
|
-
case Units.Centimeters:
|
|
45
|
-
return 'cm';
|
|
46
|
-
case Units.Feet:
|
|
47
|
-
return 'ft';
|
|
48
|
-
case Units.FractionalInches:
|
|
49
|
-
return 'in (fractional)';
|
|
50
|
-
case Units.Inches:
|
|
51
|
-
return 'in';
|
|
52
|
-
case Units.FeetInchesDecimal:
|
|
53
|
-
return 'ft-in (decimal)';
|
|
54
|
-
case Units.FeetInchesFractional:
|
|
55
|
-
return 'ft-in (fractional)';
|
|
56
|
-
default:
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
export var FractionalTolerance;
|
|
61
|
-
(function (FractionalTolerance) {
|
|
62
|
-
FractionalTolerance["Fourth"] = "4";
|
|
63
|
-
FractionalTolerance["Eighth"] = "8";
|
|
64
|
-
FractionalTolerance["Sixteenth"] = "16";
|
|
65
|
-
FractionalTolerance["ThirtySecond"] = "32";
|
|
66
|
-
FractionalTolerance["SixtyFourth"] = "64";
|
|
67
|
-
FractionalTolerance["OneTwentyEighth"] = "128";
|
|
68
|
-
})(FractionalTolerance || (FractionalTolerance = {}));
|
|
69
|
-
export var DecimalTolerance;
|
|
70
|
-
(function (DecimalTolerance) {
|
|
71
|
-
DecimalTolerance["Half"] = "0.5";
|
|
72
|
-
DecimalTolerance["Tenth"] = "0.1";
|
|
73
|
-
DecimalTolerance["Hundredth"] = "0.01";
|
|
74
|
-
DecimalTolerance["Thousandth"] = "0.001";
|
|
75
|
-
})(DecimalTolerance || (DecimalTolerance = {}));
|
|
76
|
-
;
|
|
77
|
-
//# sourceMappingURL=firestore.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"firestore.js","sourceRoot":"","sources":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,KAAK,CAAC,gBAAgB;YACzB,OAAO,iBAAiB,CAAC;QAC3B,KAAK,KAAK,CAAC,MAAM;YACf,OAAO,IAAI,CAAC;QACd,KAAK,KAAK,CAAC,iBAAiB;YAC1B,OAAO,iBAAiB,CAAC;QAC3B,KAAK,KAAK,CAAC,oBAAoB;YAC7B,OAAO,oBAAoB,CAAC;QAC9B;YACE,OAAO,IAAI,CAAC;IAChB,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAN,IAAY,mBAOX;AAPD,WAAY,mBAAmB;IAC7B,mCAAY,CAAA;IACZ,mCAAY,CAAA;IACZ,uCAAgB,CAAA;IAChB,0CAAmB,CAAA;IACnB,yCAAkB,CAAA;IAClB,8CAAuB,CAAA;AACzB,CAAC,EAPW,mBAAmB,KAAnB,mBAAmB,QAO9B;AAED,MAAM,CAAN,IAAY,gBAKX;AALD,WAAY,gBAAgB;IAC1B,gCAAY,CAAA;IACZ,iCAAa,CAAA;IACb,sCAAkB,CAAA;IAClB,wCAAoB,CAAA;AACtB,CAAC,EALW,gBAAgB,KAAhB,gBAAgB,QAK3B;AAaA,CAAC"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
type MeasurementMap = Map<string, {
|
|
2
|
-
id: string;
|
|
3
|
-
value: number;
|
|
4
|
-
}[]>;
|
|
5
|
-
interface FormulaEvaluationOptions {
|
|
6
|
-
expression: string;
|
|
7
|
-
mappings: Record<string, string>;
|
|
8
|
-
group: {
|
|
9
|
-
id: string;
|
|
10
|
-
columns: Map<string, any>;
|
|
11
|
-
};
|
|
12
|
-
columns: {
|
|
13
|
-
id: string;
|
|
14
|
-
type: string;
|
|
15
|
-
}[];
|
|
16
|
-
measurementMap: MeasurementMap;
|
|
17
|
-
defaultUnit?: string;
|
|
18
|
-
}
|
|
19
|
-
export declare function evaluateFormula({ expression, mappings, group, columns, measurementMap, defaultUnit, }: FormulaEvaluationOptions): number | string;
|
|
20
|
-
export {};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { create, all } from 'mathjs';
|
|
2
|
-
const math = create(all);
|
|
3
|
-
export function evaluateFormula({ expression, mappings, group, columns, measurementMap, defaultUnit = 'um', }) {
|
|
4
|
-
const scope = {};
|
|
5
|
-
for (const [variable, columnId] of Object.entries(mappings)) {
|
|
6
|
-
const rawValue = group.columns.get(columnId);
|
|
7
|
-
const columnDef = columns.find((c) => c.id === columnId);
|
|
8
|
-
if (columnDef?.type === 'Measurement') {
|
|
9
|
-
const groupMeasurements = measurementMap.get(group.id) || [];
|
|
10
|
-
const measurement = groupMeasurements.find((m) => m.id === rawValue);
|
|
11
|
-
if (measurement?.value !== undefined) {
|
|
12
|
-
scope[variable] = math.unit(measurement.value, defaultUnit);
|
|
13
|
-
continue;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
const parsedValue = typeof rawValue === 'number' ? rawValue : parseFloat(rawValue || '');
|
|
17
|
-
scope[variable] = isNaN(parsedValue) ? 0 : parsedValue;
|
|
18
|
-
}
|
|
19
|
-
try {
|
|
20
|
-
const compiled = math.compile(expression);
|
|
21
|
-
const result = compiled.evaluate(scope);
|
|
22
|
-
if (math.typeOf(result) === 'Unit') {
|
|
23
|
-
return result.toNumber(defaultUnit);
|
|
24
|
-
}
|
|
25
|
-
return result;
|
|
26
|
-
}
|
|
27
|
-
catch (err) {
|
|
28
|
-
console.error(`Formula evaluation failed:`, err);
|
|
29
|
-
return 'Error';
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=evaluateFormula.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"evaluateFormula.js","sourceRoot":"","sources":["../../src/utils/evaluateFormula.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,GAAG,EAAQ,MAAM,QAAQ,CAAC;AAE3C,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;AAazB,MAAM,UAAU,eAAe,CAAC,EAC9B,UAAU,EACV,QAA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,MAAM,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAExC,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,MAAM,EAAE,CAAC;YACnC,OAAO,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;QACtC,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAAC;QACjD,OAAO,OAAO,CAAC;IACjB,CAAC;AACH,CAAC"}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { DecimalTolerance, FractionalTolerance, Units } from '../index';
|
|
2
|
-
export declare const convertMicrometers: (micrometers: number, unit: Units, fractionalTolerance: FractionalTolerance, decimalTolerance: DecimalTolerance) => {
|
|
3
|
-
value: string;
|
|
4
|
-
unit: string | null;
|
|
5
|
-
};
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { convertUnitsToReadable, Units } from '../index';
|
|
2
|
-
import { create, all } from 'mathjs';
|
|
3
|
-
const math = create(all);
|
|
4
|
-
export const convertMicrometers = (micrometers, unit, fractionalTolerance, decimalTolerance) => {
|
|
5
|
-
const converted = math.unit(micrometers, 'um');
|
|
6
|
-
let value = 0;
|
|
7
|
-
let displayUnit = '';
|
|
8
|
-
switch (unit) {
|
|
9
|
-
case Units.Inches:
|
|
10
|
-
case Units.FractionalInches: {
|
|
11
|
-
const inches = converted.toNumber('in');
|
|
12
|
-
displayUnit = 'in';
|
|
13
|
-
if (unit === Units.FractionalInches) {
|
|
14
|
-
const denominator = parseInt(fractionalTolerance, 10);
|
|
15
|
-
const whole = Math.floor(inches);
|
|
16
|
-
const fractional = inches - whole;
|
|
17
|
-
const numerator = Math.round(fractional * denominator);
|
|
18
|
-
value =
|
|
19
|
-
numerator === 0
|
|
20
|
-
? `${whole}`
|
|
21
|
-
: `${whole} ${numerator}/${denominator}`;
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
value = inches.toFixed(decimalTolerance.length - 2); // Match decimal places to tolerance
|
|
25
|
-
}
|
|
26
|
-
break;
|
|
27
|
-
}
|
|
28
|
-
case Units.Feet:
|
|
29
|
-
case Units.FeetInchesFractional:
|
|
30
|
-
case Units.FeetInchesDecimal: {
|
|
31
|
-
const feet = converted.toNumber('ft');
|
|
32
|
-
const wholeFeet = Math.floor(feet);
|
|
33
|
-
const fractionalFeet = feet - wholeFeet;
|
|
34
|
-
displayUnit = 'ft';
|
|
35
|
-
if (unit === Units.FeetInchesFractional) {
|
|
36
|
-
const inches = fractionalFeet * 12;
|
|
37
|
-
const wholeInches = Math.floor(inches);
|
|
38
|
-
const fractional = inches - wholeInches;
|
|
39
|
-
const denominator = parseInt(fractionalTolerance, 10);
|
|
40
|
-
const numerator = Math.round(fractional * denominator);
|
|
41
|
-
value =
|
|
42
|
-
numerator === 0
|
|
43
|
-
? `${wholeFeet}' ${wholeInches}"`
|
|
44
|
-
: `${wholeFeet}' ${wholeInches} ${numerator}/${denominator}"`;
|
|
45
|
-
}
|
|
46
|
-
else if (unit === Units.FeetInchesDecimal) {
|
|
47
|
-
const inches = (fractionalFeet * 12).toFixed(decimalTolerance.length - 2);
|
|
48
|
-
value = `${wholeFeet}' ${inches}"`;
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
value = feet.toFixed(decimalTolerance.length - 2);
|
|
52
|
-
}
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
case Units.Meters:
|
|
56
|
-
case Units.Centimeters:
|
|
57
|
-
case Units.Millimeters: {
|
|
58
|
-
displayUnit = convertUnitsToReadable(unit);
|
|
59
|
-
value = converted.toNumber(unit).toFixed(decimalTolerance.length - 2);
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
62
|
-
default:
|
|
63
|
-
throw new Error('Unsupported unit');
|
|
64
|
-
}
|
|
65
|
-
return { value, unit: displayUnit };
|
|
66
|
-
};
|
|
67
|
-
//# sourceMappingURL=micrometersToUnit.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"micrometersToUnit.js","sourceRoot":"","sources":["../../src/utils/micrometersToUnit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAyC,KAAK,EAAE,MAAM,UAAU,CAAC;AAChG,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAErC,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;AAEzB,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,WAAmB,EACnB,IAAW,EACX,mBAAwC,EACxC,gBAAkC,EACM,EAAE;IAC1C,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;IAC/C,IAAI,KAAK,GAAoB,CAAC,CAAC;IAC/B,IAAI,WAAW,GAAkB,EAAE,CAAC;IAEpC,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,KAAK,CAAC,MAAM,CAAC;QAClB,KAAK,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC;YAC5B,MAAM,MAAM,GAAG,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACxC,WAAW,GAAG,IAAI,CAAC;YACnB,IAAI,IAAI,KAAK,KAAK,CAAC,gBAAgB,EAAE,CAAC;gBACpC,MAAM,WAAW,GAAG,QAAQ,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC;gBACtD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;gBACjC,MAAM,UAAU,GAAG,MAAM,GAAG,KAAK,CAAC;gBAClC,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG,WAAW,CAAC,CAAC;gBAEvD,KAAK;oBACH,SAAS,KAAK,CAAC;wBACb,CAAC,CAAC,GAAG,KAAK,EAAE;wBACZ,CAAC,CAAC,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gBAAgB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;gBAC1E,KAAK,GAAG,GAAG,SAAS,KAAK,MAAM,GAAG,CAAC;YACrC,CAAC;iBAAM,CAAC;gBACN,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YACpD,CAAC;YACD,MAAM;QACR,CAAC;QACD,KAAK,KAAK,CAAC,MAAM,CAAC;QAClB,KAAK,KAAK,CAAC,WAAW,CAAC;QACvB,KAAK,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;YACvB,WAAW,GAAG,sBAAsB,CAAC,IAAI,CAAC,CAAC;YAC3C,KAAK,GAAG,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YACtE,MAAM;QACR,CAAC;QACD;YACE,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACxC,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;AACtC,CAAC,CAAC"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { all, create } from 'mathjs';
|
|
2
|
-
const math = create(all);
|
|
3
|
-
export const parseMeasurement = (input, defaultUnit = 'mm') => {
|
|
4
|
-
try {
|
|
5
|
-
// Trim and normalize spaces
|
|
6
|
-
const normalizedInput = input.trim().replace(/\s+/g, ' ');
|
|
7
|
-
// Preprocess mixed fractions (e.g., "12 1/2" -> "12 + 1/2")
|
|
8
|
-
const processedInput = normalizedInput.replace(/(\d+)\s+(\d+\/\d+)/g, '$1 + $2');
|
|
9
|
-
// Match numeric value and optional unit
|
|
10
|
-
const match = processedInput.match(/^([\d.+\-*/\s]+)\s*(\w+)?$/);
|
|
11
|
-
if (!match) {
|
|
12
|
-
throw new Error('Invalid input format');
|
|
13
|
-
}
|
|
14
|
-
const [_, value, unit] = match;
|
|
15
|
-
// Evaluate the numeric value (e.g., "12 + 1/2")
|
|
16
|
-
const numericValue = math.evaluate(value.trim());
|
|
17
|
-
// Use the provided unit or fallback to the default unit
|
|
18
|
-
const targetUnit = unit || defaultUnit;
|
|
19
|
-
// Convert to micrometers
|
|
20
|
-
return math.unit(numericValue, targetUnit).toNumber('um');
|
|
21
|
-
}
|
|
22
|
-
catch (err) {
|
|
23
|
-
if (err instanceof Error) {
|
|
24
|
-
console.error('Invalid measurement:', err.message);
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
console.error('An unknown error occurred:', err);
|
|
28
|
-
}
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
export const numberToLetterIndex = (index) => {
|
|
33
|
-
let result = '';
|
|
34
|
-
while (index > 0) {
|
|
35
|
-
index--; // Adjust for 0-based index
|
|
36
|
-
result = String.fromCharCode((index % 26) + 65) + result;
|
|
37
|
-
index = Math.floor(index / 26);
|
|
38
|
-
}
|
|
39
|
-
return result;
|
|
40
|
-
};
|
|
41
|
-
//# sourceMappingURL=parseMeasurement.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parseMeasurement.js","sourceRoot":"","sources":["../../src/utils/parseMeasurement.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;AAEzB,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,KAAa,EACb,cAAsB,IAAI,EACX,EAAE;IACjB,IAAI,CAAC;QACH,4BAA4B;QAC5B,MAAM,eAAe,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAE1D,4DAA4D;QAC5D,MAAM,cAAc,GAAG,eAAe,CAAC,OAAO,CAC5C,qBAAqB,EACrB,SAAS,CACV,CAAC;QAEF,wCAAwC;QACxC,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