igniteui-webcomponents
Version:
Ignite UI for Web Components is a complete library of UI components, giving you the ability to build modern web applications using encapsulation and the concept of reusable components in a dependency-free approach.
46 lines • 1.38 kB
JavaScript
const _cache = new Map();
function stringifyOptions(options) {
return Object.entries(options)
.map(([k, v]) => `${k}:${v}`)
.join('::');
}
function getFormatter(locale, options) {
const key = `${locale}#${stringifyOptions(options)}`;
if (!_cache.has(key)) {
_cache.set(key, new Intl.DateTimeFormat(locale, options));
}
return _cache.get(key);
}
class DateTimeFormatters {
_update(configuration) {
for (const [key, value] of Object.entries(configuration)) {
this._formatters.set(key, getFormatter(this._locale, value));
}
}
constructor(_locale, _configuration) {
this._locale = _locale;
this._configuration = _configuration;
this._formatters = new Map();
this._update(_configuration);
}
get(name) {
return this._formatters.get(name);
}
get configuration() {
return { ...this._configuration };
}
get locale() {
return this._locale;
}
set locale(value) {
this._locale = value;
this._update(this._configuration);
}
update(configuration) {
this._update(Object.assign(this._configuration, configuration));
}
}
export function createDateTimeFormatters(locale, configuration) {
return new DateTimeFormatters(locale, configuration);
}
//# sourceMappingURL=intl-formatters.js.map