@intlify/core 12.0.0-alpha.6 → 12.0.0-alpha.8
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.esm-browser.js +35 -54
- package/dist/core.esm-browser.prod.js +348 -351
- package/dist/core.global.js +35 -54
- package/dist/core.global.prod.js +249 -252
- package/dist/core.js +1 -1
- package/dist/core.node.js +1 -1
- package/dist/core.runtime.esm-browser.js +29 -42
- package/dist/core.runtime.esm-browser.prod.js +201 -204
- package/dist/core.runtime.global.js +29 -42
- package/dist/core.runtime.global.prod.js +183 -186
- package/dist/core.runtime.js +3 -5
- package/dist/core.runtime.node.js +3 -5
- package/package.json +3 -3
package/dist/core.js
CHANGED
package/dist/core.node.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @intlify/core v12.0.0-alpha.
|
|
2
|
+
* @intlify/core v12.0.0-alpha.8
|
|
3
3
|
* (c) 2016-present kazuya kawaguchi and contributors
|
|
4
4
|
* @license MIT
|
|
5
5
|
**/
|
|
6
|
-
|
|
6
|
+
// packages/shared/src/utils.ts
|
|
7
7
|
/**
|
|
8
8
|
* Original Utilities
|
|
9
9
|
* written by kazuya kawaguchi
|
|
@@ -123,8 +123,7 @@ function generateCodeFrame(source, start = 0, end = source.length) {
|
|
|
123
123
|
}
|
|
124
124
|
return res.join("\n");
|
|
125
125
|
}
|
|
126
|
-
|
|
127
|
-
//#region packages/shared/src/warn.ts
|
|
126
|
+
// packages/shared/src/warn.ts
|
|
128
127
|
function warn(msg, err) {
|
|
129
128
|
if (typeof console !== "undefined") {
|
|
130
129
|
console.warn(`[intlify] ` + msg);
|
|
@@ -139,8 +138,7 @@ function warnOnce(msg) {
|
|
|
139
138
|
warn(msg);
|
|
140
139
|
}
|
|
141
140
|
}
|
|
142
|
-
|
|
143
|
-
//#region packages/shared/src/sanitize.ts
|
|
141
|
+
// packages/shared/src/sanitize.ts
|
|
144
142
|
function escapeHtml(rawText) {
|
|
145
143
|
return rawText.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'").replace(/\//g, "/").replace(/=/g, "=");
|
|
146
144
|
}
|
|
@@ -148,7 +146,7 @@ function escapeAttributeValue(value) {
|
|
|
148
146
|
return value.replace(/&(?![a-z0-9#]{2,6};)/gi, "&").replace(/"/g, """).replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">");
|
|
149
147
|
}
|
|
150
148
|
const javascriptSchemePattern = /^javascript:/i;
|
|
151
|
-
const urlAttributePattern = /^(?:href|src|action|formaction)$/i;
|
|
149
|
+
const urlAttributePattern = /^(?:href|xlink:href|src|action|formaction)$/i;
|
|
152
150
|
const numericCharacterReferencePattern = /&#(?:x([0-9a-f]+)|(\d+));?/gi;
|
|
153
151
|
const namedWhitespaceCharacterReferencePattern = /&(?:Tab|NewLine);/g;
|
|
154
152
|
const colonCharacterReferencePattern = /:?/gi;
|
|
@@ -157,7 +155,9 @@ const eventHandlerPattern = /(?:^|[\s"'<>/])on\w+\s*=\s*["']?[^"'>]+["']?/i;
|
|
|
157
155
|
const eventHandlerAttributePattern = /(^|[\s"'<>/])on(\w+\s*=)/gi;
|
|
158
156
|
const srcdocPattern = /(?:^|[\s"'<>/])srcdoc\s*=/i;
|
|
159
157
|
const srcdocAttributePattern = /(^|[\s"'<>/])s(rcdoc\s*=)/gi;
|
|
160
|
-
const
|
|
158
|
+
const dangerousElementPattern = /<(?:base|animate|set)(?=[\s/>]|$)/i;
|
|
159
|
+
const dangerousElementStartTagPattern = /<(base|animate|set)(?=[\s/>]|$)/gi;
|
|
160
|
+
const unquotedUrlAttributePattern = /(^|[\s"'<>/])((?:href|xlink:href|src|action|formaction)\s*=\s*)([^\s"'=<>`]+)/gi;
|
|
161
161
|
function decodeNumericCharacterReference(match, hex, decimal) {
|
|
162
162
|
const digits = hex || decimal;
|
|
163
163
|
if (!digits) return match;
|
|
@@ -216,11 +216,14 @@ function sanitizeTranslatedHtml(html) {
|
|
|
216
216
|
warn("Potentially dangerous srcdoc attribute detected in translation. Consider removing srcdoc from your translation messages.");
|
|
217
217
|
html = html.replace(srcdocAttributePattern, "$1s$2");
|
|
218
218
|
}
|
|
219
|
+
if (dangerousElementPattern.test(html)) {
|
|
220
|
+
warn("Potentially dangerous element (<base>, <animate> or <set>) detected in translation. Consider removing it from your translation messages.");
|
|
221
|
+
html = html.replace(dangerousElementStartTagPattern, "<$1");
|
|
222
|
+
}
|
|
219
223
|
html = html.replace(unquotedUrlAttributePattern, (match, boundary, prefix, attrValue) => hasJavascriptScheme(attrValue) ? `${boundary}${prefix}about:blank` : match);
|
|
220
224
|
return html;
|
|
221
225
|
}
|
|
222
|
-
|
|
223
|
-
//#region packages/shared/src/messages.ts
|
|
226
|
+
// packages/shared/src/messages.ts
|
|
224
227
|
const isNotObjectOrIsArray = (val) => !isObject(val) || isArray(val);
|
|
225
228
|
function deepCopy(src, des) {
|
|
226
229
|
if (isNotObjectOrIsArray(src) || isNotObjectOrIsArray(des) || des === Object.prototype) throw new Error("Invalid value");
|
|
@@ -250,8 +253,7 @@ function deepCopy(src, des) {
|
|
|
250
253
|
}
|
|
251
254
|
}
|
|
252
255
|
}
|
|
253
|
-
|
|
254
|
-
//#region packages/message-compiler/src/errors.ts
|
|
256
|
+
// packages/message-compiler/src/errors.ts
|
|
255
257
|
const CompileErrorCodes = {
|
|
256
258
|
EXPECTED_TOKEN: 1,
|
|
257
259
|
INVALID_TOKEN_IN_PLACEHOLDER: 2,
|
|
@@ -298,8 +300,7 @@ function createCompileError(code, loc, options = {}) {
|
|
|
298
300
|
error.domain = domain;
|
|
299
301
|
return error;
|
|
300
302
|
}
|
|
301
|
-
|
|
302
|
-
//#region packages/core-base/src/ast.ts
|
|
303
|
+
// packages/core-base/src/ast.ts
|
|
303
304
|
function isMessageAST(val) {
|
|
304
305
|
return isObject(val) && resolveType(val) === 0 && (hasOwn(val, "b") || hasOwn(val, "body"));
|
|
305
306
|
}
|
|
@@ -359,8 +360,7 @@ const AST_NODE_PROPS_KEYS = [
|
|
|
359
360
|
function createUnhandleNodeError(type) {
|
|
360
361
|
return /* @__PURE__ */ new Error(`unhandled node type: ${type}`);
|
|
361
362
|
}
|
|
362
|
-
|
|
363
|
-
//#region packages/core-base/src/format.ts
|
|
363
|
+
// packages/core-base/src/format.ts
|
|
364
364
|
function format(ast) {
|
|
365
365
|
return (ctx) => formatParts(ctx, ast);
|
|
366
366
|
}
|
|
@@ -408,8 +408,7 @@ function formatMessagePart(ctx, node) {
|
|
|
408
408
|
default: throw new Error(`unhandled node on format message part: ${type}`);
|
|
409
409
|
}
|
|
410
410
|
}
|
|
411
|
-
|
|
412
|
-
//#region packages/core-base/src/compilation.ts
|
|
411
|
+
// packages/core-base/src/compilation.ts
|
|
413
412
|
let compileCache = create();
|
|
414
413
|
function clearCompileCache() {
|
|
415
414
|
compileCache = create();
|
|
@@ -429,8 +428,7 @@ function compile(message, context) {
|
|
|
429
428
|
} else return format(message);
|
|
430
429
|
}
|
|
431
430
|
}
|
|
432
|
-
|
|
433
|
-
//#region packages/core-base/src/errors.ts
|
|
431
|
+
// packages/core-base/src/errors.ts
|
|
434
432
|
const CoreErrorCodes = {
|
|
435
433
|
INVALID_ARGUMENT: 17,
|
|
436
434
|
INVALID_DATE_ARGUMENT: 18,
|
|
@@ -452,8 +450,7 @@ const errorMessages = {
|
|
|
452
450
|
[CoreErrorCodes.NOT_SUPPORT_LOCALE_ASYNC_FUNCTION]: "cannot support async function",
|
|
453
451
|
[CoreErrorCodes.NOT_SUPPORT_LOCALE_TYPE]: "cannot support locale type"
|
|
454
452
|
};
|
|
455
|
-
|
|
456
|
-
//#region packages/core-base/src/fallbacker.ts
|
|
453
|
+
// packages/core-base/src/fallbacker.ts
|
|
457
454
|
/** @internal */
|
|
458
455
|
function getLocale(context, options) {
|
|
459
456
|
return options.locale != null ? resolveLocale(options.locale) : resolveLocale(context.locale);
|
|
@@ -569,8 +566,7 @@ function appendItemToChain(chain, target, blocks) {
|
|
|
569
566
|
}
|
|
570
567
|
return follow;
|
|
571
568
|
}
|
|
572
|
-
|
|
573
|
-
//#region packages/core-base/src/resolver.ts
|
|
569
|
+
// packages/core-base/src/resolver.ts
|
|
574
570
|
const pathStateMachine = [];
|
|
575
571
|
pathStateMachine[0] = {
|
|
576
572
|
["w"]: [0],
|
|
@@ -793,8 +789,7 @@ function resolveValue(obj, path) {
|
|
|
793
789
|
}
|
|
794
790
|
return last;
|
|
795
791
|
}
|
|
796
|
-
|
|
797
|
-
//#region packages/core-base/src/warnings.ts
|
|
792
|
+
// packages/core-base/src/warnings.ts
|
|
798
793
|
const CoreWarnCodes = {
|
|
799
794
|
NOT_FOUND_KEY: 1,
|
|
800
795
|
FALLBACK_TO_TRANSLATE: 2,
|
|
@@ -828,13 +823,12 @@ const warnMessages = {
|
|
|
828
823
|
function getWarnMessage(code, ...args) {
|
|
829
824
|
return format$1(warnMessages[code], ...args);
|
|
830
825
|
}
|
|
831
|
-
|
|
832
|
-
//#region packages/core-base/src/context.ts
|
|
826
|
+
// packages/core-base/src/context.ts
|
|
833
827
|
/**
|
|
834
828
|
* Intlify core-base version
|
|
835
829
|
* @internal
|
|
836
830
|
*/
|
|
837
|
-
const VERSION = "12.0.0-alpha.
|
|
831
|
+
const VERSION = "12.0.0-alpha.8";
|
|
838
832
|
const NOT_RESOLVED = -1;
|
|
839
833
|
const DEFAULT_LOCALE = "en-US";
|
|
840
834
|
const MISSING_RESOLVE_VALUE = "";
|
|
@@ -1038,8 +1032,7 @@ function isImplicitFallback(targetLocale, locales) {
|
|
|
1038
1032
|
for (let i = index + 1; i < locales.length; i++) if (isAlmostSameLocale(targetLocale, locales[i])) return true;
|
|
1039
1033
|
return false;
|
|
1040
1034
|
}
|
|
1041
|
-
|
|
1042
|
-
//#region packages/core-base/src/formatter.ts
|
|
1035
|
+
// packages/core-base/src/formatter.ts
|
|
1043
1036
|
function resolveFormatLocale(context, key, locale, formats, missingWarn, fallbackWarn, type) {
|
|
1044
1037
|
const { fallbackLocale, localeFallbacker, onWarn } = context;
|
|
1045
1038
|
const locales = localeFallbacker(context, fallbackLocale, locale);
|
|
@@ -1147,15 +1140,13 @@ function parseFormatArgs(args, options, initialOverrides, optionsKeys) {
|
|
|
1147
1140
|
if (isPlainObject(arg4)) overrides = arg4;
|
|
1148
1141
|
return overrides;
|
|
1149
1142
|
}
|
|
1150
|
-
|
|
1151
|
-
//#region packages/core-base/src/intl.ts
|
|
1143
|
+
// packages/core-base/src/intl.ts
|
|
1152
1144
|
const intlDefined = typeof Intl !== "undefined";
|
|
1153
1145
|
const Availabilities = {
|
|
1154
1146
|
dateTimeFormat: intlDefined && typeof Intl.DateTimeFormat !== "undefined",
|
|
1155
1147
|
numberFormat: intlDefined && typeof Intl.NumberFormat !== "undefined"
|
|
1156
1148
|
};
|
|
1157
|
-
|
|
1158
|
-
//#region packages/core-base/src/datetime.ts
|
|
1149
|
+
// packages/core-base/src/datetime.ts
|
|
1159
1150
|
function datetime(context, ...args) {
|
|
1160
1151
|
const { datetimeFormats, onWarn } = context;
|
|
1161
1152
|
const { __datetimeFormatters } = context;
|
|
@@ -1225,8 +1216,7 @@ function parseDateTimeArgs(...args) {
|
|
|
1225
1216
|
function clearDateTimeFormat(ctx, locale, format) {
|
|
1226
1217
|
clearFormatCache(ctx.__datetimeFormatters, locale, format);
|
|
1227
1218
|
}
|
|
1228
|
-
|
|
1229
|
-
//#region packages/core-base/src/number.ts
|
|
1219
|
+
// packages/core-base/src/number.ts
|
|
1230
1220
|
function number(context, ...args) {
|
|
1231
1221
|
const { numberFormats, onWarn } = context;
|
|
1232
1222
|
const { __numberFormatters } = context;
|
|
@@ -1282,8 +1272,7 @@ function parseNumberArgs(...args) {
|
|
|
1282
1272
|
function clearNumberFormat(ctx, locale, format) {
|
|
1283
1273
|
clearFormatCache(ctx.__numberFormatters, locale, format);
|
|
1284
1274
|
}
|
|
1285
|
-
|
|
1286
|
-
//#region packages/core-base/src/runtime.ts
|
|
1275
|
+
// packages/core-base/src/runtime.ts
|
|
1287
1276
|
const DEFAULT_MODIFIER = (str) => str;
|
|
1288
1277
|
const DEFAULT_MESSAGE = (_ctx) => "";
|
|
1289
1278
|
const DEFAULT_MESSAGE_DATA_TYPE = "text";
|
|
@@ -1400,8 +1389,7 @@ function createMessageContext(options = {}) {
|
|
|
1400
1389
|
};
|
|
1401
1390
|
return ctx;
|
|
1402
1391
|
}
|
|
1403
|
-
|
|
1404
|
-
//#region packages/core-base/src/translate.ts
|
|
1392
|
+
// packages/core-base/src/translate.ts
|
|
1405
1393
|
const NOOP_MESSAGE_FUNCTION = () => "";
|
|
1406
1394
|
const isMessageFunction = (val) => isFunction(val);
|
|
1407
1395
|
/** @internal */
|
|
@@ -1631,5 +1619,4 @@ function getMessageContextOptions(context, locale, message, options) {
|
|
|
1631
1619
|
pluralIndex: isNumber(options.plural) ? options.plural : void 0
|
|
1632
1620
|
};
|
|
1633
1621
|
}
|
|
1634
|
-
//#endregion
|
|
1635
1622
|
export { AST_NODE_PROPS_KEYS, CORE_ERROR_CODES_EXTEND_POINT, CORE_WARN_CODES_EXTEND_POINT, CoreWarnCodes, DATETIME_FORMAT_OPTIONS_KEYS, DEFAULT_LOCALE, DEFAULT_MESSAGE_DATA_TYPE, MISSING_RESOLVE_VALUE, NOT_RESOLVED, NUMBER_FORMAT_OPTIONS_KEYS, VERSION, clearCompileCache, clearDateTimeFormat, clearNumberFormat, compile, createCompileError, createCoreContext, createCoreError, createMessageContext, datetime, fallbackWithLocaleChain, fallbackWithSimple, getLocale, getLocaleMessage, getWarnMessage, handleMissing, isAlmostSameLocale, isFallbackLocale, isImplicitFallback, isMessageAST, isMessageFormat, isMessageFunction, isTranslateFallbackWarn, isTranslateMissingWarn, isWarnOption, number, parse, parseDateTimeArgs, parseNumberArgs, parseTranslateArgs, registerLocaleFallbacker, registerMessageCompiler, registerMessageResolver, resolveLocale, resolveValue, resolveWithKeyValue, setLocaleMessage, translate, updateFallbackLocale };
|