@intlify/core-base 9.2.0-beta.35 → 9.2.0-beta.38
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.
- package/dist/core-base.cjs.js +129 -20
- package/dist/core-base.cjs.prod.js +129 -20
- package/dist/core-base.d.ts +19 -8
- package/dist/core-base.esm-browser.js +158 -25
- package/dist/core-base.esm-browser.prod.js +2 -2
- package/dist/core-base.esm-bundler.js +129 -22
- package/dist/core-base.global.js +159 -24
- package/dist/core-base.global.prod.js +2 -2
- package/package.json +6 -6
package/dist/core-base.cjs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* core-base v9.2.0-beta.
|
|
2
|
+
* core-base v9.2.0-beta.38
|
|
3
3
|
* (c) 2022 kazuya kawaguchi
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -328,7 +328,9 @@ function createMessageContext(options = {}) {
|
|
|
328
328
|
shared.isFunction(options.pluralRules[locale])
|
|
329
329
|
? pluralDefault
|
|
330
330
|
: undefined;
|
|
331
|
-
const plural = (messages) =>
|
|
331
|
+
const plural = (messages) => {
|
|
332
|
+
return messages[pluralRule(pluralIndex, messages.length, orgPluralRule)];
|
|
333
|
+
};
|
|
332
334
|
const _list = options.list || [];
|
|
333
335
|
const list = (index) => _list[index];
|
|
334
336
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -358,13 +360,37 @@ function createMessageContext(options = {}) {
|
|
|
358
360
|
shared.isFunction(options.processor.interpolate)
|
|
359
361
|
? options.processor.interpolate
|
|
360
362
|
: DEFAULT_INTERPOLATE;
|
|
361
|
-
const linked = (key, modifier) => {
|
|
362
|
-
const msg = message(key)(ctx);
|
|
363
|
-
return shared.isString(modifier) ? _modifier(modifier)(msg) : msg;
|
|
364
|
-
};
|
|
365
363
|
const type = shared.isPlainObject(options.processor) && shared.isString(options.processor.type)
|
|
366
364
|
? options.processor.type
|
|
367
365
|
: DEFAULT_MESSAGE_DATA_TYPE;
|
|
366
|
+
const linked = (key, ...args) => {
|
|
367
|
+
const [arg1, arg2] = args;
|
|
368
|
+
let type = 'text';
|
|
369
|
+
let modifier = '';
|
|
370
|
+
if (args.length === 1) {
|
|
371
|
+
if (shared.isObject(arg1)) {
|
|
372
|
+
modifier = arg1.modifier || modifier;
|
|
373
|
+
type = arg1.type || type;
|
|
374
|
+
}
|
|
375
|
+
else if (shared.isString(arg1)) {
|
|
376
|
+
modifier = arg1 || modifier;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
else if (args.length === 2) {
|
|
380
|
+
if (shared.isString(arg1)) {
|
|
381
|
+
modifier = arg1 || modifier;
|
|
382
|
+
}
|
|
383
|
+
if (shared.isString(arg2)) {
|
|
384
|
+
type = arg2 || type;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
let msg = message(key)(ctx);
|
|
388
|
+
// The message in vnode resolved with linked are returned as an array by processor.nomalize
|
|
389
|
+
if (type === 'vnode' && shared.isArray(msg) && modifier) {
|
|
390
|
+
msg = msg[0];
|
|
391
|
+
}
|
|
392
|
+
return modifier ? _modifier(modifier)(msg, type) : msg;
|
|
393
|
+
};
|
|
368
394
|
const ctx = {
|
|
369
395
|
["list" /* LIST */]: list,
|
|
370
396
|
["named" /* NAMED */]: named,
|
|
@@ -543,18 +569,37 @@ function appendItemToChain(chain, target, blocks) {
|
|
|
543
569
|
* Intlify core-base version
|
|
544
570
|
* @internal
|
|
545
571
|
*/
|
|
546
|
-
const VERSION = '9.2.0-beta.
|
|
572
|
+
const VERSION = '9.2.0-beta.38';
|
|
547
573
|
const NOT_REOSLVED = -1;
|
|
548
574
|
const DEFAULT_LOCALE = 'en-US';
|
|
549
575
|
const MISSING_RESOLVE_VALUE = '';
|
|
576
|
+
const capitalize = (str) => `${str.charAt(0).toLocaleUpperCase()}${str.substr(1)}`;
|
|
550
577
|
function getDefaultLinkedModifiers() {
|
|
551
578
|
return {
|
|
552
|
-
upper: (val) =>
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
579
|
+
upper: (val, type) => {
|
|
580
|
+
// prettier-ignore
|
|
581
|
+
return type === 'text' && shared.isString(val)
|
|
582
|
+
? val.toUpperCase()
|
|
583
|
+
: type === 'vnode' && shared.isObject(val) && '__v_isVNode' in val
|
|
584
|
+
? val.children.toUpperCase()
|
|
585
|
+
: val;
|
|
586
|
+
},
|
|
587
|
+
lower: (val, type) => {
|
|
588
|
+
// prettier-ignore
|
|
589
|
+
return type === 'text' && shared.isString(val)
|
|
590
|
+
? val.toLowerCase()
|
|
591
|
+
: type === 'vnode' && shared.isObject(val) && '__v_isVNode' in val
|
|
592
|
+
? val.children.toLowerCase()
|
|
593
|
+
: val;
|
|
594
|
+
},
|
|
595
|
+
capitalize: (val, type) => {
|
|
596
|
+
// prettier-ignore
|
|
597
|
+
return (type === 'text' && shared.isString(val)
|
|
598
|
+
? capitalize(val)
|
|
599
|
+
: type === 'vnode' && shared.isObject(val) && '__v_isVNode' in val
|
|
600
|
+
? capitalize(val.children)
|
|
601
|
+
: val);
|
|
602
|
+
}
|
|
558
603
|
};
|
|
559
604
|
}
|
|
560
605
|
let _compiler;
|
|
@@ -890,7 +935,9 @@ function translate(context, ...args) {
|
|
|
890
935
|
const msgContext = createMessageContext(ctxOptions);
|
|
891
936
|
const messaged = evaluateMessage(context, msg, msgContext);
|
|
892
937
|
// if use post translation option, proceed it with handler
|
|
893
|
-
const ret = postTranslation
|
|
938
|
+
const ret = postTranslation
|
|
939
|
+
? postTranslation(messaged, key)
|
|
940
|
+
: messaged;
|
|
894
941
|
// NOTE: experimental !!
|
|
895
942
|
{
|
|
896
943
|
// prettier-ignore
|
|
@@ -1217,7 +1264,7 @@ function datetime(context, ...args) {
|
|
|
1217
1264
|
const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
1218
1265
|
fallbackLocale, locale);
|
|
1219
1266
|
if (!shared.isString(key) || key === '') {
|
|
1220
|
-
return new Intl.DateTimeFormat(locale).format(value);
|
|
1267
|
+
return new Intl.DateTimeFormat(locale, overrides).format(value);
|
|
1221
1268
|
}
|
|
1222
1269
|
// resolve format
|
|
1223
1270
|
let datetimeFormat = {};
|
|
@@ -1272,9 +1319,32 @@ function datetime(context, ...args) {
|
|
|
1272
1319
|
return !part ? formatter.format(value) : formatter.formatToParts(value);
|
|
1273
1320
|
}
|
|
1274
1321
|
/** @internal */
|
|
1322
|
+
const DATETIME_FORMAT_OPTIONS_KEYS = [
|
|
1323
|
+
'localeMatcher',
|
|
1324
|
+
'weekday',
|
|
1325
|
+
'era',
|
|
1326
|
+
'year',
|
|
1327
|
+
'month',
|
|
1328
|
+
'day',
|
|
1329
|
+
'hour',
|
|
1330
|
+
'minute',
|
|
1331
|
+
'second',
|
|
1332
|
+
'timeZoneName',
|
|
1333
|
+
'formatMatcher',
|
|
1334
|
+
'hour12',
|
|
1335
|
+
'timeZone',
|
|
1336
|
+
'dateStyle',
|
|
1337
|
+
'timeStyle',
|
|
1338
|
+
'calendar',
|
|
1339
|
+
'dayPeriod',
|
|
1340
|
+
'numberingSystem',
|
|
1341
|
+
'hourCycle',
|
|
1342
|
+
'fractionalSecondDigits'
|
|
1343
|
+
];
|
|
1344
|
+
/** @internal */
|
|
1275
1345
|
function parseDateTimeArgs(...args) {
|
|
1276
1346
|
const [arg1, arg2, arg3, arg4] = args;
|
|
1277
|
-
|
|
1347
|
+
const options = {};
|
|
1278
1348
|
let overrides = {};
|
|
1279
1349
|
let value;
|
|
1280
1350
|
if (shared.isString(arg1)) {
|
|
@@ -1316,7 +1386,14 @@ function parseDateTimeArgs(...args) {
|
|
|
1316
1386
|
options.key = arg2;
|
|
1317
1387
|
}
|
|
1318
1388
|
else if (shared.isPlainObject(arg2)) {
|
|
1319
|
-
|
|
1389
|
+
Object.keys(arg2).forEach(key => {
|
|
1390
|
+
if (DATETIME_FORMAT_OPTIONS_KEYS.includes(key)) {
|
|
1391
|
+
overrides[key] = arg2[key];
|
|
1392
|
+
}
|
|
1393
|
+
else {
|
|
1394
|
+
options[key] = arg2[key];
|
|
1395
|
+
}
|
|
1396
|
+
});
|
|
1320
1397
|
}
|
|
1321
1398
|
if (shared.isString(arg3)) {
|
|
1322
1399
|
options.locale = arg3;
|
|
@@ -1361,7 +1438,7 @@ function number(context, ...args) {
|
|
|
1361
1438
|
const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
1362
1439
|
fallbackLocale, locale);
|
|
1363
1440
|
if (!shared.isString(key) || key === '') {
|
|
1364
|
-
return new Intl.NumberFormat(locale).format(value);
|
|
1441
|
+
return new Intl.NumberFormat(locale, overrides).format(value);
|
|
1365
1442
|
}
|
|
1366
1443
|
// resolve format
|
|
1367
1444
|
let numberFormat = {};
|
|
@@ -1416,9 +1493,32 @@ function number(context, ...args) {
|
|
|
1416
1493
|
return !part ? formatter.format(value) : formatter.formatToParts(value);
|
|
1417
1494
|
}
|
|
1418
1495
|
/** @internal */
|
|
1496
|
+
const NUMBER_FORMAT_OPTIONS_KEYS = [
|
|
1497
|
+
'localeMatcher',
|
|
1498
|
+
'style',
|
|
1499
|
+
'currency',
|
|
1500
|
+
'currencyDisplay',
|
|
1501
|
+
'currencySign',
|
|
1502
|
+
'useGrouping',
|
|
1503
|
+
'minimumIntegerDigits',
|
|
1504
|
+
'minimumFractionDigits',
|
|
1505
|
+
'maximumFractionDigits',
|
|
1506
|
+
'minimumSignificantDigits',
|
|
1507
|
+
'maximumSignificantDigits',
|
|
1508
|
+
'compactDisplay',
|
|
1509
|
+
'notation',
|
|
1510
|
+
'signDisplay',
|
|
1511
|
+
'unit',
|
|
1512
|
+
'unitDisplay',
|
|
1513
|
+
'roundingMode',
|
|
1514
|
+
'roundingPriority',
|
|
1515
|
+
'roundingIncrement',
|
|
1516
|
+
'trailingZeroDisplay'
|
|
1517
|
+
];
|
|
1518
|
+
/** @internal */
|
|
1419
1519
|
function parseNumberArgs(...args) {
|
|
1420
1520
|
const [arg1, arg2, arg3, arg4] = args;
|
|
1421
|
-
|
|
1521
|
+
const options = {};
|
|
1422
1522
|
let overrides = {};
|
|
1423
1523
|
if (!shared.isNumber(arg1)) {
|
|
1424
1524
|
throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
|
|
@@ -1428,7 +1528,14 @@ function parseNumberArgs(...args) {
|
|
|
1428
1528
|
options.key = arg2;
|
|
1429
1529
|
}
|
|
1430
1530
|
else if (shared.isPlainObject(arg2)) {
|
|
1431
|
-
|
|
1531
|
+
Object.keys(arg2).forEach(key => {
|
|
1532
|
+
if (NUMBER_FORMAT_OPTIONS_KEYS.includes(key)) {
|
|
1533
|
+
overrides[key] = arg2[key];
|
|
1534
|
+
}
|
|
1535
|
+
else {
|
|
1536
|
+
options[key] = arg2[key];
|
|
1537
|
+
}
|
|
1538
|
+
});
|
|
1432
1539
|
}
|
|
1433
1540
|
if (shared.isString(arg3)) {
|
|
1434
1541
|
options.locale = arg3;
|
|
@@ -1457,10 +1564,12 @@ exports.CompileErrorCodes = messageCompiler.CompileErrorCodes;
|
|
|
1457
1564
|
exports.createCompileError = messageCompiler.createCompileError;
|
|
1458
1565
|
exports.CoreErrorCodes = CoreErrorCodes;
|
|
1459
1566
|
exports.CoreWarnCodes = CoreWarnCodes;
|
|
1567
|
+
exports.DATETIME_FORMAT_OPTIONS_KEYS = DATETIME_FORMAT_OPTIONS_KEYS;
|
|
1460
1568
|
exports.DEFAULT_LOCALE = DEFAULT_LOCALE;
|
|
1461
1569
|
exports.DEFAULT_MESSAGE_DATA_TYPE = DEFAULT_MESSAGE_DATA_TYPE;
|
|
1462
1570
|
exports.MISSING_RESOLVE_VALUE = MISSING_RESOLVE_VALUE;
|
|
1463
1571
|
exports.NOT_REOSLVED = NOT_REOSLVED;
|
|
1572
|
+
exports.NUMBER_FORMAT_OPTIONS_KEYS = NUMBER_FORMAT_OPTIONS_KEYS;
|
|
1464
1573
|
exports.VERSION = VERSION;
|
|
1465
1574
|
exports.clearCompileCache = clearCompileCache;
|
|
1466
1575
|
exports.clearDateTimeFormat = clearDateTimeFormat;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* core-base v9.2.0-beta.
|
|
2
|
+
* core-base v9.2.0-beta.38
|
|
3
3
|
* (c) 2022 kazuya kawaguchi
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -328,7 +328,9 @@ function createMessageContext(options = {}) {
|
|
|
328
328
|
shared.isFunction(options.pluralRules[locale])
|
|
329
329
|
? pluralDefault
|
|
330
330
|
: undefined;
|
|
331
|
-
const plural = (messages) =>
|
|
331
|
+
const plural = (messages) => {
|
|
332
|
+
return messages[pluralRule(pluralIndex, messages.length, orgPluralRule)];
|
|
333
|
+
};
|
|
332
334
|
const _list = options.list || [];
|
|
333
335
|
const list = (index) => _list[index];
|
|
334
336
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -358,13 +360,37 @@ function createMessageContext(options = {}) {
|
|
|
358
360
|
shared.isFunction(options.processor.interpolate)
|
|
359
361
|
? options.processor.interpolate
|
|
360
362
|
: DEFAULT_INTERPOLATE;
|
|
361
|
-
const linked = (key, modifier) => {
|
|
362
|
-
const msg = message(key)(ctx);
|
|
363
|
-
return shared.isString(modifier) ? _modifier(modifier)(msg) : msg;
|
|
364
|
-
};
|
|
365
363
|
const type = shared.isPlainObject(options.processor) && shared.isString(options.processor.type)
|
|
366
364
|
? options.processor.type
|
|
367
365
|
: DEFAULT_MESSAGE_DATA_TYPE;
|
|
366
|
+
const linked = (key, ...args) => {
|
|
367
|
+
const [arg1, arg2] = args;
|
|
368
|
+
let type = 'text';
|
|
369
|
+
let modifier = '';
|
|
370
|
+
if (args.length === 1) {
|
|
371
|
+
if (shared.isObject(arg1)) {
|
|
372
|
+
modifier = arg1.modifier || modifier;
|
|
373
|
+
type = arg1.type || type;
|
|
374
|
+
}
|
|
375
|
+
else if (shared.isString(arg1)) {
|
|
376
|
+
modifier = arg1 || modifier;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
else if (args.length === 2) {
|
|
380
|
+
if (shared.isString(arg1)) {
|
|
381
|
+
modifier = arg1 || modifier;
|
|
382
|
+
}
|
|
383
|
+
if (shared.isString(arg2)) {
|
|
384
|
+
type = arg2 || type;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
let msg = message(key)(ctx);
|
|
388
|
+
// The message in vnode resolved with linked are returned as an array by processor.nomalize
|
|
389
|
+
if (type === 'vnode' && shared.isArray(msg) && modifier) {
|
|
390
|
+
msg = msg[0];
|
|
391
|
+
}
|
|
392
|
+
return modifier ? _modifier(modifier)(msg, type) : msg;
|
|
393
|
+
};
|
|
368
394
|
const ctx = {
|
|
369
395
|
["list" /* LIST */]: list,
|
|
370
396
|
["named" /* NAMED */]: named,
|
|
@@ -543,18 +569,37 @@ function appendItemToChain(chain, target, blocks) {
|
|
|
543
569
|
* Intlify core-base version
|
|
544
570
|
* @internal
|
|
545
571
|
*/
|
|
546
|
-
const VERSION = '9.2.0-beta.
|
|
572
|
+
const VERSION = '9.2.0-beta.38';
|
|
547
573
|
const NOT_REOSLVED = -1;
|
|
548
574
|
const DEFAULT_LOCALE = 'en-US';
|
|
549
575
|
const MISSING_RESOLVE_VALUE = '';
|
|
576
|
+
const capitalize = (str) => `${str.charAt(0).toLocaleUpperCase()}${str.substr(1)}`;
|
|
550
577
|
function getDefaultLinkedModifiers() {
|
|
551
578
|
return {
|
|
552
|
-
upper: (val) =>
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
579
|
+
upper: (val, type) => {
|
|
580
|
+
// prettier-ignore
|
|
581
|
+
return type === 'text' && shared.isString(val)
|
|
582
|
+
? val.toUpperCase()
|
|
583
|
+
: type === 'vnode' && shared.isObject(val) && '__v_isVNode' in val
|
|
584
|
+
? val.children.toUpperCase()
|
|
585
|
+
: val;
|
|
586
|
+
},
|
|
587
|
+
lower: (val, type) => {
|
|
588
|
+
// prettier-ignore
|
|
589
|
+
return type === 'text' && shared.isString(val)
|
|
590
|
+
? val.toLowerCase()
|
|
591
|
+
: type === 'vnode' && shared.isObject(val) && '__v_isVNode' in val
|
|
592
|
+
? val.children.toLowerCase()
|
|
593
|
+
: val;
|
|
594
|
+
},
|
|
595
|
+
capitalize: (val, type) => {
|
|
596
|
+
// prettier-ignore
|
|
597
|
+
return (type === 'text' && shared.isString(val)
|
|
598
|
+
? capitalize(val)
|
|
599
|
+
: type === 'vnode' && shared.isObject(val) && '__v_isVNode' in val
|
|
600
|
+
? capitalize(val.children)
|
|
601
|
+
: val);
|
|
602
|
+
}
|
|
558
603
|
};
|
|
559
604
|
}
|
|
560
605
|
let _compiler;
|
|
@@ -845,7 +890,9 @@ function translate(context, ...args) {
|
|
|
845
890
|
const msgContext = createMessageContext(ctxOptions);
|
|
846
891
|
const messaged = evaluateMessage(context, msg, msgContext);
|
|
847
892
|
// if use post translation option, proceed it with handler
|
|
848
|
-
const ret = postTranslation
|
|
893
|
+
const ret = postTranslation
|
|
894
|
+
? postTranslation(messaged, key)
|
|
895
|
+
: messaged;
|
|
849
896
|
return ret;
|
|
850
897
|
}
|
|
851
898
|
function escapeParams(options) {
|
|
@@ -1021,7 +1068,7 @@ function datetime(context, ...args) {
|
|
|
1021
1068
|
const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
1022
1069
|
fallbackLocale, locale);
|
|
1023
1070
|
if (!shared.isString(key) || key === '') {
|
|
1024
|
-
return new Intl.DateTimeFormat(locale).format(value);
|
|
1071
|
+
return new Intl.DateTimeFormat(locale, overrides).format(value);
|
|
1025
1072
|
}
|
|
1026
1073
|
// resolve format
|
|
1027
1074
|
let datetimeFormat = {};
|
|
@@ -1053,9 +1100,32 @@ function datetime(context, ...args) {
|
|
|
1053
1100
|
return !part ? formatter.format(value) : formatter.formatToParts(value);
|
|
1054
1101
|
}
|
|
1055
1102
|
/** @internal */
|
|
1103
|
+
const DATETIME_FORMAT_OPTIONS_KEYS = [
|
|
1104
|
+
'localeMatcher',
|
|
1105
|
+
'weekday',
|
|
1106
|
+
'era',
|
|
1107
|
+
'year',
|
|
1108
|
+
'month',
|
|
1109
|
+
'day',
|
|
1110
|
+
'hour',
|
|
1111
|
+
'minute',
|
|
1112
|
+
'second',
|
|
1113
|
+
'timeZoneName',
|
|
1114
|
+
'formatMatcher',
|
|
1115
|
+
'hour12',
|
|
1116
|
+
'timeZone',
|
|
1117
|
+
'dateStyle',
|
|
1118
|
+
'timeStyle',
|
|
1119
|
+
'calendar',
|
|
1120
|
+
'dayPeriod',
|
|
1121
|
+
'numberingSystem',
|
|
1122
|
+
'hourCycle',
|
|
1123
|
+
'fractionalSecondDigits'
|
|
1124
|
+
];
|
|
1125
|
+
/** @internal */
|
|
1056
1126
|
function parseDateTimeArgs(...args) {
|
|
1057
1127
|
const [arg1, arg2, arg3, arg4] = args;
|
|
1058
|
-
|
|
1128
|
+
const options = {};
|
|
1059
1129
|
let overrides = {};
|
|
1060
1130
|
let value;
|
|
1061
1131
|
if (shared.isString(arg1)) {
|
|
@@ -1097,7 +1167,14 @@ function parseDateTimeArgs(...args) {
|
|
|
1097
1167
|
options.key = arg2;
|
|
1098
1168
|
}
|
|
1099
1169
|
else if (shared.isPlainObject(arg2)) {
|
|
1100
|
-
|
|
1170
|
+
Object.keys(arg2).forEach(key => {
|
|
1171
|
+
if (DATETIME_FORMAT_OPTIONS_KEYS.includes(key)) {
|
|
1172
|
+
overrides[key] = arg2[key];
|
|
1173
|
+
}
|
|
1174
|
+
else {
|
|
1175
|
+
options[key] = arg2[key];
|
|
1176
|
+
}
|
|
1177
|
+
});
|
|
1101
1178
|
}
|
|
1102
1179
|
if (shared.isString(arg3)) {
|
|
1103
1180
|
options.locale = arg3;
|
|
@@ -1138,7 +1215,7 @@ function number(context, ...args) {
|
|
|
1138
1215
|
const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
1139
1216
|
fallbackLocale, locale);
|
|
1140
1217
|
if (!shared.isString(key) || key === '') {
|
|
1141
|
-
return new Intl.NumberFormat(locale).format(value);
|
|
1218
|
+
return new Intl.NumberFormat(locale, overrides).format(value);
|
|
1142
1219
|
}
|
|
1143
1220
|
// resolve format
|
|
1144
1221
|
let numberFormat = {};
|
|
@@ -1170,9 +1247,32 @@ function number(context, ...args) {
|
|
|
1170
1247
|
return !part ? formatter.format(value) : formatter.formatToParts(value);
|
|
1171
1248
|
}
|
|
1172
1249
|
/** @internal */
|
|
1250
|
+
const NUMBER_FORMAT_OPTIONS_KEYS = [
|
|
1251
|
+
'localeMatcher',
|
|
1252
|
+
'style',
|
|
1253
|
+
'currency',
|
|
1254
|
+
'currencyDisplay',
|
|
1255
|
+
'currencySign',
|
|
1256
|
+
'useGrouping',
|
|
1257
|
+
'minimumIntegerDigits',
|
|
1258
|
+
'minimumFractionDigits',
|
|
1259
|
+
'maximumFractionDigits',
|
|
1260
|
+
'minimumSignificantDigits',
|
|
1261
|
+
'maximumSignificantDigits',
|
|
1262
|
+
'compactDisplay',
|
|
1263
|
+
'notation',
|
|
1264
|
+
'signDisplay',
|
|
1265
|
+
'unit',
|
|
1266
|
+
'unitDisplay',
|
|
1267
|
+
'roundingMode',
|
|
1268
|
+
'roundingPriority',
|
|
1269
|
+
'roundingIncrement',
|
|
1270
|
+
'trailingZeroDisplay'
|
|
1271
|
+
];
|
|
1272
|
+
/** @internal */
|
|
1173
1273
|
function parseNumberArgs(...args) {
|
|
1174
1274
|
const [arg1, arg2, arg3, arg4] = args;
|
|
1175
|
-
|
|
1275
|
+
const options = {};
|
|
1176
1276
|
let overrides = {};
|
|
1177
1277
|
if (!shared.isNumber(arg1)) {
|
|
1178
1278
|
throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
|
|
@@ -1182,7 +1282,14 @@ function parseNumberArgs(...args) {
|
|
|
1182
1282
|
options.key = arg2;
|
|
1183
1283
|
}
|
|
1184
1284
|
else if (shared.isPlainObject(arg2)) {
|
|
1185
|
-
|
|
1285
|
+
Object.keys(arg2).forEach(key => {
|
|
1286
|
+
if (NUMBER_FORMAT_OPTIONS_KEYS.includes(key)) {
|
|
1287
|
+
overrides[key] = arg2[key];
|
|
1288
|
+
}
|
|
1289
|
+
else {
|
|
1290
|
+
options[key] = arg2[key];
|
|
1291
|
+
}
|
|
1292
|
+
});
|
|
1186
1293
|
}
|
|
1187
1294
|
if (shared.isString(arg3)) {
|
|
1188
1295
|
options.locale = arg3;
|
|
@@ -1211,10 +1318,12 @@ exports.CompileErrorCodes = messageCompiler.CompileErrorCodes;
|
|
|
1211
1318
|
exports.createCompileError = messageCompiler.createCompileError;
|
|
1212
1319
|
exports.CoreErrorCodes = CoreErrorCodes;
|
|
1213
1320
|
exports.CoreWarnCodes = CoreWarnCodes;
|
|
1321
|
+
exports.DATETIME_FORMAT_OPTIONS_KEYS = DATETIME_FORMAT_OPTIONS_KEYS;
|
|
1214
1322
|
exports.DEFAULT_LOCALE = DEFAULT_LOCALE;
|
|
1215
1323
|
exports.DEFAULT_MESSAGE_DATA_TYPE = DEFAULT_MESSAGE_DATA_TYPE;
|
|
1216
1324
|
exports.MISSING_RESOLVE_VALUE = MISSING_RESOLVE_VALUE;
|
|
1217
1325
|
exports.NOT_REOSLVED = NOT_REOSLVED;
|
|
1326
|
+
exports.NUMBER_FORMAT_OPTIONS_KEYS = NUMBER_FORMAT_OPTIONS_KEYS;
|
|
1218
1327
|
exports.VERSION = VERSION;
|
|
1219
1328
|
exports.clearCompileCache = clearCompileCache;
|
|
1220
1329
|
exports.clearDateTimeFormat = clearDateTimeFormat;
|
package/dist/core-base.d.ts
CHANGED
|
@@ -199,6 +199,8 @@ export declare function datetime<Context extends CoreContext<Message, {}, Contex
|
|
|
199
199
|
|
|
200
200
|
export declare function datetime<Context extends CoreContext<Message, {}, Context['datetimeFormats'], {}>, Value extends number | string | Date = number, Key extends string = string, ResourceKeys extends PickupFormatKeys<Context['datetimeFormats']> = PickupFormatKeys<Context['datetimeFormats']>, Message = string>(context: Context, value: Value, keyOrOptions: Key | ResourceKeys | DateTimeOptions<Key | ResourceKeys, Context['locale']>, locale: Context['locale'], override: Intl.DateTimeFormatOptions): string | number | Intl.DateTimeFormatPart[];
|
|
201
201
|
|
|
202
|
+
/* Excluded from this release type: DATETIME_FORMAT_OPTIONS_KEYS */
|
|
203
|
+
|
|
202
204
|
export declare type DateTimeDigital = 'numeric' | '2-digit';
|
|
203
205
|
|
|
204
206
|
export declare type DateTimeFormat = {
|
|
@@ -249,9 +251,9 @@ export declare type DateTimeHumanReadable = 'long' | 'short' | 'narrow';
|
|
|
249
251
|
* datetime(context, value, { key: 'short', part: true })
|
|
250
252
|
*
|
|
251
253
|
* // orverride context.datetimeFormats[locale] options with functino options
|
|
252
|
-
* datetime(cnotext, value, 'short', {
|
|
253
|
-
* datetime(cnotext, value, 'short', 'ja-JP', {
|
|
254
|
-
* datetime(context, value, { key: 'short', part: true
|
|
254
|
+
* datetime(cnotext, value, 'short', { year: '2-digit' })
|
|
255
|
+
* datetime(cnotext, value, 'short', 'ja-JP', { year: '2-digit' })
|
|
256
|
+
* datetime(context, value, { key: 'short', part: true, year: '2-digit' })
|
|
255
257
|
*/
|
|
256
258
|
/**
|
|
257
259
|
* DateTime options
|
|
@@ -261,7 +263,7 @@ export declare type DateTimeHumanReadable = 'long' | 'short' | 'narrow';
|
|
|
261
263
|
*
|
|
262
264
|
* @VueI18nGeneral
|
|
263
265
|
*/
|
|
264
|
-
export declare interface DateTimeOptions<Key = string, Locales = Locale> {
|
|
266
|
+
export declare interface DateTimeOptions<Key = string, Locales = Locale> extends Intl.DateTimeFormatOptions {
|
|
265
267
|
/**
|
|
266
268
|
* @remarks
|
|
267
269
|
* The target format key
|
|
@@ -384,7 +386,12 @@ export declare type LinkedModifiers<T = string> = {
|
|
|
384
386
|
[key: string]: LinkedModify<T>;
|
|
385
387
|
};
|
|
386
388
|
|
|
387
|
-
export declare type LinkedModify<T = string> = (value: T) => MessageType<T>;
|
|
389
|
+
export declare type LinkedModify<T = string> = (value: T, type: string) => MessageType<T>;
|
|
390
|
+
|
|
391
|
+
export declare interface LinkedOptions {
|
|
392
|
+
type?: string;
|
|
393
|
+
modifier?: string;
|
|
394
|
+
}
|
|
388
395
|
|
|
389
396
|
/** @VueI18nGeneral */
|
|
390
397
|
export declare type Locale = string;
|
|
@@ -452,6 +459,8 @@ export declare interface MessageContext<T = string> {
|
|
|
452
459
|
named(key: string): unknown;
|
|
453
460
|
plural(messages: T[]): T;
|
|
454
461
|
linked(key: Path, modifier?: string): MessageType<T>;
|
|
462
|
+
linked(key: Path, modifier?: string, type?: string): MessageType<T>;
|
|
463
|
+
linked(key: Path, optoins?: LinkedOptions): MessageType<T>;
|
|
455
464
|
message(key: Path): MessageFunction<T>;
|
|
456
465
|
type: string;
|
|
457
466
|
interpolate: MessageInterpolate<T>;
|
|
@@ -524,6 +533,8 @@ export declare function number<Context extends CoreContext<Message, {}, {}, Cont
|
|
|
524
533
|
|
|
525
534
|
export declare function number<Context extends CoreContext<Message, {}, {}, Context['numberFormats']>, Value extends number = number, Key extends string = string, ResourceKeys extends PickupFormatKeys<Context['numberFormats']> = PickupFormatKeys<Context['numberFormats']>, Message = string>(context: Context, value: Value, keyOrOptions: Key | ResourceKeys | NumberOptions<Key | ResourceKeys, Context['locale']>, locale: Context['locale'], override: Intl.NumberFormatOptions): string | number | Intl.NumberFormatPart[];
|
|
526
535
|
|
|
536
|
+
/* Excluded from this release type: NUMBER_FORMAT_OPTIONS_KEYS */
|
|
537
|
+
|
|
527
538
|
export declare type NumberFormat = {
|
|
528
539
|
[key: string]: NumberFormatOptions;
|
|
529
540
|
};
|
|
@@ -572,7 +583,7 @@ export declare type NumberFormatToPartsResult = {
|
|
|
572
583
|
* // orverride context.numberFormats[locale] options with functino options
|
|
573
584
|
* number(cnotext, value, 'currency', { year: '2-digit' })
|
|
574
585
|
* number(cnotext, value, 'currency', 'ja-JP', { year: '2-digit' })
|
|
575
|
-
* number(context, value, { key: 'currenty', part: true
|
|
586
|
+
* number(context, value, { key: 'currenty', locale: 'ja-JP', part: true, year: '2-digit'})
|
|
576
587
|
*/
|
|
577
588
|
/**
|
|
578
589
|
* Number Options
|
|
@@ -582,7 +593,7 @@ export declare type NumberFormatToPartsResult = {
|
|
|
582
593
|
*
|
|
583
594
|
* @VueI18nGeneral
|
|
584
595
|
*/
|
|
585
|
-
export declare interface NumberOptions<Key = string, Locales = Locale> {
|
|
596
|
+
export declare interface NumberOptions<Key = string, Locales = Locale> extends Intl.NumberFormatOptions {
|
|
586
597
|
/**
|
|
587
598
|
* @remarks
|
|
588
599
|
* The target format key
|
|
@@ -654,7 +665,7 @@ export declare type PluralizationRules = {
|
|
|
654
665
|
};
|
|
655
666
|
|
|
656
667
|
/** @VueI18nGeneral */
|
|
657
|
-
export declare type PostTranslationHandler<Message = string> = (translated: MessageType<Message
|
|
668
|
+
export declare type PostTranslationHandler<Message = string> = (translated: MessageType<Message>, key: string) => MessageType<Message>;
|
|
658
669
|
|
|
659
670
|
/**
|
|
660
671
|
* Register the locale fallbacker
|