@bitrix24/b24jssdk
Version:
Bitrix24 REST API JavaScript SDK
65 lines (62 loc) • 1.86 kB
JavaScript
/**
* @package @bitrix24/b24jssdk
* @version 1.0.3
* @copyright (c) 2026 Bitrix24
* @license MIT
* @see https://github.com/bitrix24/b24jssdk
* @see https://bitrix24.github.io/b24jssdk/
*/
import { Type } from '../type.mjs';
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
class FormatterNumbers {
static {
__name(this, "FormatterNumbers");
}
static isInternalConstructing = false;
static instance = null;
_defLocale = null;
constructor() {
if (!FormatterNumbers.isInternalConstructing) {
throw new TypeError("FormatterNumber is not constructable");
}
FormatterNumbers.isInternalConstructing = false;
}
/**
* @return FormatterNumbers
*/
static getInstance() {
if (!FormatterNumbers.instance) {
FormatterNumbers.isInternalConstructing = true;
FormatterNumbers.instance = new FormatterNumbers();
}
return FormatterNumbers.instance;
}
setDefLocale(locale) {
this._defLocale = locale;
}
format(value, locale) {
let formatter;
if (typeof locale === "undefined" || !Type.isStringFilled(locale)) {
locale = Type.isStringFilled(this._defLocale) ? this._defLocale || "en" : typeof navigator === "undefined" ? "en" : navigator?.language || "en";
}
if (Number.isInteger(value)) {
formatter = new Intl.NumberFormat(locale, {
minimumFractionDigits: 0,
maximumFractionDigits: 0
});
} else {
formatter = new Intl.NumberFormat(locale, {
minimumFractionDigits: 2,
maximumFractionDigits: 2
});
}
let result = formatter.format(value);
if (locale.includes("ru")) {
result = result.replace(",", ".");
}
return result;
}
}
export { FormatterNumbers as default };
//# sourceMappingURL=numbers.mjs.map