decord/source/utils/NumberUtils.tsx

78 lines
2.4 KiB
TypeScript
Raw Normal View History

// Module ID: 1880
// Function ID: 1881
2026-07-20 16:05:17 +00:00
// Name: shortenAndLocalizeNumber
// Dependencies: [1114, 2]
2026-07-20 16:05:17 +00:00
// Exports: formatPercent, humanizeValue, parseInteger, shortenAndLocalizeNumber
// Module 1880 (shortenAndLocalizeNumber)
2026-08-24 06:08:38 +00:00
import set from "set" /* 2 */;
import getSystemLocale from "getSystemLocale" /* 1114 */;
2026-08-24 06:08:38 +00:00
2026-07-29 08:29:29 +00:00
let c2 = 1000000;
2026-08-24 06:08:38 +00:00
let result = set.fileFinishedImporting("utils/NumberUtils.tsx");
2026-07-20 16:05:17 +00:00
export const shortenAndLocalizeNumber = function shortenAndLocalizeNumber(count) {
2026-07-29 08:29:29 +00:00
if (count < c2) {
2026-08-24 06:08:38 +00:00
const intl2 = getSystemLocale.intl;
2026-07-29 08:29:29 +00:00
let obj = { value: null };
obj[0] = count;
2026-08-24 06:08:38 +00:00
return intl2.formatToPlainString(getSystemLocale.t.OiHat3, obj);
2026-07-20 16:05:17 +00:00
} else {
2026-07-29 08:29:29 +00:00
const result = count / tmp;
2026-08-24 06:08:38 +00:00
const intl = getSystemLocale.intl;
2026-07-29 08:29:29 +00:00
obj = { value: null };
obj[0] = result.toFixed(1);
2026-08-24 06:08:38 +00:00
return intl.formatToPlainString(getSystemLocale.t.Iku48I, obj);
2026-07-20 16:05:17 +00:00
}
};
export const humanizeValue = function humanizeValue(newPostCount, stateFromStores) {
if (newPostCount < 1000) {
2026-08-24 06:08:38 +00:00
const intl2 = getSystemLocale.intl;
2026-07-29 08:29:29 +00:00
let obj = { value: null };
2026-07-20 16:05:17 +00:00
const _Math2 = Math;
2026-07-29 08:29:29 +00:00
obj[0] = Math.floor(newPostCount);
2026-08-24 06:08:38 +00:00
return intl2.formatToPlainString(getSystemLocale.t.OiHat3, obj);
2026-07-29 08:29:29 +00:00
} else if (newPostCount < c2) {
2026-08-24 06:08:38 +00:00
const intl = getSystemLocale.intl;
2026-07-29 08:29:29 +00:00
obj = { value: null };
2026-07-20 16:05:17 +00:00
const _Math = Math;
2026-07-29 08:29:29 +00:00
obj[0] = Math.floor(newPostCount / 1000);
2026-08-24 06:08:38 +00:00
return intl.formatToPlainString(getSystemLocale.t["84R4Tc"], obj);
2026-07-20 16:05:17 +00:00
} else {
const _Math3 = Math;
const _Intl = Intl;
2026-07-29 08:29:29 +00:00
const result = Math.floor(10 * newPostCount / tmp7) / 10;
const numberFormat = new Intl.NumberFormat(stateFromStores, { maximumFractionDigits: 1 });
2026-08-24 06:08:38 +00:00
const intl3 = getSystemLocale.intl;
2026-07-29 08:29:29 +00:00
obj = { value: null };
obj[0] = numberFormat.format(result);
2026-08-24 06:08:38 +00:00
return intl3.formatToPlainString(getSystemLocale.t.Iku48I, obj);
2026-07-20 16:05:17 +00:00
}
};
export const parseInteger = function parseInteger(discriminator, arg1) {
2026-07-29 08:29:29 +00:00
let num = arg1;
2026-07-20 16:05:17 +00:00
if (arg1 === undefined) {
2026-07-29 08:29:29 +00:00
num = NaN;
2026-07-20 16:05:17 +00:00
}
if (null == discriminator) {
2026-07-29 08:29:29 +00:00
return num;
2026-07-20 16:05:17 +00:00
} else {
const _parseInt = parseInt;
let parsed = parseInt(discriminator);
const _Number = Number;
if (Number.isNaN(parsed)) {
2026-07-29 08:29:29 +00:00
parsed = num;
2026-07-20 16:05:17 +00:00
}
return parsed;
}
};
export const formatPercent = function formatPercent(arg0, arg1) {
let obj = arg2;
if (arg2 === undefined) {
obj = {};
}
2026-07-23 10:11:24 +00:00
obj = { style: "percent", minimumFractionDigits: 0 };
2026-07-20 16:05:17 +00:00
const merged = Object.assign(obj);
return Intl.NumberFormat(arg0, obj).format(arg1);
};