decord/source/utils/NumberUtils.tsx

73 lines
2.5 KiB
TypeScript
Raw Normal View History

2026-07-20 16:05:17 +00:00
// Module ID: 1827
2026-07-25 08:10:48 +00:00
// Function ID: 20026
2026-07-20 16:05:17 +00:00
// Name: shortenAndLocalizeNumber
2026-07-23 10:11:24 +00:00
// Dependencies: [1212, 2]
2026-07-20 16:05:17 +00:00
// Exports: formatPercent, humanizeValue, parseInteger, shortenAndLocalizeNumber
// Module 1827 (shortenAndLocalizeNumber)
2026-07-23 10:11:24 +00:00
let result = require("set").fileFinishedImporting("utils/NumberUtils.tsx");
2026-07-20 16:05:17 +00:00
export const shortenAndLocalizeNumber = function shortenAndLocalizeNumber(count) {
if (count < 1000000) {
2026-07-23 10:11:24 +00:00
const intl2 = require(1212) /* getSystemLocale */.intl;
2026-07-20 16:05:17 +00:00
let obj = { value: count };
2026-07-23 10:11:24 +00:00
return intl2.formatToPlainString(require(1212) /* getSystemLocale */.t.OiHat3, obj);
2026-07-20 16:05:17 +00:00
} else {
const result = count / 1000000;
2026-07-23 10:11:24 +00:00
const intl = require(1212) /* getSystemLocale */.intl;
2026-07-20 16:05:17 +00:00
obj = { value: result.toFixed(1) };
2026-07-23 10:11:24 +00:00
return intl.formatToPlainString(require(1212) /* getSystemLocale */.t.Iku48I, obj);
2026-07-20 16:05:17 +00:00
}
};
export const humanizeValue = function humanizeValue(newPostCount, stateFromStores) {
if (newPostCount < 1000) {
2026-07-23 10:11:24 +00:00
const intl2 = require(1212) /* getSystemLocale */.intl;
2026-07-20 16:05:17 +00:00
let obj = {};
const _Math2 = Math;
obj.value = Math.floor(newPostCount);
2026-07-23 10:11:24 +00:00
return intl2.formatToPlainString(require(1212) /* getSystemLocale */.t.OiHat3, obj);
2026-07-20 16:05:17 +00:00
} else if (newPostCount < 1000000) {
2026-07-23 10:11:24 +00:00
const intl = require(1212) /* getSystemLocale */.intl;
2026-07-20 16:05:17 +00:00
obj = {};
const _Math = Math;
obj.value = Math.floor(newPostCount / 1000);
2026-07-23 10:11:24 +00:00
return intl.formatToPlainString(require(1212) /* getSystemLocale */.t["84R4Tc"], obj);
2026-07-20 16:05:17 +00:00
} else {
const _Math3 = Math;
const _Intl = Intl;
obj = { maximumFractionDigits: 1 };
const prototype = NumberFormat.prototype;
const result = Math.floor(10 * newPostCount / 1000000) / 10;
const numberFormat = new NumberFormat(stateFromStores, obj);
2026-07-23 10:11:24 +00:00
const intl3 = require(1212) /* getSystemLocale */.intl;
2026-07-20 16:05:17 +00:00
const obj1 = { value: numberFormat.format(result) };
2026-07-23 10:11:24 +00:00
return intl3.formatToPlainString(require(1212) /* getSystemLocale */.t.Iku48I, obj1);
2026-07-20 16:05:17 +00:00
}
};
export const parseInteger = function parseInteger(discriminator, arg1) {
let _NaN = arg1;
if (arg1 === undefined) {
_NaN = NaN;
}
if (null == discriminator) {
return _NaN;
} else {
const _parseInt = parseInt;
let parsed = parseInt(discriminator);
const _Number = Number;
if (Number.isNaN(parsed)) {
parsed = _NaN;
}
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);
};