mirror of https://github.com/ghostfolio/ghostfolio
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
689 B
31 lines
689 B
/**
|
|
* Get rotation value
|
|
*/
|
|
function rotateFromString(value, defaultValue = 0) {
|
|
const units = value.replace(/^-?[0-9.]*/, "");
|
|
function cleanup(value$1) {
|
|
while (value$1 < 0) value$1 += 4;
|
|
return value$1 % 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 };
|