芝麻web文件管理V1.00
编辑当前文件:/home/freeclou/app.optimyar.com/backend/node_modules/intl-messageformat/lib/core.js
/* Copyright (c) 2014, Yahoo! Inc. All rights reserved. Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms. */ var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; import { parse } from 'intl-messageformat-parser'; import memoizeIntlConstructor from 'intl-format-cache'; import { formatToParts, } from './formatters'; // -- MessageFormat -------------------------------------------------------- function mergeConfig(c1, c2) { if (!c2) { return c1; } return __assign(__assign(__assign({}, (c1 || {})), (c2 || {})), Object.keys(c1).reduce(function (all, k) { all[k] = __assign(__assign({}, c1[k]), (c2[k] || {})); return all; }, {})); } function mergeConfigs(defaultConfig, configs) { if (!configs) { return defaultConfig; } return Object.keys(defaultConfig).reduce(function (all, k) { all[k] = mergeConfig(defaultConfig[k], configs[k]); return all; }, __assign({}, defaultConfig)); } export function createDefaultFormatters(cache) { if (cache === void 0) { cache = { number: {}, dateTime: {}, pluralRules: {}, }; } return { getNumberFormat: memoizeIntlConstructor(Intl.NumberFormat, cache.number), getDateTimeFormat: memoizeIntlConstructor(Intl.DateTimeFormat, cache.dateTime), getPluralRules: memoizeIntlConstructor(Intl.PluralRules, cache.pluralRules), }; } var IntlMessageFormat = /** @class */ (function () { function IntlMessageFormat(message, locales, overrideFormats, opts) { var _this = this; if (locales === void 0) { locales = IntlMessageFormat.defaultLocale; } this.formatterCache = { number: {}, dateTime: {}, pluralRules: {}, }; this.format = function (values) { var parts = _this.formatToParts(values); // Hot path for straight simple msg translations if (parts.length === 1) { return parts[0].value; } var result = parts.reduce(function (all, part) { if (!all.length || part.type !== 0 /* literal */ || typeof all[all.length - 1] !== 'string') { all.push(part.value); } else { all[all.length - 1] += part.value; } return all; }, []); if (result.length <= 1) { return result[0] || ''; } return result; }; this.formatToParts = function (values) { return formatToParts(_this.ast, _this.locales, _this.formatters, _this.formats, values, undefined, _this.message); }; this.resolvedOptions = function () { return ({ locale: Intl.NumberFormat.supportedLocalesOf(_this.locales)[0], }); }; this.getAst = function () { return _this.ast; }; if (typeof message === 'string') { this.message = message; if (!IntlMessageFormat.__parse) { throw new TypeError('IntlMessageFormat.__parse must be set to process `message` of type `string`'); } // Parse string messages into an AST. this.ast = IntlMessageFormat.__parse(message, { normalizeHashtagInPlural: false, ignoreTag: opts === null || opts === void 0 ? void 0 : opts.ignoreTag, }); } else { this.ast = message; } if (!Array.isArray(this.ast)) { throw new TypeError('A message must be provided as a String or AST.'); } // Creates a new object with the specified `formats` merged with the default // formats. this.formats = mergeConfigs(IntlMessageFormat.formats, overrideFormats); // Defined first because it's used to build the format pattern. this.locales = locales; this.formatters = (opts && opts.formatters) || createDefaultFormatters(this.formatterCache); } Object.defineProperty(IntlMessageFormat, "defaultLocale", { get: function () { if (!IntlMessageFormat.memoizedDefaultLocale) { IntlMessageFormat.memoizedDefaultLocale = new Intl.NumberFormat().resolvedOptions().locale; } return IntlMessageFormat.memoizedDefaultLocale; }, enumerable: true, configurable: true }); IntlMessageFormat.memoizedDefaultLocale = null; IntlMessageFormat.__parse = parse; // Default format options used as the prototype of the `formats` provided to the // constructor. These are used when constructing the internal Intl.NumberFormat // and Intl.DateTimeFormat instances. IntlMessageFormat.formats = { number: { currency: { style: 'currency', }, percent: { style: 'percent', }, }, date: { short: { month: 'numeric', day: 'numeric', year: '2-digit', }, medium: { month: 'short', day: 'numeric', year: 'numeric', }, long: { month: 'long', day: 'numeric', year: 'numeric', }, full: { weekday: 'long', month: 'long', day: 'numeric', year: 'numeric', }, }, time: { short: { hour: 'numeric', minute: 'numeric', }, medium: { hour: 'numeric', minute: 'numeric', second: 'numeric', }, long: { hour: 'numeric', minute: 'numeric', second: 'numeric', timeZoneName: 'short', }, full: { hour: 'numeric', minute: 'numeric', second: 'numeric', timeZoneName: 'short', }, }, }; return IntlMessageFormat; }()); export { IntlMessageFormat }; export default IntlMessageFormat; //# sourceMappingURL=core.js.map