🚧 Progress on workbench
This commit is contained in:
parent
1a8fe110f8
commit
158c19ae1d
101 changed files with 1222 additions and 200 deletions
|
@ -11,3 +11,4 @@ export { default as roundMmUp } from "./roundMmUp";
|
|||
export { default as sliderStep } from "./sliderStep";
|
||||
export { default as smallestImperialStep } from "./smallestImperialStep";
|
||||
export { default as storage } from "./storage";
|
||||
export { default as measurementAsMm } from "./measurementAsMm";
|
||||
|
|
25
packages/utils/src/measurementAsMm.js
Normal file
25
packages/utils/src/measurementAsMm.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
const measurementAsMm = (value, units = "metric") => {
|
||||
if (typeof value === "number")
|
||||
return value * (units === "imperial" ? 25.4 : 10);
|
||||
if (units === "metric") {
|
||||
value = Number(value);
|
||||
if (isNaN(value)) return false;
|
||||
return value * (units === "imperial" ? 25.4 : 10);
|
||||
} else {
|
||||
let chunks = value.split(" ");
|
||||
if (chunks.length === 1) {
|
||||
let val = chunks[0];
|
||||
if (!isNaN(Number(val))) return Number(val) * 25.4;
|
||||
else return imperialFractionToMm(val);
|
||||
} else if (chunks.length === 2) {
|
||||
let inches = Number(chunks[0]);
|
||||
if (isNaN(inches)) return false;
|
||||
let fraction = imperialFractionToMm(chunks[1]);
|
||||
if (fraction === false) return false;
|
||||
return inches * 25.4 + fraction;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
export default measurementAsMm;
|
Loading…
Add table
Add a link
Reference in a new issue