astro-ghostcms/.pnpm-store/v3/files/3b/f0d64a1e7f5737f214638c55c88...

34 lines
749 B
Plaintext
Raw Normal View History

2024-02-14 14:10:47 +00:00
function rotateFromString(value, defaultValue = 0) {
const units = value.replace(/^-?[0-9.]*/, "");
function cleanup(value2) {
while (value2 < 0) {
value2 += 4;
}
return value2 % 4;
}
if (units === "") {
const num = parseInt(value);
return isNaN(num) ? 0 : cleanup(num);
} else if (units !== value) {
let split = 0;
switch (units) {
case "%":
split = 25;
break;
case "deg":
split = 90;
}
if (split) {
let num = parseFloat(value.slice(0, value.length - units.length));
if (isNaN(num)) {
return 0;
}
num = num / split;
return num % 1 === 0 ? cleanup(num) : 0;
}
}
return defaultValue;
}
export { rotateFromString };