@reekon-tools/boldr-utils 1.0.1 → 1.0.2
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/dist/hooks/useParseMeasurement.d.ts +4 -0
- package/dist/hooks/useParseMeasurement.js +15 -0
- package/dist/hooks/useParseMeasurement.js.map +1 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +17 -20
- package/dist/index.js.map +1 -0
- package/dist/utils/parseMeasurement.d.ts +1 -0
- package/dist/utils/parseMeasurement.js +32 -0
- package/dist/utils/parseMeasurement.js.map +1 -0
- package/package.json +8 -1
|
@@ -0,0 +1,15 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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.d.ts
CHANGED
|
@@ -48,11 +48,15 @@ export interface Section {
|
|
|
48
48
|
name: string;
|
|
49
49
|
tableConfig: ColumnConfig[];
|
|
50
50
|
measurements: string[];
|
|
51
|
+
projectId: string;
|
|
52
|
+
jobId: string;
|
|
51
53
|
}
|
|
52
54
|
export interface Group {
|
|
53
55
|
id: string;
|
|
54
56
|
sectionId: string;
|
|
55
57
|
columns: Record<string, any>;
|
|
58
|
+
jobId: string;
|
|
59
|
+
projectId: string;
|
|
56
60
|
}
|
|
57
61
|
export interface ColumnConfig {
|
|
58
62
|
id: string;
|
|
@@ -80,7 +84,7 @@ export declare enum Units {
|
|
|
80
84
|
FeetInchesDecimal = "ft_in_decimal",
|
|
81
85
|
FeetInchesFractional = "ft_in_frac"
|
|
82
86
|
}
|
|
83
|
-
export declare const convertUnitsToReadable: (targetUnit: Units) => "cm" | "mm" | "m" | "in" | "ft" | "in (fractional)" | "ft-in (decimal)" | "ft-in (fractional)";
|
|
87
|
+
export declare const convertUnitsToReadable: (targetUnit: Units) => "cm" | "mm" | "m" | "in" | "ft" | "in (fractional)" | "ft-in (decimal)" | "ft-in (fractional)" | null;
|
|
84
88
|
export interface Measurement {
|
|
85
89
|
type: MeasurementType;
|
|
86
90
|
id: string;
|
package/dist/index.js
CHANGED
|
@@ -1,27 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DecimalTolerance = exports.FractionalTolerance = exports.convertUnitsToReadable = exports.Units = exports.MeasurementType = exports.ColumnType = exports.InvitationStatus = exports.OrganizationRole = void 0;
|
|
4
|
-
var OrganizationRole;
|
|
1
|
+
export var OrganizationRole;
|
|
5
2
|
(function (OrganizationRole) {
|
|
6
3
|
OrganizationRole["Owner"] = "owner";
|
|
7
4
|
OrganizationRole["Editor"] = "editor";
|
|
8
|
-
})(OrganizationRole || (
|
|
9
|
-
var InvitationStatus;
|
|
5
|
+
})(OrganizationRole || (OrganizationRole = {}));
|
|
6
|
+
export var InvitationStatus;
|
|
10
7
|
(function (InvitationStatus) {
|
|
11
8
|
InvitationStatus["Pending"] = "pending";
|
|
12
9
|
InvitationStatus["Accepted"] = "accepted";
|
|
13
|
-
})(InvitationStatus || (
|
|
14
|
-
var ColumnType;
|
|
10
|
+
})(InvitationStatus || (InvitationStatus = {}));
|
|
11
|
+
export var ColumnType;
|
|
15
12
|
(function (ColumnType) {
|
|
16
13
|
ColumnType["Text"] = "text";
|
|
17
14
|
ColumnType["Number"] = "number";
|
|
18
15
|
ColumnType["Measurement"] = "measurement";
|
|
19
16
|
ColumnType["Boolean"] = "boolean";
|
|
20
|
-
})(ColumnType || (
|
|
21
|
-
var MeasurementType;
|
|
17
|
+
})(ColumnType || (ColumnType = {}));
|
|
18
|
+
export var MeasurementType;
|
|
22
19
|
(function (MeasurementType) {
|
|
23
|
-
})(MeasurementType || (
|
|
24
|
-
var Units;
|
|
20
|
+
})(MeasurementType || (MeasurementType = {}));
|
|
21
|
+
export var Units;
|
|
25
22
|
(function (Units) {
|
|
26
23
|
Units["Centimeters"] = "cm";
|
|
27
24
|
Units["Millimeters"] = "mm";
|
|
@@ -31,8 +28,8 @@ var Units;
|
|
|
31
28
|
Units["Feet"] = "ft";
|
|
32
29
|
Units["FeetInchesDecimal"] = "ft_in_decimal";
|
|
33
30
|
Units["FeetInchesFractional"] = "ft_in_frac";
|
|
34
|
-
})(Units || (
|
|
35
|
-
const convertUnitsToReadable = (targetUnit) => {
|
|
31
|
+
})(Units || (Units = {}));
|
|
32
|
+
export const convertUnitsToReadable = (targetUnit) => {
|
|
36
33
|
switch (targetUnit) {
|
|
37
34
|
case Units.Meters:
|
|
38
35
|
return 'm';
|
|
@@ -51,11 +48,10 @@ const convertUnitsToReadable = (targetUnit) => {
|
|
|
51
48
|
case Units.FeetInchesFractional:
|
|
52
49
|
return 'ft-in (fractional)';
|
|
53
50
|
default:
|
|
54
|
-
return
|
|
51
|
+
return null;
|
|
55
52
|
}
|
|
56
53
|
};
|
|
57
|
-
|
|
58
|
-
var FractionalTolerance;
|
|
54
|
+
export var FractionalTolerance;
|
|
59
55
|
(function (FractionalTolerance) {
|
|
60
56
|
FractionalTolerance["Fourth"] = "4";
|
|
61
57
|
FractionalTolerance["Eighth"] = "8";
|
|
@@ -63,11 +59,12 @@ var FractionalTolerance;
|
|
|
63
59
|
FractionalTolerance["ThirtySecond"] = "32";
|
|
64
60
|
FractionalTolerance["SixtyFourth"] = "64";
|
|
65
61
|
FractionalTolerance["OneTwentyEighth"] = "128";
|
|
66
|
-
})(FractionalTolerance || (
|
|
67
|
-
var DecimalTolerance;
|
|
62
|
+
})(FractionalTolerance || (FractionalTolerance = {}));
|
|
63
|
+
export var DecimalTolerance;
|
|
68
64
|
(function (DecimalTolerance) {
|
|
69
65
|
DecimalTolerance["Half"] = "0.5";
|
|
70
66
|
DecimalTolerance["Tenth"] = "0.1";
|
|
71
67
|
DecimalTolerance["Hundredth"] = "0.01";
|
|
72
68
|
DecimalTolerance["Thousandth"] = "0.001";
|
|
73
|
-
})(DecimalTolerance || (
|
|
69
|
+
})(DecimalTolerance || (DecimalTolerance = {}));
|
|
70
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAME,MAAM,CAAN,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,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AC,oBAAoB;YAC7B,OAAO,oBAAoB,CAAC;QAC9B;YACE,OAAO,IAAI,CAAC;IAChB,CAAC;AACH,CAAC,CAAC;AAcF,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const parseMeasurement: (input: string, defaultUnit?: string) => number | null;
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
//# sourceMappingURL=parseMeasurement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseMeasurement.js","sourceRoot":"","sources":["../../src/utils/parseMeasurement.ts"],"names":[],"mappings":"AACA,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,MAAM,KAAK,GAAG,cAAc,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAEjE,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;QAC1C,CAAC;QAED,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,KAAK,CAAC;QAE/B,gDAAgD;QAChD,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;QAEjD,wDAAwD;QACxD,MAAM,UAAU,GAAG,IAAI,IAAI,WAAW,CAAC;QAEvC,yBAAyB;QACzB,OAAO,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC5D,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,YAAY,KAAK,EAAE,CAAC;YACzB,OAAO,CAAC,KAAK,CAAC,sBAAsB,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;QACrD,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAAC;QACnD,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reekon-tools/boldr-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Shared utilities for Boldr projects in Reekon Tools",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -14,7 +14,14 @@
|
|
|
14
14
|
"author": "",
|
|
15
15
|
"license": "ISC",
|
|
16
16
|
"repository": "https://gitlab.com/reekon-tools/software/rock-pro/boldr-types#",
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"mathjs": "^11.11.0"
|
|
19
|
+
},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"react": "^18.0.0"
|
|
22
|
+
},
|
|
17
23
|
"devDependencies": {
|
|
24
|
+
"@types/react": "^19.0.8",
|
|
18
25
|
"typescript": "^5.7.3"
|
|
19
26
|
},
|
|
20
27
|
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|