@intlify/core-base 9.2.0-beta.33 → 9.2.0-beta.36
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 +116 -17
- package/dist/core-base.cjs.prod.js +116 -17
- package/dist/core-base.d.ts +14 -7
- package/dist/core-base.esm-browser.js +121 -17
- package/dist/core-base.esm-browser.prod.js +2 -2
- package/dist/core-base.esm-bundler.js +117 -18
- package/dist/core-base.global.js +121 -17
- package/dist/core-base.global.prod.js +2 -2
- package/package.json +5 -5
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.36
|
|
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.36';
|
|
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;
|
|
@@ -1271,10 +1316,32 @@ function datetime(context, ...args) {
|
|
|
1271
1316
|
}
|
|
1272
1317
|
return !part ? formatter.format(value) : formatter.formatToParts(value);
|
|
1273
1318
|
}
|
|
1319
|
+
const DATETIME_FORMAT_OPTIONS_KEYS = [
|
|
1320
|
+
'localeMatcher',
|
|
1321
|
+
'weekday',
|
|
1322
|
+
'era',
|
|
1323
|
+
'year',
|
|
1324
|
+
'month',
|
|
1325
|
+
'day',
|
|
1326
|
+
'hour',
|
|
1327
|
+
'minute',
|
|
1328
|
+
'second',
|
|
1329
|
+
'timeZoneName',
|
|
1330
|
+
'formatMatcher',
|
|
1331
|
+
'hour12',
|
|
1332
|
+
'timeZone',
|
|
1333
|
+
'dateStyle',
|
|
1334
|
+
'timeStyle',
|
|
1335
|
+
'calendar',
|
|
1336
|
+
'dayPeriod',
|
|
1337
|
+
'numberingSystem',
|
|
1338
|
+
'hourCycle',
|
|
1339
|
+
'fractionalSecondDigits'
|
|
1340
|
+
];
|
|
1274
1341
|
/** @internal */
|
|
1275
1342
|
function parseDateTimeArgs(...args) {
|
|
1276
1343
|
const [arg1, arg2, arg3, arg4] = args;
|
|
1277
|
-
|
|
1344
|
+
const options = {};
|
|
1278
1345
|
let overrides = {};
|
|
1279
1346
|
let value;
|
|
1280
1347
|
if (shared.isString(arg1)) {
|
|
@@ -1316,7 +1383,14 @@ function parseDateTimeArgs(...args) {
|
|
|
1316
1383
|
options.key = arg2;
|
|
1317
1384
|
}
|
|
1318
1385
|
else if (shared.isPlainObject(arg2)) {
|
|
1319
|
-
|
|
1386
|
+
Object.keys(arg2).forEach(key => {
|
|
1387
|
+
if (DATETIME_FORMAT_OPTIONS_KEYS.includes(key)) {
|
|
1388
|
+
overrides[key] = arg2[key];
|
|
1389
|
+
}
|
|
1390
|
+
else {
|
|
1391
|
+
options[key] = arg2[key];
|
|
1392
|
+
}
|
|
1393
|
+
});
|
|
1320
1394
|
}
|
|
1321
1395
|
if (shared.isString(arg3)) {
|
|
1322
1396
|
options.locale = arg3;
|
|
@@ -1415,10 +1489,28 @@ function number(context, ...args) {
|
|
|
1415
1489
|
}
|
|
1416
1490
|
return !part ? formatter.format(value) : formatter.formatToParts(value);
|
|
1417
1491
|
}
|
|
1492
|
+
const NUMBER_FORMAT_OPTIONS_KEYS = [
|
|
1493
|
+
'localeMatcher',
|
|
1494
|
+
'style',
|
|
1495
|
+
'currency',
|
|
1496
|
+
'currencyDisplay',
|
|
1497
|
+
'currencySign',
|
|
1498
|
+
'useGrouping',
|
|
1499
|
+
'minimumIntegerDigits',
|
|
1500
|
+
'minimumFractionDigits',
|
|
1501
|
+
'maximumFractionDigits',
|
|
1502
|
+
'minimumSignificantDigits',
|
|
1503
|
+
'maximumSignificantDigits',
|
|
1504
|
+
'compactDisplay',
|
|
1505
|
+
'notation',
|
|
1506
|
+
'signDisplay',
|
|
1507
|
+
'unit',
|
|
1508
|
+
'unitDisplay'
|
|
1509
|
+
];
|
|
1418
1510
|
/** @internal */
|
|
1419
1511
|
function parseNumberArgs(...args) {
|
|
1420
1512
|
const [arg1, arg2, arg3, arg4] = args;
|
|
1421
|
-
|
|
1513
|
+
const options = {};
|
|
1422
1514
|
let overrides = {};
|
|
1423
1515
|
if (!shared.isNumber(arg1)) {
|
|
1424
1516
|
throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
|
|
@@ -1428,7 +1520,14 @@ function parseNumberArgs(...args) {
|
|
|
1428
1520
|
options.key = arg2;
|
|
1429
1521
|
}
|
|
1430
1522
|
else if (shared.isPlainObject(arg2)) {
|
|
1431
|
-
|
|
1523
|
+
Object.keys(arg2).forEach(key => {
|
|
1524
|
+
if (NUMBER_FORMAT_OPTIONS_KEYS.includes(key)) {
|
|
1525
|
+
overrides[key] = arg2[key];
|
|
1526
|
+
}
|
|
1527
|
+
else {
|
|
1528
|
+
options[key] = arg2[key];
|
|
1529
|
+
}
|
|
1530
|
+
});
|
|
1432
1531
|
}
|
|
1433
1532
|
if (shared.isString(arg3)) {
|
|
1434
1533
|
options.locale = arg3;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* core-base v9.2.0-beta.
|
|
2
|
+
* core-base v9.2.0-beta.36
|
|
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.36';
|
|
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;
|
|
@@ -1052,10 +1097,32 @@ function datetime(context, ...args) {
|
|
|
1052
1097
|
}
|
|
1053
1098
|
return !part ? formatter.format(value) : formatter.formatToParts(value);
|
|
1054
1099
|
}
|
|
1100
|
+
const DATETIME_FORMAT_OPTIONS_KEYS = [
|
|
1101
|
+
'localeMatcher',
|
|
1102
|
+
'weekday',
|
|
1103
|
+
'era',
|
|
1104
|
+
'year',
|
|
1105
|
+
'month',
|
|
1106
|
+
'day',
|
|
1107
|
+
'hour',
|
|
1108
|
+
'minute',
|
|
1109
|
+
'second',
|
|
1110
|
+
'timeZoneName',
|
|
1111
|
+
'formatMatcher',
|
|
1112
|
+
'hour12',
|
|
1113
|
+
'timeZone',
|
|
1114
|
+
'dateStyle',
|
|
1115
|
+
'timeStyle',
|
|
1116
|
+
'calendar',
|
|
1117
|
+
'dayPeriod',
|
|
1118
|
+
'numberingSystem',
|
|
1119
|
+
'hourCycle',
|
|
1120
|
+
'fractionalSecondDigits'
|
|
1121
|
+
];
|
|
1055
1122
|
/** @internal */
|
|
1056
1123
|
function parseDateTimeArgs(...args) {
|
|
1057
1124
|
const [arg1, arg2, arg3, arg4] = args;
|
|
1058
|
-
|
|
1125
|
+
const options = {};
|
|
1059
1126
|
let overrides = {};
|
|
1060
1127
|
let value;
|
|
1061
1128
|
if (shared.isString(arg1)) {
|
|
@@ -1097,7 +1164,14 @@ function parseDateTimeArgs(...args) {
|
|
|
1097
1164
|
options.key = arg2;
|
|
1098
1165
|
}
|
|
1099
1166
|
else if (shared.isPlainObject(arg2)) {
|
|
1100
|
-
|
|
1167
|
+
Object.keys(arg2).forEach(key => {
|
|
1168
|
+
if (DATETIME_FORMAT_OPTIONS_KEYS.includes(key)) {
|
|
1169
|
+
overrides[key] = arg2[key];
|
|
1170
|
+
}
|
|
1171
|
+
else {
|
|
1172
|
+
options[key] = arg2[key];
|
|
1173
|
+
}
|
|
1174
|
+
});
|
|
1101
1175
|
}
|
|
1102
1176
|
if (shared.isString(arg3)) {
|
|
1103
1177
|
options.locale = arg3;
|
|
@@ -1169,10 +1243,28 @@ function number(context, ...args) {
|
|
|
1169
1243
|
}
|
|
1170
1244
|
return !part ? formatter.format(value) : formatter.formatToParts(value);
|
|
1171
1245
|
}
|
|
1246
|
+
const NUMBER_FORMAT_OPTIONS_KEYS = [
|
|
1247
|
+
'localeMatcher',
|
|
1248
|
+
'style',
|
|
1249
|
+
'currency',
|
|
1250
|
+
'currencyDisplay',
|
|
1251
|
+
'currencySign',
|
|
1252
|
+
'useGrouping',
|
|
1253
|
+
'minimumIntegerDigits',
|
|
1254
|
+
'minimumFractionDigits',
|
|
1255
|
+
'maximumFractionDigits',
|
|
1256
|
+
'minimumSignificantDigits',
|
|
1257
|
+
'maximumSignificantDigits',
|
|
1258
|
+
'compactDisplay',
|
|
1259
|
+
'notation',
|
|
1260
|
+
'signDisplay',
|
|
1261
|
+
'unit',
|
|
1262
|
+
'unitDisplay'
|
|
1263
|
+
];
|
|
1172
1264
|
/** @internal */
|
|
1173
1265
|
function parseNumberArgs(...args) {
|
|
1174
1266
|
const [arg1, arg2, arg3, arg4] = args;
|
|
1175
|
-
|
|
1267
|
+
const options = {};
|
|
1176
1268
|
let overrides = {};
|
|
1177
1269
|
if (!shared.isNumber(arg1)) {
|
|
1178
1270
|
throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
|
|
@@ -1182,7 +1274,14 @@ function parseNumberArgs(...args) {
|
|
|
1182
1274
|
options.key = arg2;
|
|
1183
1275
|
}
|
|
1184
1276
|
else if (shared.isPlainObject(arg2)) {
|
|
1185
|
-
|
|
1277
|
+
Object.keys(arg2).forEach(key => {
|
|
1278
|
+
if (NUMBER_FORMAT_OPTIONS_KEYS.includes(key)) {
|
|
1279
|
+
overrides[key] = arg2[key];
|
|
1280
|
+
}
|
|
1281
|
+
else {
|
|
1282
|
+
options[key] = arg2[key];
|
|
1283
|
+
}
|
|
1284
|
+
});
|
|
1186
1285
|
}
|
|
1187
1286
|
if (shared.isString(arg3)) {
|
|
1188
1287
|
options.locale = arg3;
|
package/dist/core-base.d.ts
CHANGED
|
@@ -249,9 +249,9 @@ export declare type DateTimeHumanReadable = 'long' | 'short' | 'narrow';
|
|
|
249
249
|
* datetime(context, value, { key: 'short', part: true })
|
|
250
250
|
*
|
|
251
251
|
* // 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
|
|
252
|
+
* datetime(cnotext, value, 'short', { year: '2-digit' })
|
|
253
|
+
* datetime(cnotext, value, 'short', 'ja-JP', { year: '2-digit' })
|
|
254
|
+
* datetime(context, value, { key: 'short', part: true, year: '2-digit' })
|
|
255
255
|
*/
|
|
256
256
|
/**
|
|
257
257
|
* DateTime options
|
|
@@ -261,7 +261,7 @@ export declare type DateTimeHumanReadable = 'long' | 'short' | 'narrow';
|
|
|
261
261
|
*
|
|
262
262
|
* @VueI18nGeneral
|
|
263
263
|
*/
|
|
264
|
-
export declare interface DateTimeOptions<Key = string, Locales = Locale> {
|
|
264
|
+
export declare interface DateTimeOptions<Key = string, Locales = Locale> extends Intl.DateTimeFormatOptions {
|
|
265
265
|
/**
|
|
266
266
|
* @remarks
|
|
267
267
|
* The target format key
|
|
@@ -384,7 +384,12 @@ export declare type LinkedModifiers<T = string> = {
|
|
|
384
384
|
[key: string]: LinkedModify<T>;
|
|
385
385
|
};
|
|
386
386
|
|
|
387
|
-
export declare type LinkedModify<T = string> = (value: T) => MessageType<T>;
|
|
387
|
+
export declare type LinkedModify<T = string> = (value: T, type: string) => MessageType<T>;
|
|
388
|
+
|
|
389
|
+
export declare interface LinkedOptions {
|
|
390
|
+
type?: string;
|
|
391
|
+
modifier?: string;
|
|
392
|
+
}
|
|
388
393
|
|
|
389
394
|
/** @VueI18nGeneral */
|
|
390
395
|
export declare type Locale = string;
|
|
@@ -452,6 +457,8 @@ export declare interface MessageContext<T = string> {
|
|
|
452
457
|
named(key: string): unknown;
|
|
453
458
|
plural(messages: T[]): T;
|
|
454
459
|
linked(key: Path, modifier?: string): MessageType<T>;
|
|
460
|
+
linked(key: Path, modifier?: string, type?: string): MessageType<T>;
|
|
461
|
+
linked(key: Path, optoins?: LinkedOptions): MessageType<T>;
|
|
455
462
|
message(key: Path): MessageFunction<T>;
|
|
456
463
|
type: string;
|
|
457
464
|
interpolate: MessageInterpolate<T>;
|
|
@@ -572,7 +579,7 @@ export declare type NumberFormatToPartsResult = {
|
|
|
572
579
|
* // orverride context.numberFormats[locale] options with functino options
|
|
573
580
|
* number(cnotext, value, 'currency', { year: '2-digit' })
|
|
574
581
|
* number(cnotext, value, 'currency', 'ja-JP', { year: '2-digit' })
|
|
575
|
-
* number(context, value, { key: 'currenty', part: true
|
|
582
|
+
* number(context, value, { key: 'currenty', locale: 'ja-JP', part: true, year: '2-digit'})
|
|
576
583
|
*/
|
|
577
584
|
/**
|
|
578
585
|
* Number Options
|
|
@@ -582,7 +589,7 @@ export declare type NumberFormatToPartsResult = {
|
|
|
582
589
|
*
|
|
583
590
|
* @VueI18nGeneral
|
|
584
591
|
*/
|
|
585
|
-
export declare interface NumberOptions<Key = string, Locales = Locale> {
|
|
592
|
+
export declare interface NumberOptions<Key = string, Locales = Locale> extends Intl.NumberFormatOptions {
|
|
586
593
|
/**
|
|
587
594
|
* @remarks
|
|
588
595
|
* The target format key
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* core-base v9.2.0-beta.
|
|
2
|
+
* core-base v9.2.0-beta.36
|
|
3
3
|
* (c) 2022 kazuya kawaguchi
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -1246,6 +1246,7 @@ function traverseNode(node, transformer) {
|
|
|
1246
1246
|
const linked = node;
|
|
1247
1247
|
traverseNode(linked.key, transformer);
|
|
1248
1248
|
transformer.helper("linked" /* LINKED */);
|
|
1249
|
+
transformer.helper("type" /* TYPE */);
|
|
1249
1250
|
break;
|
|
1250
1251
|
case 5 /* List */:
|
|
1251
1252
|
transformer.helper("interpolate" /* INTERPOLATE */);
|
|
@@ -1322,6 +1323,10 @@ function generateLinkedNode(generator, node) {
|
|
|
1322
1323
|
if (node.modifier) {
|
|
1323
1324
|
generator.push(`, `);
|
|
1324
1325
|
generateNode(generator, node.modifier);
|
|
1326
|
+
generator.push(`, _type`);
|
|
1327
|
+
}
|
|
1328
|
+
else {
|
|
1329
|
+
generator.push(`, undefined, _type`);
|
|
1325
1330
|
}
|
|
1326
1331
|
generator.push(`)`);
|
|
1327
1332
|
}
|
|
@@ -1773,7 +1778,9 @@ function createMessageContext(options = {}) {
|
|
|
1773
1778
|
isFunction(options.pluralRules[locale])
|
|
1774
1779
|
? pluralDefault
|
|
1775
1780
|
: undefined;
|
|
1776
|
-
const plural = (messages) =>
|
|
1781
|
+
const plural = (messages) => {
|
|
1782
|
+
return messages[pluralRule(pluralIndex, messages.length, orgPluralRule)];
|
|
1783
|
+
};
|
|
1777
1784
|
const _list = options.list || [];
|
|
1778
1785
|
const list = (index) => _list[index];
|
|
1779
1786
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -1803,13 +1810,37 @@ function createMessageContext(options = {}) {
|
|
|
1803
1810
|
isFunction(options.processor.interpolate)
|
|
1804
1811
|
? options.processor.interpolate
|
|
1805
1812
|
: DEFAULT_INTERPOLATE;
|
|
1806
|
-
const linked = (key, modifier) => {
|
|
1807
|
-
const msg = message(key)(ctx);
|
|
1808
|
-
return isString(modifier) ? _modifier(modifier)(msg) : msg;
|
|
1809
|
-
};
|
|
1810
1813
|
const type = isPlainObject(options.processor) && isString(options.processor.type)
|
|
1811
1814
|
? options.processor.type
|
|
1812
1815
|
: DEFAULT_MESSAGE_DATA_TYPE;
|
|
1816
|
+
const linked = (key, ...args) => {
|
|
1817
|
+
const [arg1, arg2] = args;
|
|
1818
|
+
let type = 'text';
|
|
1819
|
+
let modifier = '';
|
|
1820
|
+
if (args.length === 1) {
|
|
1821
|
+
if (isObject(arg1)) {
|
|
1822
|
+
modifier = arg1.modifier || modifier;
|
|
1823
|
+
type = arg1.type || type;
|
|
1824
|
+
}
|
|
1825
|
+
else if (isString(arg1)) {
|
|
1826
|
+
modifier = arg1 || modifier;
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
else if (args.length === 2) {
|
|
1830
|
+
if (isString(arg1)) {
|
|
1831
|
+
modifier = arg1 || modifier;
|
|
1832
|
+
}
|
|
1833
|
+
if (isString(arg2)) {
|
|
1834
|
+
type = arg2 || type;
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1837
|
+
let msg = message(key)(ctx);
|
|
1838
|
+
// The message in vnode resolved with linked are returned as an array by processor.nomalize
|
|
1839
|
+
if (type === 'vnode' && isArray(msg) && modifier) {
|
|
1840
|
+
msg = msg[0];
|
|
1841
|
+
}
|
|
1842
|
+
return modifier ? _modifier(modifier)(msg, type) : msg;
|
|
1843
|
+
};
|
|
1813
1844
|
const ctx = {
|
|
1814
1845
|
["list" /* LIST */]: list,
|
|
1815
1846
|
["named" /* NAMED */]: named,
|
|
@@ -1993,18 +2024,37 @@ function appendItemToChain(chain, target, blocks) {
|
|
|
1993
2024
|
* Intlify core-base version
|
|
1994
2025
|
* @internal
|
|
1995
2026
|
*/
|
|
1996
|
-
const VERSION = '9.2.0-beta.
|
|
2027
|
+
const VERSION = '9.2.0-beta.36';
|
|
1997
2028
|
const NOT_REOSLVED = -1;
|
|
1998
2029
|
const DEFAULT_LOCALE = 'en-US';
|
|
1999
2030
|
const MISSING_RESOLVE_VALUE = '';
|
|
2031
|
+
const capitalize = (str) => `${str.charAt(0).toLocaleUpperCase()}${str.substr(1)}`;
|
|
2000
2032
|
function getDefaultLinkedModifiers() {
|
|
2001
2033
|
return {
|
|
2002
|
-
upper: (val) =>
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2034
|
+
upper: (val, type) => {
|
|
2035
|
+
// prettier-ignore
|
|
2036
|
+
return type === 'text' && isString(val)
|
|
2037
|
+
? val.toUpperCase()
|
|
2038
|
+
: type === 'vnode' && isObject(val) && '__v_isVNode' in val
|
|
2039
|
+
? val.children.toUpperCase()
|
|
2040
|
+
: val;
|
|
2041
|
+
},
|
|
2042
|
+
lower: (val, type) => {
|
|
2043
|
+
// prettier-ignore
|
|
2044
|
+
return type === 'text' && isString(val)
|
|
2045
|
+
? val.toLowerCase()
|
|
2046
|
+
: type === 'vnode' && isObject(val) && '__v_isVNode' in val
|
|
2047
|
+
? val.children.toLowerCase()
|
|
2048
|
+
: val;
|
|
2049
|
+
},
|
|
2050
|
+
capitalize: (val, type) => {
|
|
2051
|
+
// prettier-ignore
|
|
2052
|
+
return (type === 'text' && isString(val)
|
|
2053
|
+
? capitalize(val)
|
|
2054
|
+
: type === 'vnode' && isObject(val) && '__v_isVNode' in val
|
|
2055
|
+
? capitalize(val.children)
|
|
2056
|
+
: val);
|
|
2057
|
+
}
|
|
2008
2058
|
};
|
|
2009
2059
|
}
|
|
2010
2060
|
let _compiler;
|
|
@@ -2721,10 +2771,32 @@ function datetime(context, ...args) {
|
|
|
2721
2771
|
}
|
|
2722
2772
|
return !part ? formatter.format(value) : formatter.formatToParts(value);
|
|
2723
2773
|
}
|
|
2774
|
+
const DATETIME_FORMAT_OPTIONS_KEYS = [
|
|
2775
|
+
'localeMatcher',
|
|
2776
|
+
'weekday',
|
|
2777
|
+
'era',
|
|
2778
|
+
'year',
|
|
2779
|
+
'month',
|
|
2780
|
+
'day',
|
|
2781
|
+
'hour',
|
|
2782
|
+
'minute',
|
|
2783
|
+
'second',
|
|
2784
|
+
'timeZoneName',
|
|
2785
|
+
'formatMatcher',
|
|
2786
|
+
'hour12',
|
|
2787
|
+
'timeZone',
|
|
2788
|
+
'dateStyle',
|
|
2789
|
+
'timeStyle',
|
|
2790
|
+
'calendar',
|
|
2791
|
+
'dayPeriod',
|
|
2792
|
+
'numberingSystem',
|
|
2793
|
+
'hourCycle',
|
|
2794
|
+
'fractionalSecondDigits'
|
|
2795
|
+
];
|
|
2724
2796
|
/** @internal */
|
|
2725
2797
|
function parseDateTimeArgs(...args) {
|
|
2726
2798
|
const [arg1, arg2, arg3, arg4] = args;
|
|
2727
|
-
|
|
2799
|
+
const options = {};
|
|
2728
2800
|
let overrides = {};
|
|
2729
2801
|
let value;
|
|
2730
2802
|
if (isString(arg1)) {
|
|
@@ -2766,7 +2838,14 @@ function parseDateTimeArgs(...args) {
|
|
|
2766
2838
|
options.key = arg2;
|
|
2767
2839
|
}
|
|
2768
2840
|
else if (isPlainObject(arg2)) {
|
|
2769
|
-
|
|
2841
|
+
Object.keys(arg2).forEach(key => {
|
|
2842
|
+
if (DATETIME_FORMAT_OPTIONS_KEYS.includes(key)) {
|
|
2843
|
+
overrides[key] = arg2[key];
|
|
2844
|
+
}
|
|
2845
|
+
else {
|
|
2846
|
+
options[key] = arg2[key];
|
|
2847
|
+
}
|
|
2848
|
+
});
|
|
2770
2849
|
}
|
|
2771
2850
|
if (isString(arg3)) {
|
|
2772
2851
|
options.locale = arg3;
|
|
@@ -2865,10 +2944,28 @@ function number(context, ...args) {
|
|
|
2865
2944
|
}
|
|
2866
2945
|
return !part ? formatter.format(value) : formatter.formatToParts(value);
|
|
2867
2946
|
}
|
|
2947
|
+
const NUMBER_FORMAT_OPTIONS_KEYS = [
|
|
2948
|
+
'localeMatcher',
|
|
2949
|
+
'style',
|
|
2950
|
+
'currency',
|
|
2951
|
+
'currencyDisplay',
|
|
2952
|
+
'currencySign',
|
|
2953
|
+
'useGrouping',
|
|
2954
|
+
'minimumIntegerDigits',
|
|
2955
|
+
'minimumFractionDigits',
|
|
2956
|
+
'maximumFractionDigits',
|
|
2957
|
+
'minimumSignificantDigits',
|
|
2958
|
+
'maximumSignificantDigits',
|
|
2959
|
+
'compactDisplay',
|
|
2960
|
+
'notation',
|
|
2961
|
+
'signDisplay',
|
|
2962
|
+
'unit',
|
|
2963
|
+
'unitDisplay'
|
|
2964
|
+
];
|
|
2868
2965
|
/** @internal */
|
|
2869
2966
|
function parseNumberArgs(...args) {
|
|
2870
2967
|
const [arg1, arg2, arg3, arg4] = args;
|
|
2871
|
-
|
|
2968
|
+
const options = {};
|
|
2872
2969
|
let overrides = {};
|
|
2873
2970
|
if (!isNumber(arg1)) {
|
|
2874
2971
|
throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
|
|
@@ -2878,7 +2975,14 @@ function parseNumberArgs(...args) {
|
|
|
2878
2975
|
options.key = arg2;
|
|
2879
2976
|
}
|
|
2880
2977
|
else if (isPlainObject(arg2)) {
|
|
2881
|
-
|
|
2978
|
+
Object.keys(arg2).forEach(key => {
|
|
2979
|
+
if (NUMBER_FORMAT_OPTIONS_KEYS.includes(key)) {
|
|
2980
|
+
overrides[key] = arg2[key];
|
|
2981
|
+
}
|
|
2982
|
+
else {
|
|
2983
|
+
options[key] = arg2[key];
|
|
2984
|
+
}
|
|
2985
|
+
});
|
|
2882
2986
|
}
|
|
2883
2987
|
if (isString(arg3)) {
|
|
2884
2988
|
options.locale = arg3;
|