@reekon-tools/boldr-utils 1.18.1 → 1.18.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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DecimalTolerance, FractionalTolerance, Units } from '../types/firestore.js';
|
|
2
2
|
export declare const roundToT1Values: (value: number, u: Units) => number;
|
|
3
|
-
export declare const convertMicrometers: (micrometers: number | null | undefined, unit: Units, fractionalTolerance
|
|
3
|
+
export declare const convertMicrometers: (micrometers: number | null | undefined, unit: Units, fractionalTolerance?: FractionalTolerance, decimalTolerance?: DecimalTolerance, device?: string) => {
|
|
4
4
|
value: string;
|
|
5
5
|
unit: string;
|
|
6
6
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Units, convertUnitsToReadable, } from '../types/firestore.js';
|
|
1
|
+
import { DecimalTolerance, FractionalTolerance, Units, convertUnitsToReadable, } from '../types/firestore.js';
|
|
2
2
|
import { create, all } from 'mathjs';
|
|
3
3
|
const math = create(all);
|
|
4
4
|
// The T1 rounds differently depending on the selected measurement unit.
|
|
@@ -45,12 +45,19 @@ const reduceFraction = (numerator, denominator) => {
|
|
|
45
45
|
* plain zero, not as a negative.
|
|
46
46
|
*/
|
|
47
47
|
const signPrefix = (signed, body) => signed < 0 && /[1-9]/.test(body) ? `-${body}` : body;
|
|
48
|
-
export const convertMicrometers = (micrometers, unit, fractionalTolerance, decimalTolerance) => {
|
|
48
|
+
export const convertMicrometers = (micrometers, unit, fractionalTolerance = FractionalTolerance.Sixteenth, decimalTolerance = DecimalTolerance.Hundredth, device) => {
|
|
49
49
|
if (micrometers == null || isNaN(micrometers)) {
|
|
50
50
|
return { value: 'NaN', unit: '' };
|
|
51
51
|
}
|
|
52
52
|
try {
|
|
53
|
-
|
|
53
|
+
// Only mirror T1 firmware rounding for values that actually came from a
|
|
54
|
+
// T1-family tape (T1, T1M, T1R). A manual entry, formula result, or Bosch
|
|
55
|
+
// reading was never snapped by firmware, so displaying it snapped would
|
|
56
|
+
// misreport the stored value.
|
|
57
|
+
const source = device?.includes('T1')
|
|
58
|
+
? roundToT1Values(micrometers, unit)
|
|
59
|
+
: micrometers;
|
|
60
|
+
const converted = math.unit(source, 'um');
|
|
54
61
|
let value = 0;
|
|
55
62
|
let displayUnit = '';
|
|
56
63
|
switch (unit) {
|