@intlify/core 11.4.7 → 11.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,21 +1,11 @@
1
1
  /*!
2
- * core v11.4.7
2
+ * core v11.4.9
3
3
  * (c) 2026 kazuya kawaguchi
4
4
  * Released under the MIT License.
5
5
  */
6
6
  var IntlifyCore = (function (exports) {
7
7
  'use strict';
8
8
 
9
- function warn(msg, err) {
10
- if (typeof console !== 'undefined') {
11
- console.warn(`[intlify] ` + msg);
12
- /* istanbul ignore if */
13
- if (err) {
14
- console.warn(err.stack);
15
- }
16
- }
17
- }
18
-
19
9
  /**
20
10
  * Original Utilities
21
11
  * written by kazuya kawaguchi
@@ -66,6 +56,86 @@ var IntlifyCore = (function (exports) {
66
56
  const assign = Object.assign;
67
57
  const _create = Object.create;
68
58
  const create = (obj = null) => _create(obj);
59
+ const hasOwnProperty = Object.prototype.hasOwnProperty;
60
+ function hasOwn(obj, key) {
61
+ return hasOwnProperty.call(obj, key);
62
+ }
63
+ /* eslint-enable */
64
+ /**
65
+ * Useful Utilities By Evan you
66
+ * Modified by kazuya kawaguchi
67
+ * MIT License
68
+ * https://github.com/vuejs/vue-next/blob/master/packages/shared/src/index.ts
69
+ * https://github.com/vuejs/vue-next/blob/master/packages/shared/src/codeframe.ts
70
+ */
71
+ const isArray = Array.isArray;
72
+ const isFunction = (val) => typeof val === 'function';
73
+ const isString = (val) => typeof val === 'string';
74
+ const isBoolean = (val) => typeof val === 'boolean';
75
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
76
+ const isObject = (val) => val !== null && typeof val === 'object';
77
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
78
+ const isPromise = (val) => {
79
+ return isObject(val) && isFunction(val.then) && isFunction(val.catch);
80
+ };
81
+ const objectToString = Object.prototype.toString;
82
+ const toTypeString = (value) => objectToString.call(value);
83
+ const isPlainObject = (val) => toTypeString(val) === '[object Object]';
84
+ // for converting list and named values to displayed strings.
85
+ const toDisplayString = (val) => {
86
+ return val == null
87
+ ? ''
88
+ : isArray(val) || (isPlainObject(val) && val.toString === objectToString)
89
+ ? JSON.stringify(val, null, 2)
90
+ : String(val);
91
+ };
92
+ function join(items, separator = '') {
93
+ return items.reduce((str, item, index) => (index === 0 ? str + item : str + separator + item), '');
94
+ }
95
+ const RANGE = 2;
96
+ function generateCodeFrame(source, start = 0, end = source.length) {
97
+ const lines = source.split(/\r?\n/);
98
+ let count = 0;
99
+ const res = [];
100
+ for (let i = 0; i < lines.length; i++) {
101
+ count += lines[i].length + 1;
102
+ if (count >= start) {
103
+ for (let j = i - RANGE; j <= i + RANGE || end > count; j++) {
104
+ if (j < 0 || j >= lines.length)
105
+ continue;
106
+ const line = j + 1;
107
+ res.push(`${line}${' '.repeat(3 - String(line).length)}| ${lines[j]}`);
108
+ const lineLength = lines[j].length;
109
+ if (j === i) {
110
+ // push underline
111
+ const pad = start - (count - lineLength) + 1;
112
+ const length = Math.max(1, end > count ? lineLength - pad : end - start);
113
+ res.push(` | ` + ' '.repeat(pad) + '^'.repeat(length));
114
+ }
115
+ else if (j > i) {
116
+ if (end > count) {
117
+ const length = Math.max(Math.min(end - count, lineLength), 1);
118
+ res.push(` | ` + '^'.repeat(length));
119
+ }
120
+ count += lineLength + 1;
121
+ }
122
+ }
123
+ break;
124
+ }
125
+ }
126
+ return res.join('\n');
127
+ }
128
+
129
+ function warn(msg, err) {
130
+ if (typeof console !== 'undefined') {
131
+ console.warn(`[intlify] ` + msg);
132
+ /* istanbul ignore if */
133
+ if (err) {
134
+ console.warn(err.stack);
135
+ }
136
+ }
137
+ }
138
+
69
139
  function escapeHtml(rawText) {
70
140
  return rawText
71
141
  .replace(/&/g, '&amp;') // escape `&` first to avoid double escaping
@@ -78,16 +148,37 @@ var IntlifyCore = (function (exports) {
78
148
  }
79
149
  function escapeAttributeValue(value) {
80
150
  return value
81
- .replace(/&(?![a-zA-Z0-9#]{2,6};)/g, '&amp;') // escape unescaped `&`
151
+ .replace(/&(?![a-z0-9#]{2,6};)/gi, '&amp;') // escape unescaped `&`
82
152
  .replace(/"/g, '&quot;')
83
153
  .replace(/'/g, '&apos;')
84
154
  .replace(/</g, '&lt;')
85
155
  .replace(/>/g, '&gt;');
86
156
  }
87
- const javascriptSchemePattern = /^\s*javascript\s*(?::|&#0*58;?|&#x0*3a;?|&colon;?)/i;
157
+ const javascriptSchemePattern = /^javascript:/i;
88
158
  const urlAttributePattern = /^(?:href|src|action|formaction)$/i;
159
+ const numericCharacterReferencePattern = /&#(?:x([0-9a-f]+)|(\d+));?/gi;
160
+ const namedWhitespaceCharacterReferencePattern = /&(?:Tab|NewLine);/g;
161
+ const colonCharacterReferencePattern = /&colon;?/gi;
162
+ // eslint-disable-next-line no-control-regex -- URL scheme normalization requires the full control range
163
+ const controlOrWhitespacePattern = /[\u0000-\u0020\u007f-\u009f]/g;
164
+ const eventHandlerPattern = /(?:^|[\s"'<>/])on\w+\s*=\s*["']?[^"'>]+["']?/i;
165
+ const eventHandlerAttributePattern = /(^|[\s"'<>/])on(\w+\s*=)/gi;
166
+ const unquotedUrlAttributePattern = /(^|[\s"'<>/])((?:href|src|action|formaction)\s*=\s*)([^\s"'=<>`]+)/gi;
167
+ function decodeNumericCharacterReference(match, hex, decimal) {
168
+ const digits = hex || decimal;
169
+ if (!digits) {
170
+ return match;
171
+ }
172
+ const codePoint = Number.parseInt(digits, hex ? 16 : 10);
173
+ return codePoint <= 0x7f ? String.fromCharCode(codePoint) : match;
174
+ }
89
175
  function hasJavascriptScheme(value) {
90
- return javascriptSchemePattern.test(value);
176
+ const normalized = value
177
+ .replace(numericCharacterReferencePattern, decodeNumericCharacterReference)
178
+ .replace(namedWhitespaceCharacterReferencePattern, '')
179
+ .replace(colonCharacterReferencePattern, ':')
180
+ .replace(controlOrWhitespacePattern, '');
181
+ return javascriptSchemePattern.test(normalized);
91
182
  }
92
183
  function sanitizeStyleValue(value) {
93
184
  const urlPattern = /url\s*\(/gi;
@@ -151,88 +242,18 @@ var IntlifyCore = (function (exports) {
151
242
  // Process attributes with single quotes
152
243
  html = html.replace(/([\w:-]+)\s*=\s*'([^']*)'/g, (_, attrName, attrValue) => `${attrName}='${sanitizeAttributeValue(attrName, attrValue)}'`);
153
244
  // Detect and neutralize event handler attributes
154
- const eventHandlerPattern = /\s*on\w+\s*=\s*["']?[^"'>]+["']?/gi;
155
245
  if (eventHandlerPattern.test(html)) {
156
246
  {
157
247
  warn('Potentially dangerous event handlers detected in translation. ' +
158
248
  'Consider removing onclick, onerror, etc. from your translation messages.');
159
249
  }
160
250
  // Neutralize event handler attributes by escaping 'on'
161
- html = html.replace(/(\s+)(on)(\w+\s*=)/gi, '$1&#111;n$3');
251
+ html = html.replace(eventHandlerAttributePattern, '$1&#111;n$2');
162
252
  }
163
253
  // Disable javascript: URLs in unquoted attributes
164
- html = html.replace(/(\s+(?:href|src|action|formaction)\s*=\s*)([^\s"'=<>`]+)/gi, (match, prefix, attrValue) => hasJavascriptScheme(attrValue) ? `${prefix}about:blank` : match);
254
+ html = html.replace(unquotedUrlAttributePattern, (match, boundary, prefix, attrValue) => hasJavascriptScheme(attrValue) ? `${boundary}${prefix}about:blank` : match);
165
255
  return html;
166
256
  }
167
- const hasOwnProperty = Object.prototype.hasOwnProperty;
168
- function hasOwn(obj, key) {
169
- return hasOwnProperty.call(obj, key);
170
- }
171
- /* eslint-enable */
172
- /**
173
- * Useful Utilities By Evan you
174
- * Modified by kazuya kawaguchi
175
- * MIT License
176
- * https://github.com/vuejs/vue-next/blob/master/packages/shared/src/index.ts
177
- * https://github.com/vuejs/vue-next/blob/master/packages/shared/src/codeframe.ts
178
- */
179
- const isArray = Array.isArray;
180
- const isFunction = (val) => typeof val === 'function';
181
- const isString = (val) => typeof val === 'string';
182
- const isBoolean = (val) => typeof val === 'boolean';
183
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
184
- const isObject = (val) => val !== null && typeof val === 'object';
185
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
186
- const isPromise = (val) => {
187
- return isObject(val) && isFunction(val.then) && isFunction(val.catch);
188
- };
189
- const objectToString = Object.prototype.toString;
190
- const toTypeString = (value) => objectToString.call(value);
191
- const isPlainObject = (val) => toTypeString(val) === '[object Object]';
192
- // for converting list and named values to displayed strings.
193
- const toDisplayString = (val) => {
194
- return val == null
195
- ? ''
196
- : isArray(val) || (isPlainObject(val) && val.toString === objectToString)
197
- ? JSON.stringify(val, null, 2)
198
- : String(val);
199
- };
200
- function join(items, separator = '') {
201
- return items.reduce((str, item, index) => (index === 0 ? str + item : str + separator + item), '');
202
- }
203
- const RANGE = 2;
204
- function generateCodeFrame(source, start = 0, end = source.length) {
205
- const lines = source.split(/\r?\n/);
206
- let count = 0;
207
- const res = [];
208
- for (let i = 0; i < lines.length; i++) {
209
- count += lines[i].length + 1;
210
- if (count >= start) {
211
- for (let j = i - RANGE; j <= i + RANGE || end > count; j++) {
212
- if (j < 0 || j >= lines.length)
213
- continue;
214
- const line = j + 1;
215
- res.push(`${line}${' '.repeat(3 - String(line).length)}| ${lines[j]}`);
216
- const lineLength = lines[j].length;
217
- if (j === i) {
218
- // push underline
219
- const pad = start - (count - lineLength) + 1;
220
- const length = Math.max(1, end > count ? lineLength - pad : end - start);
221
- res.push(` | ` + ' '.repeat(pad) + '^'.repeat(length));
222
- }
223
- else if (j > i) {
224
- if (end > count) {
225
- const length = Math.max(Math.min(end - count, lineLength), 1);
226
- res.push(` | ` + '^'.repeat(length));
227
- }
228
- count += lineLength + 1;
229
- }
230
- }
231
- break;
232
- }
233
- }
234
- return res.join('\n');
235
- }
236
257
 
237
258
  const CompileErrorCodes = {
238
259
  // tokenizer error codes
@@ -565,7 +586,7 @@ var IntlifyCore = (function (exports) {
565
586
  * @remarks
566
587
  * A fallback locale function implemented with a simple fallback algorithm.
567
588
  *
568
- * Basically, it returns the value as specified in the `fallbackLocale` props, and is processed with the fallback inside intlify.
589
+ * Basically, the chain consists of `start` plus the specified fallback: for a string or array `fallbackLocale`, the value as specified in the props is used; for a map `fallbackLocale`, the map's **keys** are used and the `default` key is skipped since it is not a locale name.
569
590
  *
570
591
  * @param ctx - A {@link CoreContext | context}
571
592
  * @param fallback - A {@link FallbackLocale | fallback locale}
@@ -582,7 +603,7 @@ var IntlifyCore = (function (exports) {
582
603
  ...(isArray(fallback)
583
604
  ? fallback
584
605
  : isObject(fallback)
585
- ? Object.keys(fallback)
606
+ ? Object.keys(fallback).filter(locale => locale !== 'default')
586
607
  : isString(fallback)
587
608
  ? [fallback]
588
609
  : [start])
@@ -610,29 +631,36 @@ var IntlifyCore = (function (exports) {
610
631
  if (!context.__localeChainCache) {
611
632
  context.__localeChainCache = new Map();
612
633
  }
613
- let chain = context.__localeChainCache.get(startLocale);
614
- if (!chain) {
615
- chain = [];
616
- // first block defined by start
617
- let block = [start];
618
- // while any intervening block found
619
- while (isArray(block)) {
620
- block = appendBlockToChain(chain, block, fallback);
621
- }
622
- // prettier-ignore
623
- // last block defined by default
624
- const defaults = isArray(fallback) || !isPlainObject(fallback)
625
- ? fallback
626
- : fallback['default']
627
- ? fallback['default']
628
- : null;
629
- // convert defaults to array
630
- block = isString(defaults) ? [defaults] : defaults;
631
- if (isArray(block)) {
632
- appendBlockToChain(chain, block, false);
633
- }
634
- context.__localeChainCache.set(startLocale, chain);
634
+ const fallbackKey = friendlyJSONstringify(fallback);
635
+ let chains = context.__localeChainCache.get(startLocale);
636
+ if (!chains) {
637
+ chains = new Map();
638
+ context.__localeChainCache.set(startLocale, chains);
639
+ }
640
+ const cached = chains.get(fallbackKey);
641
+ if (cached) {
642
+ return cached;
635
643
  }
644
+ const chain = [];
645
+ // first block defined by start
646
+ let block = [start];
647
+ // while any intervening block found
648
+ while (isArray(block)) {
649
+ block = appendBlockToChain(chain, block, fallback);
650
+ }
651
+ // prettier-ignore
652
+ // last block defined by default
653
+ const defaults = isArray(fallback) || !isPlainObject(fallback)
654
+ ? fallback
655
+ : fallback['default']
656
+ ? fallback['default']
657
+ : null;
658
+ // convert defaults to array
659
+ block = isString(defaults) ? [defaults] : defaults;
660
+ if (isArray(block)) {
661
+ appendBlockToChain(chain, block, false);
662
+ }
663
+ chains.set(fallbackKey, chain);
636
664
  return chain;
637
665
  }
638
666
  function appendBlockToChain(chain, block, blocks) {
@@ -991,7 +1019,7 @@ var IntlifyCore = (function (exports) {
991
1019
  * Intlify core-base version
992
1020
  * @internal
993
1021
  */
994
- const VERSION = '11.4.7';
1022
+ const VERSION = '11.4.9';
995
1023
  const NOT_REOSLVED = -1;
996
1024
  const DEFAULT_LOCALE = 'en-US';
997
1025
  const MISSING_RESOLVE_VALUE = '';
@@ -1238,6 +1266,88 @@ var IntlifyCore = (function (exports) {
1238
1266
  }
1239
1267
  /* eslint-enable @typescript-eslint/no-explicit-any */
1240
1268
 
1269
+ function resolveFormatLocale(context, key, locale, formats, missingWarn, fallbackWarn, type) {
1270
+ const { fallbackLocale, localeFallbacker, onWarn } = context;
1271
+ const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
1272
+ fallbackLocale, locale);
1273
+ let from = locale;
1274
+ for (let i = 0; i < locales.length; i++) {
1275
+ const targetLocale = locales[i];
1276
+ if (locale !== targetLocale &&
1277
+ isTranslateFallbackWarn(fallbackWarn, key)) {
1278
+ onWarn(getWarnMessage(type === 'datetime format'
1279
+ ? CoreWarnCodes.FALLBACK_TO_DATE_FORMAT
1280
+ : CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT, {
1281
+ key,
1282
+ target: targetLocale
1283
+ }));
1284
+ }
1285
+ if (locale !== targetLocale) {
1286
+ const emitter = context.__v_emitter;
1287
+ if (emitter) {
1288
+ emitter.emit('fallback', {
1289
+ type,
1290
+ key,
1291
+ from,
1292
+ to: targetLocale,
1293
+ groupId: `${type}:${key}`
1294
+ });
1295
+ }
1296
+ }
1297
+ const format = (formats[targetLocale] || {})[key];
1298
+ if (isPlainObject(format) && isString(targetLocale)) {
1299
+ return targetLocale;
1300
+ }
1301
+ handleMissing(context, key, targetLocale, missingWarn, type);
1302
+ from = targetLocale;
1303
+ }
1304
+ return null;
1305
+ }
1306
+ function getFormatterCacheKey(locale, key, overrides) {
1307
+ let id = `${locale}__${key}`;
1308
+ if (isPlainObject(overrides) && !isEmptyObject(overrides)) {
1309
+ id = `${id}__${JSON.stringify(overrides)}`;
1310
+ }
1311
+ return id;
1312
+ }
1313
+ function clearFormatCache(formatters, locale, format) {
1314
+ for (const key in format) {
1315
+ const prefix = `${locale}__${key}`;
1316
+ for (const id of formatters.keys()) {
1317
+ if (id === prefix || id.startsWith(`${prefix}__`)) {
1318
+ formatters.delete(id);
1319
+ }
1320
+ }
1321
+ }
1322
+ }
1323
+ function parseFormatArgs(args, options, initialOverrides, optionsKeys) {
1324
+ const [, arg2, arg3, arg4] = args;
1325
+ let overrides = initialOverrides;
1326
+ if (isString(arg2)) {
1327
+ options.key = arg2;
1328
+ }
1329
+ else if (isPlainObject(arg2)) {
1330
+ Object.keys(arg2).forEach(key => {
1331
+ if (optionsKeys.includes(key)) {
1332
+ overrides[key] = arg2[key];
1333
+ }
1334
+ else {
1335
+ options[key] = arg2[key];
1336
+ }
1337
+ });
1338
+ }
1339
+ if (isString(arg3)) {
1340
+ options.locale = arg3;
1341
+ }
1342
+ else if (isPlainObject(arg3)) {
1343
+ overrides = arg3;
1344
+ }
1345
+ if (isPlainObject(arg4)) {
1346
+ overrides = arg4;
1347
+ }
1348
+ return overrides;
1349
+ }
1350
+
1241
1351
  const intlDefined = typeof Intl !== 'undefined';
1242
1352
  const Availabilities = {
1243
1353
  dateTimeFormat: intlDefined && typeof Intl.DateTimeFormat !== 'undefined',
@@ -1246,7 +1356,7 @@ var IntlifyCore = (function (exports) {
1246
1356
 
1247
1357
  // implementation of `datetime` function
1248
1358
  function datetime(context, ...args) {
1249
- const { datetimeFormats, unresolving, fallbackLocale, onWarn, localeFallbacker } = context;
1359
+ const { datetimeFormats, unresolving, onWarn } = context;
1250
1360
  const { __datetimeFormatters } = context;
1251
1361
  if (!Availabilities.dateTimeFormat) {
1252
1362
  onWarn(getWarnMessage(CoreWarnCodes.CANNOT_FORMAT_DATE));
@@ -1269,57 +1379,16 @@ var IntlifyCore = (function (exports) {
1269
1379
  : context.fallbackWarn;
1270
1380
  const part = !!options.part;
1271
1381
  const locale = getLocale(context, options);
1272
- const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
1273
- fallbackLocale, locale);
1274
1382
  if (!isString(key) || key === '') {
1275
1383
  const formatter = new Intl.DateTimeFormat(locale.replace(/!/g, ''), overrides);
1276
1384
  return !part ? formatter.format(value) : formatter.formatToParts(value);
1277
1385
  }
1278
- // resolve format
1279
- let datetimeFormat = {};
1280
- let targetLocale;
1281
- let format = null;
1282
- let from = locale;
1283
- let to = null;
1284
- const type = 'datetime format';
1285
- for (let i = 0; i < locales.length; i++) {
1286
- targetLocale = to = locales[i];
1287
- if (locale !== targetLocale &&
1288
- isTranslateFallbackWarn(fallbackWarn, key)) {
1289
- onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_DATE_FORMAT, {
1290
- key,
1291
- target: targetLocale
1292
- }));
1293
- }
1294
- // for vue-devtools timeline event
1295
- if (locale !== targetLocale) {
1296
- const emitter = context.__v_emitter;
1297
- if (emitter) {
1298
- emitter.emit('fallback', {
1299
- type,
1300
- key,
1301
- from,
1302
- to,
1303
- groupId: `${type}:${key}`
1304
- });
1305
- }
1306
- }
1307
- datetimeFormat =
1308
- datetimeFormats[targetLocale] || {};
1309
- format = datetimeFormat[key];
1310
- if (isPlainObject(format))
1311
- break;
1312
- handleMissing(context, key, targetLocale, missingWarn, type); // eslint-disable-line @typescript-eslint/no-explicit-any
1313
- from = to;
1314
- }
1315
- // checking format and target locale
1316
- if (!isPlainObject(format) || !isString(targetLocale)) {
1386
+ const targetLocale = resolveFormatLocale(context, key, locale, datetimeFormats, missingWarn, fallbackWarn, 'datetime format');
1387
+ if (!isString(targetLocale)) {
1317
1388
  return unresolving ? NOT_REOSLVED : key;
1318
1389
  }
1319
- let id = `${targetLocale}__${key}`;
1320
- if (!isEmptyObject(overrides)) {
1321
- id = `${id}__${JSON.stringify(overrides)}`;
1322
- }
1390
+ const format = datetimeFormats[targetLocale][key];
1391
+ const id = getFormatterCacheKey(targetLocale, key, overrides);
1323
1392
  let formatter = __datetimeFormatters.get(id);
1324
1393
  if (!formatter) {
1325
1394
  formatter = new Intl.DateTimeFormat(targetLocale, assign({}, format, overrides));
@@ -1352,9 +1421,9 @@ var IntlifyCore = (function (exports) {
1352
1421
  ];
1353
1422
  /** @internal */
1354
1423
  function parseDateTimeArgs(...args) {
1355
- const [arg1, arg2, arg3, arg4] = args;
1424
+ const [arg1] = args;
1356
1425
  const options = create();
1357
- let overrides = create();
1426
+ const initialOverrides = create();
1358
1427
  let value;
1359
1428
  if (isString(arg1)) {
1360
1429
  // Only allow ISO strings - other date formats are often supported,
@@ -1391,45 +1460,18 @@ var IntlifyCore = (function (exports) {
1391
1460
  else {
1392
1461
  throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
1393
1462
  }
1394
- if (isString(arg2)) {
1395
- options.key = arg2;
1396
- }
1397
- else if (isPlainObject(arg2)) {
1398
- Object.keys(arg2).forEach(key => {
1399
- if (DATETIME_FORMAT_OPTIONS_KEYS.includes(key)) {
1400
- overrides[key] = arg2[key];
1401
- }
1402
- else {
1403
- options[key] = arg2[key];
1404
- }
1405
- });
1406
- }
1407
- if (isString(arg3)) {
1408
- options.locale = arg3;
1409
- }
1410
- else if (isPlainObject(arg3)) {
1411
- overrides = arg3;
1412
- }
1413
- if (isPlainObject(arg4)) {
1414
- overrides = arg4;
1415
- }
1463
+ const overrides = parseFormatArgs(args, options, initialOverrides, DATETIME_FORMAT_OPTIONS_KEYS);
1416
1464
  return [options.key || '', value, options, overrides];
1417
1465
  }
1418
1466
  /** @internal */
1419
1467
  function clearDateTimeFormat(ctx, locale, format) {
1420
1468
  const context = ctx;
1421
- for (const key in format) {
1422
- const id = `${locale}__${key}`;
1423
- if (!context.__datetimeFormatters.has(id)) {
1424
- continue;
1425
- }
1426
- context.__datetimeFormatters.delete(id);
1427
- }
1469
+ clearFormatCache(context.__datetimeFormatters, locale, format);
1428
1470
  }
1429
1471
 
1430
1472
  // implementation of `number` function
1431
1473
  function number(context, ...args) {
1432
- const { numberFormats, unresolving, fallbackLocale, onWarn, localeFallbacker } = context;
1474
+ const { numberFormats, unresolving, onWarn } = context;
1433
1475
  const { __numberFormatters } = context;
1434
1476
  if (!Availabilities.numberFormat) {
1435
1477
  onWarn(getWarnMessage(CoreWarnCodes.CANNOT_FORMAT_NUMBER));
@@ -1452,57 +1494,16 @@ var IntlifyCore = (function (exports) {
1452
1494
  : context.fallbackWarn;
1453
1495
  const part = !!options.part;
1454
1496
  const locale = getLocale(context, options);
1455
- const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
1456
- fallbackLocale, locale);
1457
1497
  if (!isString(key) || key === '') {
1458
1498
  const formatter = new Intl.NumberFormat(locale.replace(/!/g, ''), overrides);
1459
1499
  return !part ? formatter.format(value) : formatter.formatToParts(value);
1460
1500
  }
1461
- // resolve format
1462
- let numberFormat = {};
1463
- let targetLocale;
1464
- let format = null;
1465
- let from = locale;
1466
- let to = null;
1467
- const type = 'number format';
1468
- for (let i = 0; i < locales.length; i++) {
1469
- targetLocale = to = locales[i];
1470
- if (locale !== targetLocale &&
1471
- isTranslateFallbackWarn(fallbackWarn, key)) {
1472
- onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT, {
1473
- key,
1474
- target: targetLocale
1475
- }));
1476
- }
1477
- // for vue-devtools timeline event
1478
- if (locale !== targetLocale) {
1479
- const emitter = context.__v_emitter;
1480
- if (emitter) {
1481
- emitter.emit('fallback', {
1482
- type,
1483
- key,
1484
- from,
1485
- to,
1486
- groupId: `${type}:${key}`
1487
- });
1488
- }
1489
- }
1490
- numberFormat =
1491
- numberFormats[targetLocale] || {};
1492
- format = numberFormat[key];
1493
- if (isPlainObject(format))
1494
- break;
1495
- handleMissing(context, key, targetLocale, missingWarn, type); // eslint-disable-line @typescript-eslint/no-explicit-any
1496
- from = to;
1497
- }
1498
- // checking format and target locale
1499
- if (!isPlainObject(format) || !isString(targetLocale)) {
1501
+ const targetLocale = resolveFormatLocale(context, key, locale, numberFormats, missingWarn, fallbackWarn, 'number format');
1502
+ if (!isString(targetLocale)) {
1500
1503
  return unresolving ? NOT_REOSLVED : key;
1501
1504
  }
1502
- let id = `${targetLocale}__${key}`;
1503
- if (!isEmptyObject(overrides)) {
1504
- id = `${id}__${JSON.stringify(overrides)}`;
1505
- }
1505
+ const format = numberFormats[targetLocale][key];
1506
+ const id = getFormatterCacheKey(targetLocale, key, overrides);
1506
1507
  let formatter = __numberFormatters.get(id);
1507
1508
  if (!formatter) {
1508
1509
  formatter = new Intl.NumberFormat(targetLocale, assign({}, format, overrides));
@@ -1535,47 +1536,20 @@ var IntlifyCore = (function (exports) {
1535
1536
  ];
1536
1537
  /** @internal */
1537
1538
  function parseNumberArgs(...args) {
1538
- const [arg1, arg2, arg3, arg4] = args;
1539
+ const [arg1] = args;
1539
1540
  const options = create();
1540
- let overrides = create();
1541
+ const initialOverrides = create();
1541
1542
  if (!isNumber(arg1)) {
1542
1543
  throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
1543
1544
  }
1544
1545
  const value = arg1;
1545
- if (isString(arg2)) {
1546
- options.key = arg2;
1547
- }
1548
- else if (isPlainObject(arg2)) {
1549
- Object.keys(arg2).forEach(key => {
1550
- if (NUMBER_FORMAT_OPTIONS_KEYS.includes(key)) {
1551
- overrides[key] = arg2[key];
1552
- }
1553
- else {
1554
- options[key] = arg2[key];
1555
- }
1556
- });
1557
- }
1558
- if (isString(arg3)) {
1559
- options.locale = arg3;
1560
- }
1561
- else if (isPlainObject(arg3)) {
1562
- overrides = arg3;
1563
- }
1564
- if (isPlainObject(arg4)) {
1565
- overrides = arg4;
1566
- }
1546
+ const overrides = parseFormatArgs(args, options, initialOverrides, NUMBER_FORMAT_OPTIONS_KEYS);
1567
1547
  return [options.key || '', value, options, overrides];
1568
1548
  }
1569
1549
  /** @internal */
1570
1550
  function clearNumberFormat(ctx, locale, format) {
1571
1551
  const context = ctx;
1572
- for (const key in format) {
1573
- const id = `${locale}__${key}`;
1574
- if (!context.__numberFormatters.has(id)) {
1575
- continue;
1576
- }
1577
- context.__numberFormatters.delete(id);
1578
- }
1552
+ clearFormatCache(context.__numberFormatters, locale, format);
1579
1553
  }
1580
1554
 
1581
1555
  const DEFAULT_MODIFIER = (str) => str;