decord/alpha/source/utils/PriceUtils.tsx

112 lines
4.1 KiB
TypeScript
Raw Permalink Normal View History

2026-10-12 06:59:38 +00:00
// Module ID: 6940
// Function ID: 6941
// Name: PriceUtils
2026-10-12 06:59:38 +00:00
// Dependencies: [2129, 1392, 1096, 1382, 6941, 1126, 2]
2026-10-06 11:16:32 +00:00
// Exports: formatDualPriceForBG, formatPercent, formatPrice, formatRate, maybeShortenPrice, shortenAndFormatPrice
2026-07-20 16:05:17 +00:00
2026-10-12 06:59:38 +00:00
// Module 6940 (PriceUtils)
2026-10-03 08:58:59 +00:00
import Constants from "Constants" /* 1096 */;
import intl4 from "intl" /* 1126 */;
2026-10-09 10:00:15 +00:00
import PlatformUtils from "PlatformUtils" /* 1382 */;
import PremiumConstants from "PremiumConstants" /* 1392 */;
2026-10-12 06:59:38 +00:00
import utils_PriceUtils from "utils/PriceUtils" /* 6941 */;
2026-10-10 08:08:14 +00:00
import LocaleStore from "LocaleStore" /* 2129 */;
2026-10-03 08:58:59 +00:00
import size from "module_2" /* 2 */;
2026-07-23 10:11:24 +00:00
2026-07-20 16:05:17 +00:00
function formatSingleCurrencyPrice(result, BGN, localeOverride) {
2026-07-29 08:29:29 +00:00
let obj = localeOverride;
if (localeOverride == null) {
2026-07-20 16:05:17 +00:00
obj = {};
}
const obj2 = {};
2026-07-20 16:05:17 +00:00
const merged = Object.assign(obj);
localeOverride = undefined;
2026-07-29 08:29:29 +00:00
if (localeOverride != null) {
2026-07-20 16:05:17 +00:00
localeOverride = localeOverride.localeOverride;
}
2026-07-29 08:29:29 +00:00
if (localeOverride == null) {
localeOverride = LocaleStore.locale;
2026-07-20 16:05:17 +00:00
}
let isWindowsResult = "en-US" === localeOverride;
2026-10-06 11:16:32 +00:00
const hasItem = isWindowsResult && closure_5.includes(LocaleStore.systemLocale);
2026-07-20 16:05:17 +00:00
if (hasItem) {
obj2.currencyDisplay = "code";
2026-07-20 16:05:17 +00:00
}
if (isWindowsResult) {
2026-10-03 08:58:59 +00:00
const obj3 = PlatformUtils;
isWindowsResult = obj3.isWindows();
2026-07-20 16:05:17 +00:00
}
if (isWindowsResult) {
isWindowsResult = "en-GB" === LocaleStore.systemLocale;
2026-07-20 16:05:17 +00:00
}
if (isWindowsResult) {
obj2.currencyDisplay = "code";
2026-07-20 16:05:17 +00:00
}
2026-10-03 08:58:59 +00:00
const tmp11 = 0 === obj2.maximumFractionDigits && null == obj2.minimumFractionDigits;
2026-07-20 16:05:17 +00:00
if (tmp11) {
obj2.minimumFractionDigits = 0;
2026-07-20 16:05:17 +00:00
}
2026-10-03 08:58:59 +00:00
const obj4 = utils_PriceUtils;
return obj4.formatPrice(result, BGN, localeOverride, obj2);
2026-07-20 16:05:17 +00:00
}
2026-10-06 11:16:32 +00:00
const SubscriptionIntervalTypes = PremiumConstants.SubscriptionIntervalTypes;
const CurrencyCodes = Constants.CurrencyCodes;
let closure_5 = Object.freeze(["en-CA", "en-AU", "en-NZ"]);
const result = size.fileFinishedImporting("utils/PriceUtils.tsx");
export { formatSingleCurrencyPrice };
export const formatDualPriceForBG = function formatDualPriceForBG(result, localeOverride) {
const tmp = formatSingleCurrencyPrice(result, CurrencyCodes.EUR, localeOverride);
return "" + tmp + " (" + formatSingleCurrencyPrice(1.95583 * result, CurrencyCodes.BGN, localeOverride) + ")";
};
export const formatPrice = function formatPrice(amount, currency, localeOverride) {
return formatSingleCurrencyPrice(amount, currency, localeOverride);
};
export const formatRate = function formatRate(priceString, interval, intervalCount) {
2026-07-20 16:05:17 +00:00
if (interval === SubscriptionIntervalTypes.YEAR) {
2026-10-03 08:58:59 +00:00
const intl3 = intl4.intl;
const obj2 = { price: priceString };
2026-10-03 08:58:59 +00:00
return intl3.formatToPlainString(intl4.t["rS8FA+"], obj2);
2026-07-20 16:05:17 +00:00
} else {
2026-10-03 08:58:59 +00:00
if (interval === SubscriptionIntervalTypes.MONTH) {
2026-07-20 16:05:17 +00:00
if (1 === intervalCount) {
2026-10-03 08:58:59 +00:00
const intl2 = intl4.intl;
const obj3 = { price: priceString };
2026-10-03 08:58:59 +00:00
return intl2.formatToPlainString(intl4.t.AbOLNu, obj3);
2026-07-20 16:05:17 +00:00
}
}
2026-10-03 08:58:59 +00:00
if (interval === SubscriptionIntervalTypes.MONTH) {
2026-07-20 16:05:17 +00:00
if (intervalCount > 1) {
2026-10-03 08:58:59 +00:00
const intl = intl4.intl;
const obj = { price: priceString, intervalCount };
2026-10-03 08:58:59 +00:00
return intl.formatToPlainString(intl4.t["Qc+9ww"], obj);
2026-07-20 16:05:17 +00:00
}
}
const _Error = Error;
const _HermesInternal = HermesInternal;
2026-10-03 08:58:59 +00:00
const self = this;
const self2 = this;
const error = new Error("Unsupported interval type: " + interval + ", and interval count: " + intervalCount);
2026-07-20 16:05:17 +00:00
throw error;
}
2026-07-29 08:29:29 +00:00
};
2026-07-20 16:05:17 +00:00
export const formatPercent = function formatPercent(arg0, arg1) {
2026-10-03 08:58:59 +00:00
const NumberFormatResult = Intl.NumberFormat(arg0, { style: "percent", minimumFractionDigits: 0 });
return NumberFormatResult.format(arg1);
2026-07-20 16:05:17 +00:00
};
2026-07-29 08:29:29 +00:00
export const maybeShortenPrice = function maybeShortenPrice(str) {
let replaced = str;
if (str.length > 5) {
replaced = str.replace(/\.00(?=[\s)]|$)/g, "");
}
return replaced;
};
2026-07-20 16:05:17 +00:00
export const shortenAndFormatPrice = function shortenAndFormatPrice(amount, currency, localeOverride) {
2026-10-06 11:16:32 +00:00
const arr = formatSingleCurrencyPrice(amount, currency, localeOverride);
2026-07-29 08:29:29 +00:00
let replaced = arr;
if (arr.length > 5) {
replaced = arr.replace(/\.00(?=[\s)]|$)/g, "");
}
return replaced;
2026-07-20 16:05:17 +00:00
};