@mikezimm/npmfunctions
Version:
Functions used in my SPFx webparts
75 lines • 3.41 kB
JavaScript
/**
* This was created to pass in screen ratios like 3440 / 1440 and get rounded value for comparison.
* You have to adjust the decimals depending on if it's landscape or portrait to be able to do a comparison.
* That way you can group screen sizes in buckets like 16 x 9 when the actual ratio is fractionally different
* @param num
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCommaSepLabel = exports.getCountLabel = exports.getSizeLabel = exports.round1decimals = exports.round2decimals = exports.round3decimals = exports.round4decimals = exports.round5decimals = exports.roundRatio = void 0;
function roundRatio(num) {
if (num < 1) {
return round3decimals(num);
}
else {
return round1decimals(num);
}
}
exports.roundRatio = roundRatio;
function round5decimals(num) {
return Math.round(num * 100000) / 100000;
}
exports.round5decimals = round5decimals;
function round4decimals(num) {
return Math.round(num * 10000) / 10000;
}
exports.round4decimals = round4decimals;
function round3decimals(num) {
return Math.round(num * 1000) / 1000;
}
exports.round3decimals = round3decimals;
function round2decimals(num) {
return Math.round(num * 100) / 100;
}
exports.round2decimals = round2decimals;
function round1decimals(num) {
return Math.round(num * 10) / 10;
}
exports.round1decimals = round1decimals;
/***
* d888b d88888b d888888b .d8888. d888888b d88888D d88888b db .d8b. d8888b. d88888b db
* 88' Y8b 88' `~~88~~' 88' YP `88' YP d8' 88' 88 d8' `8b 88 `8D 88' 88
* 88 88ooooo 88 `8bo. 88 d8' 88ooooo 88 88ooo88 88oooY' 88ooooo 88
* 88 ooo 88~~~~~ 88 `Y8b. 88 d8' 88~~~~~ 88 88~~~88 88~~~b. 88~~~~~ 88
* 88. ~8~ 88. 88 db 8D .88. d8' db 88. 88booo. 88 88 88 8D 88. 88booo.
* Y888P Y88888P YP `8888Y' Y888888P d88888P Y88888P Y88888P YP YP Y8888P' Y88888P Y88888P
*
* import { getSizeLabel } from '@mikezimm/npmfunctions/dist/Services/Strings/stringServices';
*/
function getSizeLabel(size, decimal) {
if (decimal === void 0) { decimal = 1; }
if (size === null || size === undefined) {
return '';
}
return size > 1e9 ? "".concat((size / 1e9).toFixed(decimal), " GB") : size > 1e6 ? "".concat((size / 1e6).toFixed(decimal), " MB") : size > 1e3 ? "".concat((size / 1e3).toFixed(decimal), " KB") : "".concat((size).toFixed(decimal), " B");
}
exports.getSizeLabel = getSizeLabel;
function getCountLabel(count, decimal) {
if (decimal === void 0) { decimal = 1; }
if (count === null || count === undefined) {
return '';
}
return count > 1e9 ? "".concat((count / 1e9).toFixed(decimal), " G") : count > 1e6 ? "".concat((count / 1e6).toFixed(decimal), " M") : count > 1e3 ? "".concat((count / 1e3).toFixed(decimal), " k") : "".concat((count).toFixed(decimal));
}
exports.getCountLabel = getCountLabel;
/**
* Returns string with 1000's separated format.
* For US: 1,000,000
* For EU: 1.000.000
* @param numb
*/
function getCommaSepLabel(numb) {
return new Intl.NumberFormat().format(numb);
}
exports.getCommaSepLabel = getCommaSepLabel;
//# sourceMappingURL=basicOperations.js.map
;