File: /var/www/innodrive/src/js/modules-legacy/utils.js
export const isMobile = () => document.documentElement.clientWidth <= 991;
export const isTablet = () => document.documentElement.clientWidth <= 992;
export const isDesktop = () => document.documentElement.clientWidth > 1024;
export const plural = (number, one, two, five) => {
let n = Math.abs(number);
n %= 100;
if (n >= 5 && n <= 20) {
return five;
}
n %= 10;
if (n === 1) {
return one;
}
if (n >= 2 && n <= 4) {
return two;
}
return five;
};
export const numberFormat = (number, decimals, decPoint, thousandsSep) => {
let i;
let j;
let kw;
let kd;
let km;
// input sanitation & defaults
if (isNaN(decimals = Math.abs(decimals))) {
decimals = 2;
}
if (decPoint === undefined) {
decPoint = ',';
}
if (thousandsSep === undefined) {
thousandsSep = '.';
}
i = parseInt(number = (+number || 0).toFixed(decimals)) + '';
if ((j = i.length) > 3) {
j = j % 3;
} else {
j = 0;
}
km = (j ? i.substr(0, j) + thousandsSep : '');
kw = i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + thousandsSep);
kd = (decimals ? decPoint + Math.abs(number - i).toFixed(decimals).replace(/-/, 0).slice(2) : '');
return km + kw + kd;
};