@intlify/core-base 9.2.0-beta.34 → 9.2.0-beta.37
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
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* core-base v9.2.0-beta.
|
|
2
|
+
* core-base v9.2.0-beta.37
|
|
3
3
|
* (c) 2022 kazuya kawaguchi
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
|
-
import { isObject, isNumber, isString, isFunction, isPlainObject, toDisplayString,
|
|
6
|
+
import { isObject, isNumber, isString, isFunction, isPlainObject, toDisplayString, isArray, format, isBoolean, assign, isRegExp, warn, escapeHtml, inBrowser, mark, measure, generateCodeFrame, generateFormatCacheKey, isEmptyObject, isDate, getGlobalThis } from '@intlify/shared';
|
|
7
7
|
import { defaultOnError, baseCompile, CompileErrorCodes, createCompileError } from '@intlify/message-compiler';
|
|
8
8
|
export { CompileErrorCodes, createCompileError } from '@intlify/message-compiler';
|
|
9
9
|
import { IntlifyDevToolsHooks } from '@intlify/devtools-if';
|
|
@@ -325,7 +325,9 @@ function createMessageContext(options = {}) {
|
|
|
325
325
|
isFunction(options.pluralRules[locale])
|
|
326
326
|
? pluralDefault
|
|
327
327
|
: undefined;
|
|
328
|
-
const plural = (messages) =>
|
|
328
|
+
const plural = (messages) => {
|
|
329
|
+
return messages[pluralRule(pluralIndex, messages.length, orgPluralRule)];
|
|
330
|
+
};
|
|
329
331
|
const _list = options.list || [];
|
|
330
332
|
const list = (index) => _list[index];
|
|
331
333
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -355,13 +357,37 @@ function createMessageContext(options = {}) {
|
|
|
355
357
|
isFunction(options.processor.interpolate)
|
|
356
358
|
? options.processor.interpolate
|
|
357
359
|
: DEFAULT_INTERPOLATE;
|
|
358
|
-
const linked = (key, modifier) => {
|
|
359
|
-
const msg = message(key)(ctx);
|
|
360
|
-
return isString(modifier) ? _modifier(modifier)(msg) : msg;
|
|
361
|
-
};
|
|
362
360
|
const type = isPlainObject(options.processor) && isString(options.processor.type)
|
|
363
361
|
? options.processor.type
|
|
364
362
|
: DEFAULT_MESSAGE_DATA_TYPE;
|
|
363
|
+
const linked = (key, ...args) => {
|
|
364
|
+
const [arg1, arg2] = args;
|
|
365
|
+
let type = 'text';
|
|
366
|
+
let modifier = '';
|
|
367
|
+
if (args.length === 1) {
|
|
368
|
+
if (isObject(arg1)) {
|
|
369
|
+
modifier = arg1.modifier || modifier;
|
|
370
|
+
type = arg1.type || type;
|
|
371
|
+
}
|
|
372
|
+
else if (isString(arg1)) {
|
|
373
|
+
modifier = arg1 || modifier;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
else if (args.length === 2) {
|
|
377
|
+
if (isString(arg1)) {
|
|
378
|
+
modifier = arg1 || modifier;
|
|
379
|
+
}
|
|
380
|
+
if (isString(arg2)) {
|
|
381
|
+
type = arg2 || type;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
let msg = message(key)(ctx);
|
|
385
|
+
// The message in vnode resolved with linked are returned as an array by processor.nomalize
|
|
386
|
+
if (type === 'vnode' && isArray(msg) && modifier) {
|
|
387
|
+
msg = msg[0];
|
|
388
|
+
}
|
|
389
|
+
return modifier ? _modifier(modifier)(msg, type) : msg;
|
|
390
|
+
};
|
|
365
391
|
const ctx = {
|
|
366
392
|
["list" /* LIST */]: list,
|
|
367
393
|
["named" /* NAMED */]: named,
|
|
@@ -540,18 +566,37 @@ function appendItemToChain(chain, target, blocks) {
|
|
|
540
566
|
* Intlify core-base version
|
|
541
567
|
* @internal
|
|
542
568
|
*/
|
|
543
|
-
const VERSION = '9.2.0-beta.
|
|
569
|
+
const VERSION = '9.2.0-beta.37';
|
|
544
570
|
const NOT_REOSLVED = -1;
|
|
545
571
|
const DEFAULT_LOCALE = 'en-US';
|
|
546
572
|
const MISSING_RESOLVE_VALUE = '';
|
|
573
|
+
const capitalize = (str) => `${str.charAt(0).toLocaleUpperCase()}${str.substr(1)}`;
|
|
547
574
|
function getDefaultLinkedModifiers() {
|
|
548
575
|
return {
|
|
549
|
-
upper: (val) =>
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
576
|
+
upper: (val, type) => {
|
|
577
|
+
// prettier-ignore
|
|
578
|
+
return type === 'text' && isString(val)
|
|
579
|
+
? val.toUpperCase()
|
|
580
|
+
: type === 'vnode' && isObject(val) && '__v_isVNode' in val
|
|
581
|
+
? val.children.toUpperCase()
|
|
582
|
+
: val;
|
|
583
|
+
},
|
|
584
|
+
lower: (val, type) => {
|
|
585
|
+
// prettier-ignore
|
|
586
|
+
return type === 'text' && isString(val)
|
|
587
|
+
? val.toLowerCase()
|
|
588
|
+
: type === 'vnode' && isObject(val) && '__v_isVNode' in val
|
|
589
|
+
? val.children.toLowerCase()
|
|
590
|
+
: val;
|
|
591
|
+
},
|
|
592
|
+
capitalize: (val, type) => {
|
|
593
|
+
// prettier-ignore
|
|
594
|
+
return (type === 'text' && isString(val)
|
|
595
|
+
? capitalize(val)
|
|
596
|
+
: type === 'vnode' && isObject(val) && '__v_isVNode' in val
|
|
597
|
+
? capitalize(val.children)
|
|
598
|
+
: val);
|
|
599
|
+
}
|
|
555
600
|
};
|
|
556
601
|
}
|
|
557
602
|
let _compiler;
|
|
@@ -887,7 +932,9 @@ function translate(context, ...args) {
|
|
|
887
932
|
const msgContext = createMessageContext(ctxOptions);
|
|
888
933
|
const messaged = evaluateMessage(context, msg, msgContext);
|
|
889
934
|
// if use post translation option, proceed it with handler
|
|
890
|
-
const ret = postTranslation
|
|
935
|
+
const ret = postTranslation
|
|
936
|
+
? postTranslation(messaged, key)
|
|
937
|
+
: messaged;
|
|
891
938
|
// NOTE: experimental !!
|
|
892
939
|
if ((process.env.NODE_ENV !== 'production') || __INTLIFY_PROD_DEVTOOLS__) {
|
|
893
940
|
// prettier-ignore
|
|
@@ -1218,7 +1265,7 @@ function datetime(context, ...args) {
|
|
|
1218
1265
|
const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
1219
1266
|
fallbackLocale, locale);
|
|
1220
1267
|
if (!isString(key) || key === '') {
|
|
1221
|
-
return new Intl.DateTimeFormat(locale).format(value);
|
|
1268
|
+
return new Intl.DateTimeFormat(locale, overrides).format(value);
|
|
1222
1269
|
}
|
|
1223
1270
|
// resolve format
|
|
1224
1271
|
let datetimeFormat = {};
|
|
@@ -1274,9 +1321,32 @@ function datetime(context, ...args) {
|
|
|
1274
1321
|
return !part ? formatter.format(value) : formatter.formatToParts(value);
|
|
1275
1322
|
}
|
|
1276
1323
|
/** @internal */
|
|
1324
|
+
const DATETIME_FORMAT_OPTIONS_KEYS = [
|
|
1325
|
+
'localeMatcher',
|
|
1326
|
+
'weekday',
|
|
1327
|
+
'era',
|
|
1328
|
+
'year',
|
|
1329
|
+
'month',
|
|
1330
|
+
'day',
|
|
1331
|
+
'hour',
|
|
1332
|
+
'minute',
|
|
1333
|
+
'second',
|
|
1334
|
+
'timeZoneName',
|
|
1335
|
+
'formatMatcher',
|
|
1336
|
+
'hour12',
|
|
1337
|
+
'timeZone',
|
|
1338
|
+
'dateStyle',
|
|
1339
|
+
'timeStyle',
|
|
1340
|
+
'calendar',
|
|
1341
|
+
'dayPeriod',
|
|
1342
|
+
'numberingSystem',
|
|
1343
|
+
'hourCycle',
|
|
1344
|
+
'fractionalSecondDigits'
|
|
1345
|
+
];
|
|
1346
|
+
/** @internal */
|
|
1277
1347
|
function parseDateTimeArgs(...args) {
|
|
1278
1348
|
const [arg1, arg2, arg3, arg4] = args;
|
|
1279
|
-
|
|
1349
|
+
const options = {};
|
|
1280
1350
|
let overrides = {};
|
|
1281
1351
|
let value;
|
|
1282
1352
|
if (isString(arg1)) {
|
|
@@ -1318,7 +1388,14 @@ function parseDateTimeArgs(...args) {
|
|
|
1318
1388
|
options.key = arg2;
|
|
1319
1389
|
}
|
|
1320
1390
|
else if (isPlainObject(arg2)) {
|
|
1321
|
-
|
|
1391
|
+
Object.keys(arg2).forEach(key => {
|
|
1392
|
+
if (DATETIME_FORMAT_OPTIONS_KEYS.includes(key)) {
|
|
1393
|
+
overrides[key] = arg2[key];
|
|
1394
|
+
}
|
|
1395
|
+
else {
|
|
1396
|
+
options[key] = arg2[key];
|
|
1397
|
+
}
|
|
1398
|
+
});
|
|
1322
1399
|
}
|
|
1323
1400
|
if (isString(arg3)) {
|
|
1324
1401
|
options.locale = arg3;
|
|
@@ -1363,7 +1440,7 @@ function number(context, ...args) {
|
|
|
1363
1440
|
const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
1364
1441
|
fallbackLocale, locale);
|
|
1365
1442
|
if (!isString(key) || key === '') {
|
|
1366
|
-
return new Intl.NumberFormat(locale).format(value);
|
|
1443
|
+
return new Intl.NumberFormat(locale, overrides).format(value);
|
|
1367
1444
|
}
|
|
1368
1445
|
// resolve format
|
|
1369
1446
|
let numberFormat = {};
|
|
@@ -1419,9 +1496,32 @@ function number(context, ...args) {
|
|
|
1419
1496
|
return !part ? formatter.format(value) : formatter.formatToParts(value);
|
|
1420
1497
|
}
|
|
1421
1498
|
/** @internal */
|
|
1499
|
+
const NUMBER_FORMAT_OPTIONS_KEYS = [
|
|
1500
|
+
'localeMatcher',
|
|
1501
|
+
'style',
|
|
1502
|
+
'currency',
|
|
1503
|
+
'currencyDisplay',
|
|
1504
|
+
'currencySign',
|
|
1505
|
+
'useGrouping',
|
|
1506
|
+
'minimumIntegerDigits',
|
|
1507
|
+
'minimumFractionDigits',
|
|
1508
|
+
'maximumFractionDigits',
|
|
1509
|
+
'minimumSignificantDigits',
|
|
1510
|
+
'maximumSignificantDigits',
|
|
1511
|
+
'compactDisplay',
|
|
1512
|
+
'notation',
|
|
1513
|
+
'signDisplay',
|
|
1514
|
+
'unit',
|
|
1515
|
+
'unitDisplay',
|
|
1516
|
+
'roundingMode',
|
|
1517
|
+
'roundingPriority',
|
|
1518
|
+
'roundingIncrement',
|
|
1519
|
+
'trailingZeroDisplay'
|
|
1520
|
+
];
|
|
1521
|
+
/** @internal */
|
|
1422
1522
|
function parseNumberArgs(...args) {
|
|
1423
1523
|
const [arg1, arg2, arg3, arg4] = args;
|
|
1424
|
-
|
|
1524
|
+
const options = {};
|
|
1425
1525
|
let overrides = {};
|
|
1426
1526
|
if (!isNumber(arg1)) {
|
|
1427
1527
|
throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
|
|
@@ -1431,7 +1531,14 @@ function parseNumberArgs(...args) {
|
|
|
1431
1531
|
options.key = arg2;
|
|
1432
1532
|
}
|
|
1433
1533
|
else if (isPlainObject(arg2)) {
|
|
1434
|
-
|
|
1534
|
+
Object.keys(arg2).forEach(key => {
|
|
1535
|
+
if (NUMBER_FORMAT_OPTIONS_KEYS.includes(key)) {
|
|
1536
|
+
overrides[key] = arg2[key];
|
|
1537
|
+
}
|
|
1538
|
+
else {
|
|
1539
|
+
options[key] = arg2[key];
|
|
1540
|
+
}
|
|
1541
|
+
});
|
|
1435
1542
|
}
|
|
1436
1543
|
if (isString(arg3)) {
|
|
1437
1544
|
options.locale = arg3;
|
|
@@ -1463,4 +1570,4 @@ function clearNumberFormat(ctx, locale, format) {
|
|
|
1463
1570
|
}
|
|
1464
1571
|
}
|
|
1465
1572
|
|
|
1466
|
-
export { CoreErrorCodes, CoreWarnCodes, DEFAULT_LOCALE, DEFAULT_MESSAGE_DATA_TYPE, MISSING_RESOLVE_VALUE, NOT_REOSLVED, VERSION, clearCompileCache, clearDateTimeFormat, clearNumberFormat, compileToFunction, createCoreContext, createCoreError, createMessageContext, datetime, fallbackWithLocaleChain, fallbackWithSimple, getAdditionalMeta, getDevToolsHook, getFallbackContext, getWarnMessage, handleMissing, initI18nDevTools, isMessageFunction, isTranslateFallbackWarn, isTranslateMissingWarn, number, parse, parseDateTimeArgs, parseNumberArgs, parseTranslateArgs, registerLocaleFallbacker, registerMessageCompiler, registerMessageResolver, resolveValue, resolveWithKeyValue, setAdditionalMeta, setDevToolsHook, setFallbackContext, translate, translateDevTools, updateFallbackLocale };
|
|
1573
|
+
export { CoreErrorCodes, CoreWarnCodes, DATETIME_FORMAT_OPTIONS_KEYS, DEFAULT_LOCALE, DEFAULT_MESSAGE_DATA_TYPE, MISSING_RESOLVE_VALUE, NOT_REOSLVED, NUMBER_FORMAT_OPTIONS_KEYS, VERSION, clearCompileCache, clearDateTimeFormat, clearNumberFormat, compileToFunction, createCoreContext, createCoreError, createMessageContext, datetime, fallbackWithLocaleChain, fallbackWithSimple, getAdditionalMeta, getDevToolsHook, getFallbackContext, getWarnMessage, handleMissing, initI18nDevTools, isMessageFunction, isTranslateFallbackWarn, isTranslateMissingWarn, number, parse, parseDateTimeArgs, parseNumberArgs, parseTranslateArgs, registerLocaleFallbacker, registerMessageCompiler, registerMessageResolver, resolveValue, resolveWithKeyValue, setAdditionalMeta, setDevToolsHook, setFallbackContext, translate, translateDevTools, updateFallbackLocale };
|
package/dist/core-base.global.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* core-base v9.2.0-beta.
|
|
2
|
+
* core-base v9.2.0-beta.37
|
|
3
3
|
* (c) 2022 kazuya kawaguchi
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -462,6 +462,16 @@ var IntlifyCoreBase = (function (exports) {
|
|
|
462
462
|
scnr.resetPeek();
|
|
463
463
|
return ret;
|
|
464
464
|
}
|
|
465
|
+
function detectModuloStart(scnr) {
|
|
466
|
+
const spaces = peekSpaces(scnr);
|
|
467
|
+
const ret = scnr.currentPeek() === "%" /* Modulo */ &&
|
|
468
|
+
scnr.peek() === "{" /* BraceLeft */;
|
|
469
|
+
scnr.resetPeek();
|
|
470
|
+
return {
|
|
471
|
+
isModulo: ret,
|
|
472
|
+
hasSpace: spaces.length > 0
|
|
473
|
+
};
|
|
474
|
+
}
|
|
465
475
|
function isTextStart(scnr, reset = true) {
|
|
466
476
|
const fn = (hasSpace = false, prev = '', detectModulo = false) => {
|
|
467
477
|
const ch = scnr.currentPeek();
|
|
@@ -543,6 +553,15 @@ var IntlifyCoreBase = (function (exports) {
|
|
|
543
553
|
}
|
|
544
554
|
return num;
|
|
545
555
|
}
|
|
556
|
+
function readModulo(scnr) {
|
|
557
|
+
skipSpaces(scnr);
|
|
558
|
+
const ch = scnr.currentChar();
|
|
559
|
+
if (ch !== "%" /* Modulo */) {
|
|
560
|
+
emitError(CompileErrorCodes.EXPECTED_TOKEN, currentPosition(), 0, ch);
|
|
561
|
+
}
|
|
562
|
+
scnr.next();
|
|
563
|
+
return "%" /* Modulo */;
|
|
564
|
+
}
|
|
546
565
|
function readText(scnr) {
|
|
547
566
|
let buf = '';
|
|
548
567
|
while (true) {
|
|
@@ -889,13 +908,15 @@ var IntlifyCoreBase = (function (exports) {
|
|
|
889
908
|
context.inLinked = false;
|
|
890
909
|
return token;
|
|
891
910
|
}
|
|
911
|
+
const { isModulo, hasSpace } = detectModuloStart(scnr);
|
|
912
|
+
if (isModulo) {
|
|
913
|
+
return hasSpace
|
|
914
|
+
? getToken(context, 0 /* Text */, readText(scnr))
|
|
915
|
+
: getToken(context, 4 /* Modulo */, readModulo(scnr));
|
|
916
|
+
}
|
|
892
917
|
if (isTextStart(scnr)) {
|
|
893
918
|
return getToken(context, 0 /* Text */, readText(scnr));
|
|
894
919
|
}
|
|
895
|
-
if (ch === "%" /* Modulo */) {
|
|
896
|
-
scnr.next();
|
|
897
|
-
return getToken(context, 4 /* Modulo */, "%" /* Modulo */);
|
|
898
|
-
}
|
|
899
920
|
break;
|
|
900
921
|
}
|
|
901
922
|
return token;
|
|
@@ -1249,6 +1270,7 @@ var IntlifyCoreBase = (function (exports) {
|
|
|
1249
1270
|
const linked = node;
|
|
1250
1271
|
traverseNode(linked.key, transformer);
|
|
1251
1272
|
transformer.helper("linked" /* LINKED */);
|
|
1273
|
+
transformer.helper("type" /* TYPE */);
|
|
1252
1274
|
break;
|
|
1253
1275
|
case 5 /* List */:
|
|
1254
1276
|
transformer.helper("interpolate" /* INTERPOLATE */);
|
|
@@ -1325,6 +1347,10 @@ var IntlifyCoreBase = (function (exports) {
|
|
|
1325
1347
|
if (node.modifier) {
|
|
1326
1348
|
generator.push(`, `);
|
|
1327
1349
|
generateNode(generator, node.modifier);
|
|
1350
|
+
generator.push(`, _type`);
|
|
1351
|
+
}
|
|
1352
|
+
else {
|
|
1353
|
+
generator.push(`, undefined, _type`);
|
|
1328
1354
|
}
|
|
1329
1355
|
generator.push(`)`);
|
|
1330
1356
|
}
|
|
@@ -1776,7 +1802,9 @@ var IntlifyCoreBase = (function (exports) {
|
|
|
1776
1802
|
isFunction(options.pluralRules[locale])
|
|
1777
1803
|
? pluralDefault
|
|
1778
1804
|
: undefined;
|
|
1779
|
-
const plural = (messages) =>
|
|
1805
|
+
const plural = (messages) => {
|
|
1806
|
+
return messages[pluralRule(pluralIndex, messages.length, orgPluralRule)];
|
|
1807
|
+
};
|
|
1780
1808
|
const _list = options.list || [];
|
|
1781
1809
|
const list = (index) => _list[index];
|
|
1782
1810
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -1806,13 +1834,37 @@ var IntlifyCoreBase = (function (exports) {
|
|
|
1806
1834
|
isFunction(options.processor.interpolate)
|
|
1807
1835
|
? options.processor.interpolate
|
|
1808
1836
|
: DEFAULT_INTERPOLATE;
|
|
1809
|
-
const linked = (key, modifier) => {
|
|
1810
|
-
const msg = message(key)(ctx);
|
|
1811
|
-
return isString(modifier) ? _modifier(modifier)(msg) : msg;
|
|
1812
|
-
};
|
|
1813
1837
|
const type = isPlainObject(options.processor) && isString(options.processor.type)
|
|
1814
1838
|
? options.processor.type
|
|
1815
1839
|
: DEFAULT_MESSAGE_DATA_TYPE;
|
|
1840
|
+
const linked = (key, ...args) => {
|
|
1841
|
+
const [arg1, arg2] = args;
|
|
1842
|
+
let type = 'text';
|
|
1843
|
+
let modifier = '';
|
|
1844
|
+
if (args.length === 1) {
|
|
1845
|
+
if (isObject(arg1)) {
|
|
1846
|
+
modifier = arg1.modifier || modifier;
|
|
1847
|
+
type = arg1.type || type;
|
|
1848
|
+
}
|
|
1849
|
+
else if (isString(arg1)) {
|
|
1850
|
+
modifier = arg1 || modifier;
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
else if (args.length === 2) {
|
|
1854
|
+
if (isString(arg1)) {
|
|
1855
|
+
modifier = arg1 || modifier;
|
|
1856
|
+
}
|
|
1857
|
+
if (isString(arg2)) {
|
|
1858
|
+
type = arg2 || type;
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
let msg = message(key)(ctx);
|
|
1862
|
+
// The message in vnode resolved with linked are returned as an array by processor.nomalize
|
|
1863
|
+
if (type === 'vnode' && isArray(msg) && modifier) {
|
|
1864
|
+
msg = msg[0];
|
|
1865
|
+
}
|
|
1866
|
+
return modifier ? _modifier(modifier)(msg, type) : msg;
|
|
1867
|
+
};
|
|
1816
1868
|
const ctx = {
|
|
1817
1869
|
["list" /* LIST */]: list,
|
|
1818
1870
|
["named" /* NAMED */]: named,
|
|
@@ -1996,18 +2048,37 @@ var IntlifyCoreBase = (function (exports) {
|
|
|
1996
2048
|
* Intlify core-base version
|
|
1997
2049
|
* @internal
|
|
1998
2050
|
*/
|
|
1999
|
-
const VERSION = '9.2.0-beta.
|
|
2051
|
+
const VERSION = '9.2.0-beta.37';
|
|
2000
2052
|
const NOT_REOSLVED = -1;
|
|
2001
2053
|
const DEFAULT_LOCALE = 'en-US';
|
|
2002
2054
|
const MISSING_RESOLVE_VALUE = '';
|
|
2055
|
+
const capitalize = (str) => `${str.charAt(0).toLocaleUpperCase()}${str.substr(1)}`;
|
|
2003
2056
|
function getDefaultLinkedModifiers() {
|
|
2004
2057
|
return {
|
|
2005
|
-
upper: (val) =>
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2058
|
+
upper: (val, type) => {
|
|
2059
|
+
// prettier-ignore
|
|
2060
|
+
return type === 'text' && isString(val)
|
|
2061
|
+
? val.toUpperCase()
|
|
2062
|
+
: type === 'vnode' && isObject(val) && '__v_isVNode' in val
|
|
2063
|
+
? val.children.toUpperCase()
|
|
2064
|
+
: val;
|
|
2065
|
+
},
|
|
2066
|
+
lower: (val, type) => {
|
|
2067
|
+
// prettier-ignore
|
|
2068
|
+
return type === 'text' && isString(val)
|
|
2069
|
+
? val.toLowerCase()
|
|
2070
|
+
: type === 'vnode' && isObject(val) && '__v_isVNode' in val
|
|
2071
|
+
? val.children.toLowerCase()
|
|
2072
|
+
: val;
|
|
2073
|
+
},
|
|
2074
|
+
capitalize: (val, type) => {
|
|
2075
|
+
// prettier-ignore
|
|
2076
|
+
return (type === 'text' && isString(val)
|
|
2077
|
+
? capitalize(val)
|
|
2078
|
+
: type === 'vnode' && isObject(val) && '__v_isVNode' in val
|
|
2079
|
+
? capitalize(val.children)
|
|
2080
|
+
: val);
|
|
2081
|
+
}
|
|
2011
2082
|
};
|
|
2012
2083
|
}
|
|
2013
2084
|
let _compiler;
|
|
@@ -2343,7 +2414,9 @@ var IntlifyCoreBase = (function (exports) {
|
|
|
2343
2414
|
const msgContext = createMessageContext(ctxOptions);
|
|
2344
2415
|
const messaged = evaluateMessage(context, msg, msgContext);
|
|
2345
2416
|
// if use post translation option, proceed it with handler
|
|
2346
|
-
const ret = postTranslation
|
|
2417
|
+
const ret = postTranslation
|
|
2418
|
+
? postTranslation(messaged, key)
|
|
2419
|
+
: messaged;
|
|
2347
2420
|
// NOTE: experimental !!
|
|
2348
2421
|
{
|
|
2349
2422
|
// prettier-ignore
|
|
@@ -2670,7 +2743,7 @@ var IntlifyCoreBase = (function (exports) {
|
|
|
2670
2743
|
const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
2671
2744
|
fallbackLocale, locale);
|
|
2672
2745
|
if (!isString(key) || key === '') {
|
|
2673
|
-
return new Intl.DateTimeFormat(locale).format(value);
|
|
2746
|
+
return new Intl.DateTimeFormat(locale, overrides).format(value);
|
|
2674
2747
|
}
|
|
2675
2748
|
// resolve format
|
|
2676
2749
|
let datetimeFormat = {};
|
|
@@ -2725,9 +2798,32 @@ var IntlifyCoreBase = (function (exports) {
|
|
|
2725
2798
|
return !part ? formatter.format(value) : formatter.formatToParts(value);
|
|
2726
2799
|
}
|
|
2727
2800
|
/** @internal */
|
|
2801
|
+
const DATETIME_FORMAT_OPTIONS_KEYS = [
|
|
2802
|
+
'localeMatcher',
|
|
2803
|
+
'weekday',
|
|
2804
|
+
'era',
|
|
2805
|
+
'year',
|
|
2806
|
+
'month',
|
|
2807
|
+
'day',
|
|
2808
|
+
'hour',
|
|
2809
|
+
'minute',
|
|
2810
|
+
'second',
|
|
2811
|
+
'timeZoneName',
|
|
2812
|
+
'formatMatcher',
|
|
2813
|
+
'hour12',
|
|
2814
|
+
'timeZone',
|
|
2815
|
+
'dateStyle',
|
|
2816
|
+
'timeStyle',
|
|
2817
|
+
'calendar',
|
|
2818
|
+
'dayPeriod',
|
|
2819
|
+
'numberingSystem',
|
|
2820
|
+
'hourCycle',
|
|
2821
|
+
'fractionalSecondDigits'
|
|
2822
|
+
];
|
|
2823
|
+
/** @internal */
|
|
2728
2824
|
function parseDateTimeArgs(...args) {
|
|
2729
2825
|
const [arg1, arg2, arg3, arg4] = args;
|
|
2730
|
-
|
|
2826
|
+
const options = {};
|
|
2731
2827
|
let overrides = {};
|
|
2732
2828
|
let value;
|
|
2733
2829
|
if (isString(arg1)) {
|
|
@@ -2769,7 +2865,14 @@ var IntlifyCoreBase = (function (exports) {
|
|
|
2769
2865
|
options.key = arg2;
|
|
2770
2866
|
}
|
|
2771
2867
|
else if (isPlainObject(arg2)) {
|
|
2772
|
-
|
|
2868
|
+
Object.keys(arg2).forEach(key => {
|
|
2869
|
+
if (DATETIME_FORMAT_OPTIONS_KEYS.includes(key)) {
|
|
2870
|
+
overrides[key] = arg2[key];
|
|
2871
|
+
}
|
|
2872
|
+
else {
|
|
2873
|
+
options[key] = arg2[key];
|
|
2874
|
+
}
|
|
2875
|
+
});
|
|
2773
2876
|
}
|
|
2774
2877
|
if (isString(arg3)) {
|
|
2775
2878
|
options.locale = arg3;
|
|
@@ -2814,7 +2917,7 @@ var IntlifyCoreBase = (function (exports) {
|
|
|
2814
2917
|
const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
2815
2918
|
fallbackLocale, locale);
|
|
2816
2919
|
if (!isString(key) || key === '') {
|
|
2817
|
-
return new Intl.NumberFormat(locale).format(value);
|
|
2920
|
+
return new Intl.NumberFormat(locale, overrides).format(value);
|
|
2818
2921
|
}
|
|
2819
2922
|
// resolve format
|
|
2820
2923
|
let numberFormat = {};
|
|
@@ -2869,9 +2972,32 @@ var IntlifyCoreBase = (function (exports) {
|
|
|
2869
2972
|
return !part ? formatter.format(value) : formatter.formatToParts(value);
|
|
2870
2973
|
}
|
|
2871
2974
|
/** @internal */
|
|
2975
|
+
const NUMBER_FORMAT_OPTIONS_KEYS = [
|
|
2976
|
+
'localeMatcher',
|
|
2977
|
+
'style',
|
|
2978
|
+
'currency',
|
|
2979
|
+
'currencyDisplay',
|
|
2980
|
+
'currencySign',
|
|
2981
|
+
'useGrouping',
|
|
2982
|
+
'minimumIntegerDigits',
|
|
2983
|
+
'minimumFractionDigits',
|
|
2984
|
+
'maximumFractionDigits',
|
|
2985
|
+
'minimumSignificantDigits',
|
|
2986
|
+
'maximumSignificantDigits',
|
|
2987
|
+
'compactDisplay',
|
|
2988
|
+
'notation',
|
|
2989
|
+
'signDisplay',
|
|
2990
|
+
'unit',
|
|
2991
|
+
'unitDisplay',
|
|
2992
|
+
'roundingMode',
|
|
2993
|
+
'roundingPriority',
|
|
2994
|
+
'roundingIncrement',
|
|
2995
|
+
'trailingZeroDisplay'
|
|
2996
|
+
];
|
|
2997
|
+
/** @internal */
|
|
2872
2998
|
function parseNumberArgs(...args) {
|
|
2873
2999
|
const [arg1, arg2, arg3, arg4] = args;
|
|
2874
|
-
|
|
3000
|
+
const options = {};
|
|
2875
3001
|
let overrides = {};
|
|
2876
3002
|
if (!isNumber(arg1)) {
|
|
2877
3003
|
throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
|
|
@@ -2881,7 +3007,14 @@ var IntlifyCoreBase = (function (exports) {
|
|
|
2881
3007
|
options.key = arg2;
|
|
2882
3008
|
}
|
|
2883
3009
|
else if (isPlainObject(arg2)) {
|
|
2884
|
-
|
|
3010
|
+
Object.keys(arg2).forEach(key => {
|
|
3011
|
+
if (NUMBER_FORMAT_OPTIONS_KEYS.includes(key)) {
|
|
3012
|
+
overrides[key] = arg2[key];
|
|
3013
|
+
}
|
|
3014
|
+
else {
|
|
3015
|
+
options[key] = arg2[key];
|
|
3016
|
+
}
|
|
3017
|
+
});
|
|
2885
3018
|
}
|
|
2886
3019
|
if (isString(arg3)) {
|
|
2887
3020
|
options.locale = arg3;
|
|
@@ -2909,10 +3042,12 @@ var IntlifyCoreBase = (function (exports) {
|
|
|
2909
3042
|
exports.CompileErrorCodes = CompileErrorCodes;
|
|
2910
3043
|
exports.CoreErrorCodes = CoreErrorCodes;
|
|
2911
3044
|
exports.CoreWarnCodes = CoreWarnCodes;
|
|
3045
|
+
exports.DATETIME_FORMAT_OPTIONS_KEYS = DATETIME_FORMAT_OPTIONS_KEYS;
|
|
2912
3046
|
exports.DEFAULT_LOCALE = DEFAULT_LOCALE;
|
|
2913
3047
|
exports.DEFAULT_MESSAGE_DATA_TYPE = DEFAULT_MESSAGE_DATA_TYPE;
|
|
2914
3048
|
exports.MISSING_RESOLVE_VALUE = MISSING_RESOLVE_VALUE;
|
|
2915
3049
|
exports.NOT_REOSLVED = NOT_REOSLVED;
|
|
3050
|
+
exports.NUMBER_FORMAT_OPTIONS_KEYS = NUMBER_FORMAT_OPTIONS_KEYS;
|
|
2916
3051
|
exports.VERSION = VERSION;
|
|
2917
3052
|
exports.clearCompileCache = clearCompileCache;
|
|
2918
3053
|
exports.clearDateTimeFormat = clearDateTimeFormat;
|