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