refactor(es modules): migrate numberUtils

This commit is contained in:
Azgaar 2022-06-26 02:11:36 +03:00
parent b425a9daf6
commit ad252b54e6
63 changed files with 97 additions and 56 deletions

21
src/utils/numberUtils.ts Normal file
View file

@ -0,0 +1,21 @@
// round value to d decimals
export function rn(value: number, decimals: number = 0) {
const multiplier = Math.pow(10, decimals);
return Math.round(value * multiplier) / multiplier;
}
export function minmax(value: number, min: number, max: number) {
return Math.min(Math.max(value, min), max);
}
// return value clamped to [0, 100]
export function lim(value: number) {
return minmax(value, 0, 100);
}
// normalization function
export function normalize(val: number, min: number, max: number) {
return minmax((val - min) / (max - min), 0, 1);
}
// import {rn, minmax, lim, normalize} from '/src/utils/numberUtils';