Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@intlify/shared

Package Overview
Dependencies
Maintainers
2
Versions
208
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@intlify/shared - npm Package Compare versions

Comparing version
12.0.0-alpha.3
to
12.0.0-alpha.4
+111
-142
dist/shared.d.ts

@@ -1,152 +0,121 @@

export declare const assign: typeof Object.assign;
export declare interface BaseError {
code: number;
}
export declare const create: (obj?: object | null) => object;
//#region temp/packages/shared/src/utils.d.ts
declare const inBrowser: boolean;
declare let mark: (tag: string) => void | undefined;
declare let measure: (name: string, startTag: string, endTag: string) => void | undefined;
declare function format(message: string, ...args: any): string;
declare const makeSymbol: (name: string, shareable?: boolean) => symbol;
declare const generateFormatCacheKey: (locale: string, key: string, source: string) => string;
declare const friendlyJSONstringify: (json: unknown) => string;
declare const isNumber: (val: unknown) => val is number;
declare const isDate: (val: unknown) => val is Date;
declare const isRegExp: (val: unknown) => val is RegExp;
/** @deprecated use {@link isPlainObject} and {@link isKeylessObject} together instead */
declare const isEmptyObject: (val: unknown) => val is boolean;
declare const isKeylessObject: <T extends Record<string, any>>(val: T extends readonly any[] ? never : T) => val is Record<string, never>;
declare const assign: typeof Object.assign;
declare const create: (obj?: object | null) => object;
declare const getGlobalThis: () => any;
declare function escapeHtml(rawText: string): string;
declare function sanitizeTranslatedHtml(html: string): string;
declare function hasOwn(obj: object | Array<any>, key: string): boolean;
/**
* Create a event emitter
*
* @returns An event emitter
*/
export declare function createEmitter<Events extends Record<EventType, unknown>>(): Emittable<Events>;
export declare function deepCopy(src: any, des: any): void;
/**
* Event emitter interface
*/
export declare interface Emittable<Events extends Record<EventType, unknown> = {}> {
/**
* A map of event names of registered event handlers
*/
events: EventHandlerMap<Events>;
/**
* Register an event handler with the event type
*
* @param event - An {@link EventType}
* @param handler - An {@link EventHandler}, or a {@link WildcardEventHandler} if you are specified "*"
*/
on<Key extends keyof Events>(event: Key | '*', handler: EventHandler<Events[keyof Events]> | WildcardEventHandler<Events>): void;
/**
* Unregister an event handler for the event type
*
* @param event - An {@link EventType}
* @param handler - An {@link EventHandler}, or a {@link WildcardEventHandler} if you are specified "*"
*/
off<Key extends keyof Events>(event: Key | '*', handler: EventHandler<Events[keyof Events]> | WildcardEventHandler<Events>): void;
/**
* Invoke all handlers with the event type
*
* @remarks
* Note Manually firing "*" handlers should be not supported
*
* @param event - An {@link EventType}
* @param payload - An event payload, optional
*/
emit<Key extends keyof Events>(event: Key, payload?: Events[keyof Events]): void;
* Useful Utilities By Evan you
* Modified by kazuya kawaguchi
* MIT License
* https://github.com/vuejs/vue-next/blob/master/packages/shared/src/index.ts
* https://github.com/vuejs/vue-next/blob/master/packages/shared/src/codeframe.ts
*/
declare const isArray: typeof Array.isArray;
declare const isFunction: (val: unknown) => val is Function;
declare const isString: (val: unknown) => val is string;
declare const isBoolean: (val: unknown) => val is boolean;
declare const isSymbol: (val: unknown) => val is symbol;
declare const isObject: (val: unknown) => val is Record<any, any>;
declare const isPromise: <T = any>(val: unknown) => val is Promise<T>;
declare const objectToString: typeof Object.prototype.toString;
declare const toTypeString: (value: unknown) => string;
declare const isPlainObject: (val: unknown) => val is object;
declare const toDisplayString: (val: unknown) => string;
declare function join(items: string[], separator?: string): string;
declare function generateCodeFrame(source: string, start?: number, end?: number): string;
//#endregion
//#region temp/packages/shared/src/warn.d.ts
declare function warn(msg: string, err?: Error): void;
declare function warnOnce(msg: string): void;
//#endregion
//#region temp/packages/shared/src/error.d.ts
interface BaseError {
code: number;
}
export declare function escapeHtml(rawText: string): string;
//#endregion
//#region temp/packages/shared/src/emittable.d.ts
/**
* Event handler
*/
export declare type EventHandler<T = unknown> = (payload?: T) => void;
* Event type
*/
type EventType = string | symbol;
/**
* Event handler list
*/
export declare type EventHandlerList<T = unknown> = Array<EventHandler<T>>;
* Event handler
*/
type EventHandler<T = unknown> = (payload?: T) => void;
/**
* Event handler map
*/
export declare type EventHandlerMap<Events extends Record<EventType, unknown>> = Map<keyof Events | '*', EventHandlerList<Events[keyof Events]> | WildcardEventHandlerList<Events>>;
* Wildcard event handler
*/
type WildcardEventHandler<T = Record<string, unknown>> = (event: keyof T, payload?: T[keyof T]) => void;
/**
* Event type
*/
export declare type EventType = string | symbol;
export declare function format(message: string, ...args: any): string;
export declare const friendlyJSONstringify: (json: unknown) => string;
export declare function generateCodeFrame(source: string, start?: number, end?: number): string;
export declare const generateFormatCacheKey: (locale: string, key: string, source: string) => string;
export declare const getGlobalThis: () => any;
export declare function hasOwn(obj: object | Array<any>, key: string): boolean;
* Event handler list
*/
type EventHandlerList<T = unknown> = Array<EventHandler<T>>;
/**
* Original Utilities
* written by kazuya kawaguchi
*/
export declare const inBrowser: boolean;
* Wildcard event handler list
*/
type WildcardEventHandlerList<T = Record<string, unknown>> = Array<WildcardEventHandler<T>>;
/**
* Useful Utilities By Evan you
* Modified by kazuya kawaguchi
* MIT License
* https://github.com/vuejs/vue-next/blob/master/packages/shared/src/index.ts
* https://github.com/vuejs/vue-next/blob/master/packages/shared/src/codeframe.ts
*/
export declare const isArray: typeof Array.isArray;
export declare const isBoolean: (val: unknown) => val is boolean;
export declare const isDate: (val: unknown) => val is Date;
export declare const isEmptyObject: (val: unknown) => val is boolean;
export declare const isFunction: (val: unknown) => val is Function;
export declare const isNumber: (val: unknown) => val is number;
export declare const isObject: (val: unknown) => val is Record<any, any>;
export declare const isPlainObject: (val: unknown) => val is object;
export declare const isPromise: <T = any>(val: unknown) => val is Promise<T>;
export declare const isRegExp: (val: unknown) => val is RegExp;
export declare const isString: (val: unknown) => val is string;
export declare const isSymbol: (val: unknown) => val is symbol;
export declare function join(items: string[], separator?: string): string;
export declare const makeSymbol: (name: string, shareable?: boolean) => symbol;
export declare let mark: (tag: string) => void | undefined;
export declare let measure: (name: string, startTag: string, endTag: string) => void | undefined;
export declare const objectToString: typeof Object.prototype.toString;
export declare const toDisplayString: (val: unknown) => string;
export declare const toTypeString: (value: unknown) => string;
export declare function warn(msg: string, err?: Error): void;
export declare function warnOnce(msg: string): void;
* Event handler map
*/
type EventHandlerMap<Events extends Record<EventType, unknown>> = Map<keyof Events | "*", EventHandlerList<Events[keyof Events]> | WildcardEventHandlerList<Events>>;
/**
* Wildcard event handler
*/
export declare type WildcardEventHandler<T = Record<string, unknown>> = (event: keyof T, payload?: T[keyof T]) => void;
* Event emitter interface
*/
interface Emittable<Events extends Record<EventType, unknown> = {}> {
/**
* A map of event names of registered event handlers
*/
events: EventHandlerMap<Events>;
/**
* Register an event handler with the event type
*
* @param event - An {@link EventType}
* @param handler - An {@link EventHandler}, or a {@link WildcardEventHandler} if you are specified "*"
*/
on<Key extends keyof Events>(event: Key | "*", handler: EventHandler<Events[keyof Events]> | WildcardEventHandler<Events>): void;
/**
* Unregister an event handler for the event type
*
* @param event - An {@link EventType}
* @param handler - An {@link EventHandler}, or a {@link WildcardEventHandler} if you are specified "*"
*/
off<Key extends keyof Events>(event: Key | "*", handler: EventHandler<Events[keyof Events]> | WildcardEventHandler<Events>): void;
/**
* Invoke all handlers with the event type
*
* @remarks
* Note Manually firing "*" handlers should be not supported
*
* @param event - An {@link EventType}
* @param payload - An event payload, optional
*/
emit<Key extends keyof Events>(event: Key, payload?: Events[keyof Events]): void;
}
//#endregion
//#region temp/packages/shared/src/emitter.d.ts
/**
* Wildcard event handler list
*/
export declare type WildcardEventHandlerList<T = Record<string, unknown>> = Array<WildcardEventHandler<T>>;
export { }
* Create a event emitter
*
* @returns An event emitter
*/
declare function createEmitter<Events extends Record<EventType, unknown>>(): Emittable<Events>;
//#endregion
//#region temp/packages/shared/src/messages.d.ts
declare function deepCopy(src: any, des: any): void;
//#endregion
export { BaseError, Emittable, EventHandler, EventHandlerList, EventHandlerMap, EventType, WildcardEventHandler, WildcardEventHandlerList, assign, create, createEmitter, deepCopy, escapeHtml, format, friendlyJSONstringify, generateCodeFrame, generateFormatCacheKey, getGlobalThis, hasOwn, inBrowser, isArray, isBoolean, isDate, isEmptyObject, isFunction, isKeylessObject, isNumber, isObject, isPlainObject, isPromise, isRegExp, isString, isSymbol, join, makeSymbol, mark, measure, objectToString, sanitizeTranslatedHtml, toDisplayString, toTypeString, warn, warnOnce };

@@ -1,54 +0,64 @@

/*!
* shared v12.0.0-alpha.3
* (c) 2016-present kazuya kawaguchi and contributors
* Released under the MIT License.
*/
/**
* Original Utilities
* written by kazuya kawaguchi
*/
const inBrowser = typeof window !== 'undefined';
* @intlify/shared v12.0.0-alpha.4
* (c) 2016-present kazuya kawaguchi and contributors
* @license MIT
**/
//#region packages/shared/src/warn.ts
function warn(msg, err) {
if (typeof console !== "undefined") {
console.warn(`[intlify] ` + msg);
/* istanbul ignore if */
if (err) console.warn(err.stack);
}
}
const hasWarned = {};
function warnOnce(msg) {
if (!hasWarned[msg]) {
hasWarned[msg] = true;
warn(msg);
}
}
//#endregion
//#region packages/shared/src/utils.ts
/**
* Original Utilities
* written by kazuya kawaguchi
*/
const inBrowser = typeof window !== "undefined";
let mark;
let measure;
{
const perf = inBrowser && window.performance;
if (perf &&
perf.mark &&
perf.measure &&
perf.clearMarks &&
// @ts-ignore browser compat
perf.clearMeasures) {
mark = (tag) => {
perf.mark(tag);
};
measure = (name, startTag, endTag) => {
perf.measure(name, startTag, endTag);
perf.clearMarks(startTag);
perf.clearMarks(endTag);
};
}
const perf = inBrowser && window.performance;
if (perf && perf.mark && perf.measure && perf.clearMarks && perf.clearMeasures) {
mark = (tag) => {
perf.mark(tag);
};
measure = (name, startTag, endTag) => {
perf.measure(name, startTag, endTag);
perf.clearMarks(startTag);
perf.clearMarks(endTag);
};
}
}
const RE_ARGS = /\{([0-9a-zA-Z]+)\}/g;
/* eslint-disable */
const RE_ARGS = /\{([0-9a-z]+)\}/gi;
function format(message, ...args) {
if (args.length === 1 && isObject(args[0])) {
args = args[0];
}
if (!args || !args.hasOwnProperty) {
args = {};
}
return message.replace(RE_ARGS, (match, identifier) => {
return args.hasOwnProperty(identifier) ? args[identifier] : '';
});
if (args.length === 1 && isObject(args[0])) args = args[0];
if (!args || !args.hasOwnProperty) args = {};
return message.replace(RE_ARGS, (_match, identifier) => {
return args.hasOwnProperty(identifier) ? args[identifier] : "";
});
}
const makeSymbol = (name, shareable = false) => !shareable ? Symbol(name) : Symbol.for(name);
const generateFormatCacheKey = (locale, key, source) => friendlyJSONstringify({ l: locale, k: key, s: source });
const friendlyJSONstringify = (json) => JSON.stringify(json)
.replace(/\u2028/g, '\\u2028')
.replace(/\u2029/g, '\\u2029')
.replace(/\u0027/g, '\\u0027');
const isNumber = (val) => typeof val === 'number' && isFinite(val);
const isDate = (val) => toTypeString(val) === '[object Date]';
const isRegExp = (val) => toTypeString(val) === '[object RegExp]';
const generateFormatCacheKey = (locale, key, source) => friendlyJSONstringify({
l: locale,
k: key,
s: source
});
const friendlyJSONstringify = (json) => JSON.stringify(json).replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029").replace(/\u0027/g, "\\u0027");
const isNumber = (val) => typeof val === "number" && isFinite(val);
const isDate = (val) => toTypeString(val) === "[object Date]";
const isRegExp = (val) => toTypeString(val) === "[object RegExp]";
/** @deprecated use {@link isPlainObject} and {@link isKeylessObject} together instead */
const isEmptyObject = (val) => isPlainObject(val) && Object.keys(val).length === 0;
const isKeylessObject = (val) => Object.keys(val).length === 0;
const assign = Object.assign;

@@ -59,185 +69,169 @@ const _create = Object.create;

const getGlobalThis = () => {
// prettier-ignore
return (_globalThis ||
(_globalThis =
typeof globalThis !== 'undefined'
? globalThis
: typeof self !== 'undefined'
? self
: typeof window !== 'undefined'
? window
: typeof global !== 'undefined'
? global
: create()));
return _globalThis || (_globalThis = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : create());
};
function escapeHtml(rawText) {
return rawText
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&apos;');
return rawText.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;").replace(/\//g, "&#x2F;").replace(/=/g, "&#x3D;");
}
function escapeAttributeValue(value) {
return value.replace(/&(?![a-z0-9#]{2,6};)/gi, "&amp;").replace(/"/g, "&quot;").replace(/'/g, "&apos;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
}
const javascriptSchemePattern = /^\s*javascript\s*(?::|&#0*58;?|&#x0*3a;?|&colon;?)/i;
const urlAttributePattern = /^(?:href|src|action|formaction)$/i;
function hasJavascriptScheme(value) {
return javascriptSchemePattern.test(value);
}
function sanitizeStyleValue(value) {
const urlPattern = /url\s*\(/gi;
let sanitized = "";
let cursor = 0;
let match;
while ((match = urlPattern.exec(value)) !== null) {
const urlStart = match.index;
const openParenIndex = urlPattern.lastIndex - 1;
let index = openParenIndex + 1;
let depth = 1;
let quote = null;
for (; index < value.length; index++) {
const char = value[index];
if (quote) {
if (char === quote) quote = null;
continue;
}
if (char === "\"" || char === "'") quote = char;
else if (char === "(") depth++;
else if (char === ")") {
depth--;
if (depth === 0) break;
}
}
if (depth !== 0) break;
const rawUrlValue = value.slice(openParenIndex + 1, index).trim();
const unquotedUrlValue = rawUrlValue.startsWith("\"") && rawUrlValue.endsWith("\"") || rawUrlValue.startsWith("'") && rawUrlValue.endsWith("'") ? rawUrlValue.slice(1, -1).trim() : rawUrlValue;
sanitized += value.slice(cursor, urlStart);
sanitized += hasJavascriptScheme(unquotedUrlValue) ? "url(about:blank)" : value.slice(urlStart, index + 1);
cursor = index + 1;
}
return sanitized + value.slice(cursor);
}
function sanitizeAttributeValue(attrName, value) {
if (urlAttributePattern.test(attrName) && hasJavascriptScheme(value)) return "about:blank";
return escapeAttributeValue(attrName.toLowerCase() === "style" ? sanitizeStyleValue(value) : value);
}
function sanitizeTranslatedHtml(html) {
html = html.replace(/([\w:-]+)\s*=\s*"([^"]*)"/g, (_, attrName, attrValue) => `${attrName}="${sanitizeAttributeValue(attrName, attrValue)}"`);
html = html.replace(/([\w:-]+)\s*=\s*'([^']*)'/g, (_, attrName, attrValue) => `${attrName}='${sanitizeAttributeValue(attrName, attrValue)}'`);
if (/\s*on\w+\s*=\s*["']?[^"'>]+["']?/i.test(html)) {
warn("Potentially dangerous event handlers detected in translation. Consider removing onclick, onerror, etc. from your translation messages.");
html = html.replace(/(\s+)on(\w+\s*=)/gi, "$1&#111;n$2");
}
html = html.replace(/(\s+(?:href|src|action|formaction)\s*=\s*)([^\s"'=<>`]+)/gi, (match, prefix, attrValue) => hasJavascriptScheme(attrValue) ? `${prefix}about:blank` : match);
return html;
}
const hasOwnProperty = Object.prototype.hasOwnProperty;
function hasOwn(obj, key) {
return hasOwnProperty.call(obj, key);
return hasOwnProperty.call(obj, key);
}
/* eslint-enable */
/**
* Useful Utilities By Evan you
* Modified by kazuya kawaguchi
* MIT License
* https://github.com/vuejs/vue-next/blob/master/packages/shared/src/index.ts
* https://github.com/vuejs/vue-next/blob/master/packages/shared/src/codeframe.ts
*/
* Useful Utilities By Evan you
* Modified by kazuya kawaguchi
* MIT License
* https://github.com/vuejs/vue-next/blob/master/packages/shared/src/index.ts
* https://github.com/vuejs/vue-next/blob/master/packages/shared/src/codeframe.ts
*/
const isArray = Array.isArray;
const isFunction = (val) => typeof val === 'function';
const isString = (val) => typeof val === 'string';
const isBoolean = (val) => typeof val === 'boolean';
const isSymbol = (val) => typeof val === 'symbol';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const isObject = (val) => val !== null && typeof val === 'object';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const isFunction = (val) => typeof val === "function";
const isString = (val) => typeof val === "string";
const isBoolean = (val) => typeof val === "boolean";
const isSymbol = (val) => typeof val === "symbol";
const isObject = (val) => val !== null && typeof val === "object";
const isPromise = (val) => {
return isObject(val) && isFunction(val.then) && isFunction(val.catch);
return isObject(val) && isFunction(val.then) && isFunction(val.catch);
};
const objectToString = Object.prototype.toString;
const toTypeString = (value) => objectToString.call(value);
const isPlainObject = (val) => toTypeString(val) === '[object Object]';
// for converting list and named values to displayed strings.
const isPlainObject = (val) => toTypeString(val) === "[object Object]";
const toDisplayString = (val) => {
return val == null
? ''
: isArray(val) || (isPlainObject(val) && val.toString === objectToString)
? JSON.stringify(val, null, 2)
: String(val);
return val == null ? "" : isArray(val) || isPlainObject(val) && val.toString === objectToString ? JSON.stringify(val, null, 2) : String(val);
};
function join(items, separator = '') {
return items.reduce((str, item, index) => (index === 0 ? str + item : str + separator + item), '');
function join(items, separator = "") {
return items.reduce((str, item, index) => index === 0 ? str + item : str + separator + item, "");
}
const RANGE = 2;
function generateCodeFrame(source, start = 0, end = source.length) {
const lines = source.split(/\r?\n/);
let count = 0;
const res = [];
for (let i = 0; i < lines.length; i++) {
count += lines[i].length + 1;
if (count >= start) {
for (let j = i - RANGE; j <= i + RANGE || end > count; j++) {
if (j < 0 || j >= lines.length)
continue;
const line = j + 1;
res.push(`${line}${' '.repeat(3 - String(line).length)}| ${lines[j]}`);
const lineLength = lines[j].length;
if (j === i) {
// push underline
const pad = start - (count - lineLength) + 1;
const length = Math.max(1, end > count ? lineLength - pad : end - start);
res.push(` | ` + ' '.repeat(pad) + '^'.repeat(length));
}
else if (j > i) {
if (end > count) {
const length = Math.max(Math.min(end - count, lineLength), 1);
res.push(` | ` + '^'.repeat(length));
}
count += lineLength + 1;
}
}
break;
}
}
return res.join('\n');
const lines = source.split(/\r?\n/);
let count = 0;
const res = [];
for (let i = 0; i < lines.length; i++) {
count += lines[i].length + 1;
if (count >= start) {
for (let j = i - RANGE; j <= i + RANGE || end > count; j++) {
if (j < 0 || j >= lines.length) continue;
const line = j + 1;
res.push(`${line}${" ".repeat(3 - String(line).length)}| ${lines[j]}`);
const lineLength = lines[j].length;
if (j === i) {
const pad = start - (count - lineLength) + 1;
const length = Math.max(1, end > count ? lineLength - pad : end - start);
res.push(` | ` + " ".repeat(pad) + "^".repeat(length));
} else if (j > i) {
if (end > count) {
const length = Math.max(Math.min(end - count, lineLength), 1);
res.push(` | ` + "^".repeat(length));
}
count += lineLength + 1;
}
}
break;
}
}
return res.join("\n");
}
function warn(msg, err) {
if (typeof console !== 'undefined') {
console.warn(`[intlify] ` + msg);
/* istanbul ignore if */
if (err) {
console.warn(err.stack);
}
}
}
const hasWarned = {};
function warnOnce(msg) {
if (!hasWarned[msg]) {
hasWarned[msg] = true;
warn(msg);
}
}
//#endregion
//#region packages/shared/src/emitter.ts
/**
* Event emitter, forked from the below:
* - original repository url: https://github.com/developit/mitt
* - code url: https://github.com/developit/mitt/blob/master/src/index.ts
* - author: Jason Miller (https://github.com/developit)
* - license: MIT
*/
/**
* Create a event emitter
*
* @returns An event emitter
*/
* Create a event emitter
*
* @returns An event emitter
*/
function createEmitter() {
const events = new Map();
const emitter = {
events,
on(event, handler) {
const handlers = events.get(event);
const added = handlers && handlers.push(handler);
if (!added) {
events.set(event, [handler]);
}
},
off(event, handler) {
const handlers = events.get(event);
if (handlers) {
handlers.splice(handlers.indexOf(handler) >>> 0, 1);
}
},
emit(event, payload) {
(events.get(event) || [])
.slice()
.map(handler => handler(payload));
(events.get('*') || [])
.slice()
.map(handler => handler(event, payload));
}
};
return emitter;
const events = /* @__PURE__ */ new Map();
return {
events,
on(event, handler) {
const handlers = events.get(event);
if (!(handlers && handlers.push(handler))) events.set(event, [handler]);
},
off(event, handler) {
const handlers = events.get(event);
if (handlers) handlers.splice(handlers.indexOf(handler) >>> 0, 1);
},
emit(event, payload) {
(events.get(event) || []).slice().map((handler) => handler(payload));
(events.get("*") || []).slice().map((handler) => handler(event, payload));
}
};
}
//#endregion
//#region packages/shared/src/messages.ts
const isNotObjectOrIsArray = (val) => !isObject(val) || isArray(val);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function deepCopy(src, des) {
// src and des should both be objects, and none of them can be a array
if (isNotObjectOrIsArray(src) || isNotObjectOrIsArray(des)) {
throw new Error('Invalid value');
}
const stack = [{ src, des }];
while (stack.length) {
const { src, des } = stack.pop();
// using `Object.keys` which skips prototype properties
Object.keys(src).forEach(key => {
if (key === '__proto__') {
return;
}
// if src[key] is an object/array, set des[key]
// to empty object/array to prevent setting by reference
if (isObject(src[key]) && !isObject(des[key])) {
des[key] = Array.isArray(src[key]) ? [] : create();
}
if (isNotObjectOrIsArray(des[key]) || isNotObjectOrIsArray(src[key])) {
// replace with src[key] when:
// src[key] or des[key] is not an object, or
// src[key] or des[key] is an array
des[key] = src[key];
}
else {
// src[key] and des[key] are both objects, merge them
stack.push({ src: src[key], des: des[key] });
}
});
}
if (isNotObjectOrIsArray(src) || isNotObjectOrIsArray(des)) throw new Error("Invalid value");
const stack = [{
src,
des
}];
while (stack.length) {
const { src, des } = stack.pop();
Object.keys(src).forEach((key) => {
if (key === "__proto__") return;
if (isObject(src[key]) && !isObject(des[key])) des[key] = Array.isArray(src[key]) ? [] : create();
if (isNotObjectOrIsArray(des[key]) || isNotObjectOrIsArray(src[key])) des[key] = src[key];
else stack.push({
src: src[key],
des: des[key]
});
});
}
}
export { assign, create, createEmitter, deepCopy, escapeHtml, format, friendlyJSONstringify, generateCodeFrame, generateFormatCacheKey, getGlobalThis, hasOwn, inBrowser, isArray, isBoolean, isDate, isEmptyObject, isFunction, isNumber, isObject, isPlainObject, isPromise, isRegExp, isString, isSymbol, join, makeSymbol, mark, measure, objectToString, toDisplayString, toTypeString, warn, warnOnce };
//#endregion
export { assign, create, createEmitter, deepCopy, escapeHtml, format, friendlyJSONstringify, generateCodeFrame, generateFormatCacheKey, getGlobalThis, hasOwn, inBrowser, isArray, isBoolean, isDate, isEmptyObject, isFunction, isKeylessObject, isNumber, isObject, isPlainObject, isPromise, isRegExp, isString, isSymbol, join, makeSymbol, mark, measure, objectToString, sanitizeTranslatedHtml, toDisplayString, toTypeString, warn, warnOnce };

@@ -1,6 +0,127 @@

/*!
* shared v12.0.0-alpha.3
* (c) 2016-present kazuya kawaguchi and contributors
* Released under the MIT License.
*/
const inBrowser="undefined"!=typeof window;let mark,measure;const RE_ARGS=/\{([0-9a-zA-Z]+)\}/g;function format(e,...t){return 1===t.length&&isObject(t[0])&&(t=t[0]),t&&t.hasOwnProperty||(t={}),e.replace(RE_ARGS,((e,n)=>t.hasOwnProperty(n)?t[n]:""))}const makeSymbol=(e,t=!1)=>t?Symbol.for(e):Symbol(e),generateFormatCacheKey=(e,t,n)=>friendlyJSONstringify({l:e,k:t,s:n}),friendlyJSONstringify=e=>JSON.stringify(e).replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029").replace(/\u0027/g,"\\u0027"),isNumber=e=>"number"==typeof e&&isFinite(e),isDate=e=>"[object Date]"===toTypeString(e),isRegExp=e=>"[object RegExp]"===toTypeString(e),isEmptyObject=e=>isPlainObject(e)&&0===Object.keys(e).length,assign=Object.assign,_create=Object.create,create=(e=null)=>_create(e);let _globalThis;const getGlobalThis=()=>_globalThis||(_globalThis="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:create());function escapeHtml(e){return e.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}const hasOwnProperty=Object.prototype.hasOwnProperty;function hasOwn(e,t){return hasOwnProperty.call(e,t)}const isArray=Array.isArray,isFunction=e=>"function"==typeof e,isString=e=>"string"==typeof e,isBoolean=e=>"boolean"==typeof e,isSymbol=e=>"symbol"==typeof e,isObject=e=>null!==e&&"object"==typeof e,isPromise=e=>isObject(e)&&isFunction(e.then)&&isFunction(e.catch),objectToString=Object.prototype.toString,toTypeString=e=>objectToString.call(e),isPlainObject=e=>"[object Object]"===toTypeString(e),toDisplayString=e=>null==e?"":isArray(e)||isPlainObject(e)&&e.toString===objectToString?JSON.stringify(e,null,2):String(e);function join(e,t=""){return e.reduce(((e,n,r)=>0===r?e+n:e+t+n),"")}const RANGE=2;function generateCodeFrame(e,t=0,n=e.length){const r=e.split(/\r?\n/);let o=0;const i=[];for(let s=0;s<r.length;s++)if(o+=r[s].length+1,o>=t){for(let e=s-2;e<=s+2||n>o;e++){if(e<0||e>=r.length)continue;const a=e+1;i.push(`${a}${" ".repeat(3-String(a).length)}| ${r[e]}`);const c=r[e].length;if(e===s){const e=t-(o-c)+1,r=Math.max(1,n>o?c-e:n-t);i.push(" | "+" ".repeat(e)+"^".repeat(r))}else if(e>s){if(n>o){const e=Math.max(Math.min(n-o,c),1);i.push(" | "+"^".repeat(e))}o+=c+1}}break}return i.join("\n")}function warn(e,t){"undefined"!=typeof console&&(console.warn("[intlify] "+e),t&&console.warn(t.stack))}const hasWarned={};function warnOnce(e){hasWarned[e]||(hasWarned[e]=!0,warn(e))}function createEmitter(){const e=new Map;return{events:e,on(t,n){const r=e.get(t);r&&r.push(n)||e.set(t,[n])},off(t,n){const r=e.get(t);r&&r.splice(r.indexOf(n)>>>0,1)},emit(t,n){(e.get(t)||[]).slice().map((e=>e(n))),(e.get("*")||[]).slice().map((e=>e(t,n)))}}}const isNotObjectOrIsArray=e=>!isObject(e)||isArray(e);function deepCopy(e,t){if(isNotObjectOrIsArray(e)||isNotObjectOrIsArray(t))throw new Error("Invalid value");const n=[{src:e,des:t}];for(;n.length;){const{src:e,des:t}=n.pop();Object.keys(e).forEach((r=>{"__proto__"!==r&&(isObject(e[r])&&!isObject(t[r])&&(t[r]=Array.isArray(e[r])?[]:create()),isNotObjectOrIsArray(t[r])||isNotObjectOrIsArray(e[r])?t[r]=e[r]:n.push({src:e[r],des:t[r]}))}))}}export{assign,create,createEmitter,deepCopy,escapeHtml,format,friendlyJSONstringify,generateCodeFrame,generateFormatCacheKey,getGlobalThis,hasOwn,inBrowser,isArray,isBoolean,isDate,isEmptyObject,isFunction,isNumber,isObject,isPlainObject,isPromise,isRegExp,isString,isSymbol,join,makeSymbol,mark,measure,objectToString,toDisplayString,toTypeString,warn,warnOnce};
/**
* @intlify/shared v12.0.0-alpha.4
* (c) 2016-present kazuya kawaguchi and contributors
* @license MIT
**/ function warn(e, t) {
typeof console < `u` && (console.warn(`[intlify] ` + e), t && console.warn(t.stack));
}
const hasWarned = {};
function warnOnce(n) {
hasWarned[n] || (hasWarned[n] = !0, warn(n));
}
const inBrowser = typeof window < `u`;
let mark, measure;
const RE_ARGS = /\{([0-9a-z]+)\}/gi;
function format(e, ...t) {
return t.length === 1 && isObject(t[0]) && (t = t[0]), (!t || !t.hasOwnProperty) && (t = {}), e.replace(RE_ARGS, (e, n) => t.hasOwnProperty(n) ? t[n] : ``);
}
const makeSymbol = (e, t = !1) => t ? Symbol.for(e) : Symbol(e), generateFormatCacheKey = (e, t, n) => friendlyJSONstringify({
l: e,
k: t,
s: n
}), friendlyJSONstringify = (e) => JSON.stringify(e).replace(/\u2028/g, `\\u2028`).replace(/\u2029/g, `\\u2029`).replace(/\u0027/g, `\\u0027`), isNumber = (e) => typeof e == `number` && isFinite(e), isDate = (e) => toTypeString(e) === `[object Date]`, isRegExp = (e) => toTypeString(e) === `[object RegExp]`, isEmptyObject = (e) => isPlainObject(e) && Object.keys(e).length === 0, isKeylessObject = (e) => Object.keys(e).length === 0, assign = Object.assign, _create = Object.create, create = (e = null) => _create(e);
let _globalThis;
const getGlobalThis = () => _globalThis || (_globalThis = typeof globalThis < `u` ? globalThis : typeof self < `u` ? self : typeof window < `u` ? window : typeof global < `u` ? global : create());
function escapeHtml(e) {
return e.replace(/&/g, `&amp;`).replace(/</g, `&lt;`).replace(/>/g, `&gt;`).replace(/"/g, `&quot;`).replace(/'/g, `&apos;`).replace(/\//g, `&#x2F;`).replace(/=/g, `&#x3D;`);
}
function escapeAttributeValue(e) {
return e.replace(/&(?![a-z0-9#]{2,6};)/gi, `&amp;`).replace(/"/g, `&quot;`).replace(/'/g, `&apos;`).replace(/</g, `&lt;`).replace(/>/g, `&gt;`);
}
const javascriptSchemePattern = /^\s*javascript\s*(?::|&#0*58;?|&#x0*3a;?|&colon;?)/i, urlAttributePattern = /^(?:href|src|action|formaction)$/i;
function hasJavascriptScheme(e) {
return javascriptSchemePattern.test(e);
}
function sanitizeStyleValue(e) {
let t = /url\s*\(/gi, n = ``, r = 0, i;
for (; (i = t.exec(e)) !== null;) {
let a = i.index, o = t.lastIndex - 1, s = o + 1, c = 1, l = null;
for (; s < e.length; s++) {
let t = e[s];
if (l) {
t === l && (l = null);
continue;
}
if (t === `"` || t === `'`) l = t;
else if (t === `(`) c++;
else if (t === `)` && (c--, c === 0)) break;
}
if (c !== 0) break;
let u = e.slice(o + 1, s).trim(), d = u.startsWith(`"`) && u.endsWith(`"`) || u.startsWith(`'`) && u.endsWith(`'`) ? u.slice(1, -1).trim() : u;
n += e.slice(r, a), n += hasJavascriptScheme(d) ? `url(about:blank)` : e.slice(a, s + 1), r = s + 1;
}
return n + e.slice(r);
}
function sanitizeAttributeValue(e, t) {
return urlAttributePattern.test(e) && hasJavascriptScheme(t) ? `about:blank` : escapeAttributeValue(e.toLowerCase() === `style` ? sanitizeStyleValue(t) : t);
}
function sanitizeTranslatedHtml(e) {
return e = e.replace(/([\w:-]+)\s*=\s*"([^"]*)"/g, (e, t, n) => `${t}="${sanitizeAttributeValue(t, n)}"`), e = e.replace(/([\w:-]+)\s*=\s*'([^']*)'/g, (e, t, n) => `${t}='${sanitizeAttributeValue(t, n)}'`), /\s*on\w+\s*=\s*["']?[^"'>]+["']?/i.test(e) && (e = e.replace(/(\s+)on(\w+\s*=)/gi, `$1&#111;n$2`)), e = e.replace(/(\s+(?:href|src|action|formaction)\s*=\s*)([^\s"'=<>`]+)/gi, (e, t, n) => hasJavascriptScheme(n) ? `${t}about:blank` : e), e;
}
const hasOwnProperty = Object.prototype.hasOwnProperty;
function hasOwn(e, t) {
return hasOwnProperty.call(e, t);
}
const isArray = Array.isArray, isFunction = (e) => typeof e == `function`, isString = (e) => typeof e == `string`, isBoolean = (e) => typeof e == `boolean`, isSymbol = (e) => typeof e == `symbol`, isObject = (e) => typeof e == `object` && !!e, isPromise = (e) => isObject(e) && isFunction(e.then) && isFunction(e.catch), objectToString = Object.prototype.toString, toTypeString = (e) => objectToString.call(e), isPlainObject = (e) => toTypeString(e) === `[object Object]`, toDisplayString = (e) => e == null ? `` : isArray(e) || isPlainObject(e) && e.toString === objectToString ? JSON.stringify(e, null, 2) : String(e);
function join(e, t = ``) {
return e.reduce((e, n, r) => r === 0 ? e + n : e + t + n, ``);
}
function generateCodeFrame(e, t = 0, n = e.length) {
let r = e.split(/\r?\n/), i = 0, a = [];
for (let e = 0; e < r.length; e++) if (i += r[e].length + 1, i >= t) {
for (let o = e - 2; o <= e + 2 || n > i; o++) {
if (o < 0 || o >= r.length) continue;
let s = o + 1;
a.push(`${s}${` `.repeat(3 - String(s).length)}| ${r[o]}`);
let c = r[o].length;
if (o === e) {
let e = t - (i - c) + 1, r = Math.max(1, n > i ? c - e : n - t);
a.push(` | ` + ` `.repeat(e) + `^`.repeat(r));
} else if (o > e) {
if (n > i) {
let e = Math.max(Math.min(n - i, c), 1);
a.push(` | ` + `^`.repeat(e));
}
i += c + 1;
}
}
break;
}
return a.join(`
`);
}
function createEmitter() {
let e = /* @__PURE__ */ new Map();
return {
events: e,
on(t, n) {
let r = e.get(t);
r && r.push(n) || e.set(t, [n]);
},
off(t, n) {
let r = e.get(t);
r && r.splice(r.indexOf(n) >>> 0, 1);
},
emit(t, n) {
(e.get(t) || []).slice().map((e) => e(n)), (e.get(`*`) || []).slice().map((e) => e(t, n));
}
};
}
const isNotObjectOrIsArray = (e) => !isObject(e) || isArray(e);
function deepCopy(e, t) {
if (isNotObjectOrIsArray(e) || isNotObjectOrIsArray(t)) throw Error(`Invalid value`);
let n = [{
src: e,
des: t
}];
for (; n.length;) {
let { src: e, des: t } = n.pop();
Object.keys(e).forEach((r) => {
r !== `__proto__` && (isObject(e[r]) && !isObject(t[r]) && (t[r] = Array.isArray(e[r]) ? [] : create()), isNotObjectOrIsArray(t[r]) || isNotObjectOrIsArray(e[r]) ? t[r] = e[r] : n.push({
src: e[r],
des: t[r]
}));
});
}
}
export { assign, create, createEmitter, deepCopy, escapeHtml, format, friendlyJSONstringify, generateCodeFrame, generateFormatCacheKey, getGlobalThis, hasOwn, inBrowser, isArray, isBoolean, isDate, isEmptyObject, isFunction, isKeylessObject, isNumber, isObject, isPlainObject, isPromise, isRegExp, isString, isSymbol, join, makeSymbol, mark, measure, objectToString, sanitizeTranslatedHtml, toDisplayString, toTypeString, warn, warnOnce };

@@ -1,1 +0,1 @@

export * from '../dist/shared.js'
export * from './shared.js'

@@ -1,54 +0,64 @@

/*!
* shared v12.0.0-alpha.3
* (c) 2016-present kazuya kawaguchi and contributors
* Released under the MIT License.
*/
/**
* Original Utilities
* written by kazuya kawaguchi
*/
const inBrowser = typeof window !== 'undefined';
* @intlify/shared v12.0.0-alpha.4
* (c) 2016-present kazuya kawaguchi and contributors
* @license MIT
**/
//#region packages/shared/src/warn.ts
function warn(msg, err) {
if (typeof console !== "undefined") {
console.warn(`[intlify] ` + msg);
/* istanbul ignore if */
if (err) console.warn(err.stack);
}
}
const hasWarned = {};
function warnOnce(msg) {
if (!hasWarned[msg]) {
hasWarned[msg] = true;
warn(msg);
}
}
//#endregion
//#region packages/shared/src/utils.ts
/**
* Original Utilities
* written by kazuya kawaguchi
*/
const inBrowser = typeof window !== "undefined";
let mark;
let measure;
if ((process.env.NODE_ENV !== 'production')) {
const perf = inBrowser && window.performance;
if (perf &&
perf.mark &&
perf.measure &&
perf.clearMarks &&
// @ts-ignore browser compat
perf.clearMeasures) {
mark = (tag) => {
perf.mark(tag);
};
measure = (name, startTag, endTag) => {
perf.measure(name, startTag, endTag);
perf.clearMarks(startTag);
perf.clearMarks(endTag);
};
}
{
const perf = inBrowser && window.performance;
if (perf && perf.mark && perf.measure && perf.clearMarks && perf.clearMeasures) {
mark = (tag) => {
perf.mark(tag);
};
measure = (name, startTag, endTag) => {
perf.measure(name, startTag, endTag);
perf.clearMarks(startTag);
perf.clearMarks(endTag);
};
}
}
const RE_ARGS = /\{([0-9a-zA-Z]+)\}/g;
/* eslint-disable */
const RE_ARGS = /\{([0-9a-z]+)\}/gi;
function format(message, ...args) {
if (args.length === 1 && isObject(args[0])) {
args = args[0];
}
if (!args || !args.hasOwnProperty) {
args = {};
}
return message.replace(RE_ARGS, (match, identifier) => {
return args.hasOwnProperty(identifier) ? args[identifier] : '';
});
if (args.length === 1 && isObject(args[0])) args = args[0];
if (!args || !args.hasOwnProperty) args = {};
return message.replace(RE_ARGS, (_match, identifier) => {
return args.hasOwnProperty(identifier) ? args[identifier] : "";
});
}
const makeSymbol = (name, shareable = false) => !shareable ? Symbol(name) : Symbol.for(name);
const generateFormatCacheKey = (locale, key, source) => friendlyJSONstringify({ l: locale, k: key, s: source });
const friendlyJSONstringify = (json) => JSON.stringify(json)
.replace(/\u2028/g, '\\u2028')
.replace(/\u2029/g, '\\u2029')
.replace(/\u0027/g, '\\u0027');
const isNumber = (val) => typeof val === 'number' && isFinite(val);
const isDate = (val) => toTypeString(val) === '[object Date]';
const isRegExp = (val) => toTypeString(val) === '[object RegExp]';
const generateFormatCacheKey = (locale, key, source) => friendlyJSONstringify({
l: locale,
k: key,
s: source
});
const friendlyJSONstringify = (json) => JSON.stringify(json).replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029").replace(/\u0027/g, "\\u0027");
const isNumber = (val) => typeof val === "number" && isFinite(val);
const isDate = (val) => toTypeString(val) === "[object Date]";
const isRegExp = (val) => toTypeString(val) === "[object RegExp]";
/** @deprecated use {@link isPlainObject} and {@link isKeylessObject} together instead */
const isEmptyObject = (val) => isPlainObject(val) && Object.keys(val).length === 0;
const isKeylessObject = (val) => Object.keys(val).length === 0;
const assign = Object.assign;

@@ -59,185 +69,169 @@ const _create = Object.create;

const getGlobalThis = () => {
// prettier-ignore
return (_globalThis ||
(_globalThis =
typeof globalThis !== 'undefined'
? globalThis
: typeof self !== 'undefined'
? self
: typeof window !== 'undefined'
? window
: typeof global !== 'undefined'
? global
: create()));
return _globalThis || (_globalThis = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : create());
};
function escapeHtml(rawText) {
return rawText
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&apos;');
return rawText.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;").replace(/\//g, "&#x2F;").replace(/=/g, "&#x3D;");
}
function escapeAttributeValue(value) {
return value.replace(/&(?![a-z0-9#]{2,6};)/gi, "&amp;").replace(/"/g, "&quot;").replace(/'/g, "&apos;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
}
const javascriptSchemePattern = /^\s*javascript\s*(?::|&#0*58;?|&#x0*3a;?|&colon;?)/i;
const urlAttributePattern = /^(?:href|src|action|formaction)$/i;
function hasJavascriptScheme(value) {
return javascriptSchemePattern.test(value);
}
function sanitizeStyleValue(value) {
const urlPattern = /url\s*\(/gi;
let sanitized = "";
let cursor = 0;
let match;
while ((match = urlPattern.exec(value)) !== null) {
const urlStart = match.index;
const openParenIndex = urlPattern.lastIndex - 1;
let index = openParenIndex + 1;
let depth = 1;
let quote = null;
for (; index < value.length; index++) {
const char = value[index];
if (quote) {
if (char === quote) quote = null;
continue;
}
if (char === "\"" || char === "'") quote = char;
else if (char === "(") depth++;
else if (char === ")") {
depth--;
if (depth === 0) break;
}
}
if (depth !== 0) break;
const rawUrlValue = value.slice(openParenIndex + 1, index).trim();
const unquotedUrlValue = rawUrlValue.startsWith("\"") && rawUrlValue.endsWith("\"") || rawUrlValue.startsWith("'") && rawUrlValue.endsWith("'") ? rawUrlValue.slice(1, -1).trim() : rawUrlValue;
sanitized += value.slice(cursor, urlStart);
sanitized += hasJavascriptScheme(unquotedUrlValue) ? "url(about:blank)" : value.slice(urlStart, index + 1);
cursor = index + 1;
}
return sanitized + value.slice(cursor);
}
function sanitizeAttributeValue(attrName, value) {
if (urlAttributePattern.test(attrName) && hasJavascriptScheme(value)) return "about:blank";
return escapeAttributeValue(attrName.toLowerCase() === "style" ? sanitizeStyleValue(value) : value);
}
function sanitizeTranslatedHtml(html) {
html = html.replace(/([\w:-]+)\s*=\s*"([^"]*)"/g, (_, attrName, attrValue) => `${attrName}="${sanitizeAttributeValue(attrName, attrValue)}"`);
html = html.replace(/([\w:-]+)\s*=\s*'([^']*)'/g, (_, attrName, attrValue) => `${attrName}='${sanitizeAttributeValue(attrName, attrValue)}'`);
if (/\s*on\w+\s*=\s*["']?[^"'>]+["']?/i.test(html)) {
warn("Potentially dangerous event handlers detected in translation. Consider removing onclick, onerror, etc. from your translation messages.");
html = html.replace(/(\s+)on(\w+\s*=)/gi, "$1&#111;n$2");
}
html = html.replace(/(\s+(?:href|src|action|formaction)\s*=\s*)([^\s"'=<>`]+)/gi, (match, prefix, attrValue) => hasJavascriptScheme(attrValue) ? `${prefix}about:blank` : match);
return html;
}
const hasOwnProperty = Object.prototype.hasOwnProperty;
function hasOwn(obj, key) {
return hasOwnProperty.call(obj, key);
return hasOwnProperty.call(obj, key);
}
/* eslint-enable */
/**
* Useful Utilities By Evan you
* Modified by kazuya kawaguchi
* MIT License
* https://github.com/vuejs/vue-next/blob/master/packages/shared/src/index.ts
* https://github.com/vuejs/vue-next/blob/master/packages/shared/src/codeframe.ts
*/
* Useful Utilities By Evan you
* Modified by kazuya kawaguchi
* MIT License
* https://github.com/vuejs/vue-next/blob/master/packages/shared/src/index.ts
* https://github.com/vuejs/vue-next/blob/master/packages/shared/src/codeframe.ts
*/
const isArray = Array.isArray;
const isFunction = (val) => typeof val === 'function';
const isString = (val) => typeof val === 'string';
const isBoolean = (val) => typeof val === 'boolean';
const isSymbol = (val) => typeof val === 'symbol';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const isObject = (val) => val !== null && typeof val === 'object';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const isFunction = (val) => typeof val === "function";
const isString = (val) => typeof val === "string";
const isBoolean = (val) => typeof val === "boolean";
const isSymbol = (val) => typeof val === "symbol";
const isObject = (val) => val !== null && typeof val === "object";
const isPromise = (val) => {
return isObject(val) && isFunction(val.then) && isFunction(val.catch);
return isObject(val) && isFunction(val.then) && isFunction(val.catch);
};
const objectToString = Object.prototype.toString;
const toTypeString = (value) => objectToString.call(value);
const isPlainObject = (val) => toTypeString(val) === '[object Object]';
// for converting list and named values to displayed strings.
const isPlainObject = (val) => toTypeString(val) === "[object Object]";
const toDisplayString = (val) => {
return val == null
? ''
: isArray(val) || (isPlainObject(val) && val.toString === objectToString)
? JSON.stringify(val, null, 2)
: String(val);
return val == null ? "" : isArray(val) || isPlainObject(val) && val.toString === objectToString ? JSON.stringify(val, null, 2) : String(val);
};
function join(items, separator = '') {
return items.reduce((str, item, index) => (index === 0 ? str + item : str + separator + item), '');
function join(items, separator = "") {
return items.reduce((str, item, index) => index === 0 ? str + item : str + separator + item, "");
}
const RANGE = 2;
function generateCodeFrame(source, start = 0, end = source.length) {
const lines = source.split(/\r?\n/);
let count = 0;
const res = [];
for (let i = 0; i < lines.length; i++) {
count += lines[i].length + 1;
if (count >= start) {
for (let j = i - RANGE; j <= i + RANGE || end > count; j++) {
if (j < 0 || j >= lines.length)
continue;
const line = j + 1;
res.push(`${line}${' '.repeat(3 - String(line).length)}| ${lines[j]}`);
const lineLength = lines[j].length;
if (j === i) {
// push underline
const pad = start - (count - lineLength) + 1;
const length = Math.max(1, end > count ? lineLength - pad : end - start);
res.push(` | ` + ' '.repeat(pad) + '^'.repeat(length));
}
else if (j > i) {
if (end > count) {
const length = Math.max(Math.min(end - count, lineLength), 1);
res.push(` | ` + '^'.repeat(length));
}
count += lineLength + 1;
}
}
break;
}
}
return res.join('\n');
const lines = source.split(/\r?\n/);
let count = 0;
const res = [];
for (let i = 0; i < lines.length; i++) {
count += lines[i].length + 1;
if (count >= start) {
for (let j = i - RANGE; j <= i + RANGE || end > count; j++) {
if (j < 0 || j >= lines.length) continue;
const line = j + 1;
res.push(`${line}${" ".repeat(3 - String(line).length)}| ${lines[j]}`);
const lineLength = lines[j].length;
if (j === i) {
const pad = start - (count - lineLength) + 1;
const length = Math.max(1, end > count ? lineLength - pad : end - start);
res.push(` | ` + " ".repeat(pad) + "^".repeat(length));
} else if (j > i) {
if (end > count) {
const length = Math.max(Math.min(end - count, lineLength), 1);
res.push(` | ` + "^".repeat(length));
}
count += lineLength + 1;
}
}
break;
}
}
return res.join("\n");
}
function warn(msg, err) {
if (typeof console !== 'undefined') {
console.warn(`[intlify] ` + msg);
/* istanbul ignore if */
if (err) {
console.warn(err.stack);
}
}
}
const hasWarned = {};
function warnOnce(msg) {
if (!hasWarned[msg]) {
hasWarned[msg] = true;
warn(msg);
}
}
//#endregion
//#region packages/shared/src/emitter.ts
/**
* Event emitter, forked from the below:
* - original repository url: https://github.com/developit/mitt
* - code url: https://github.com/developit/mitt/blob/master/src/index.ts
* - author: Jason Miller (https://github.com/developit)
* - license: MIT
*/
/**
* Create a event emitter
*
* @returns An event emitter
*/
* Create a event emitter
*
* @returns An event emitter
*/
function createEmitter() {
const events = new Map();
const emitter = {
events,
on(event, handler) {
const handlers = events.get(event);
const added = handlers && handlers.push(handler);
if (!added) {
events.set(event, [handler]);
}
},
off(event, handler) {
const handlers = events.get(event);
if (handlers) {
handlers.splice(handlers.indexOf(handler) >>> 0, 1);
}
},
emit(event, payload) {
(events.get(event) || [])
.slice()
.map(handler => handler(payload));
(events.get('*') || [])
.slice()
.map(handler => handler(event, payload));
}
};
return emitter;
const events = /* @__PURE__ */ new Map();
return {
events,
on(event, handler) {
const handlers = events.get(event);
if (!(handlers && handlers.push(handler))) events.set(event, [handler]);
},
off(event, handler) {
const handlers = events.get(event);
if (handlers) handlers.splice(handlers.indexOf(handler) >>> 0, 1);
},
emit(event, payload) {
(events.get(event) || []).slice().map((handler) => handler(payload));
(events.get("*") || []).slice().map((handler) => handler(event, payload));
}
};
}
//#endregion
//#region packages/shared/src/messages.ts
const isNotObjectOrIsArray = (val) => !isObject(val) || isArray(val);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function deepCopy(src, des) {
// src and des should both be objects, and none of them can be a array
if (isNotObjectOrIsArray(src) || isNotObjectOrIsArray(des)) {
throw new Error('Invalid value');
}
const stack = [{ src, des }];
while (stack.length) {
const { src, des } = stack.pop();
// using `Object.keys` which skips prototype properties
Object.keys(src).forEach(key => {
if (key === '__proto__') {
return;
}
// if src[key] is an object/array, set des[key]
// to empty object/array to prevent setting by reference
if (isObject(src[key]) && !isObject(des[key])) {
des[key] = Array.isArray(src[key]) ? [] : create();
}
if (isNotObjectOrIsArray(des[key]) || isNotObjectOrIsArray(src[key])) {
// replace with src[key] when:
// src[key] or des[key] is not an object, or
// src[key] or des[key] is an array
des[key] = src[key];
}
else {
// src[key] and des[key] are both objects, merge them
stack.push({ src: src[key], des: des[key] });
}
});
}
if (isNotObjectOrIsArray(src) || isNotObjectOrIsArray(des)) throw new Error("Invalid value");
const stack = [{
src,
des
}];
while (stack.length) {
const { src, des } = stack.pop();
Object.keys(src).forEach((key) => {
if (key === "__proto__") return;
if (isObject(src[key]) && !isObject(des[key])) des[key] = Array.isArray(src[key]) ? [] : create();
if (isNotObjectOrIsArray(des[key]) || isNotObjectOrIsArray(src[key])) des[key] = src[key];
else stack.push({
src: src[key],
des: des[key]
});
});
}
}
export { assign, create, createEmitter, deepCopy, escapeHtml, format, friendlyJSONstringify, generateCodeFrame, generateFormatCacheKey, getGlobalThis, hasOwn, inBrowser, isArray, isBoolean, isDate, isEmptyObject, isFunction, isNumber, isObject, isPlainObject, isPromise, isRegExp, isString, isSymbol, join, makeSymbol, mark, measure, objectToString, toDisplayString, toTypeString, warn, warnOnce };
//#endregion
export { assign, create, createEmitter, deepCopy, escapeHtml, format, friendlyJSONstringify, generateCodeFrame, generateFormatCacheKey, getGlobalThis, hasOwn, inBrowser, isArray, isBoolean, isDate, isEmptyObject, isFunction, isKeylessObject, isNumber, isObject, isPlainObject, isPromise, isRegExp, isString, isSymbol, join, makeSymbol, mark, measure, objectToString, sanitizeTranslatedHtml, toDisplayString, toTypeString, warn, warnOnce };
{
"name": "@intlify/shared",
"version": "12.0.0-alpha.3",
"description": "@intlify/shared",
"keywords": [
"i18n",
"internationalization",
"intlify",
"utitlity"
],
"license": "MIT",
"version": "12.0.0-alpha.4",
"author": {

@@ -16,3 +9,7 @@ "name": "kazuya kawaguchi",

},
"homepage": "https://github.com/intlify/vue-i18n/tree/master/packages/shared#readme",
"license": "MIT",
"funding": "https://github.com/sponsors/kazupon",
"bugs": {
"url": "https://github.com/intlify/vue-i18n/issues"
},
"repository": {

@@ -23,5 +20,17 @@ "type": "git",

},
"bugs": {
"url": "https://github.com/intlify/vue-i18n/issues"
"keywords": [
"i18n",
"internationalization",
"intlify",
"utitlity"
],
"homepage": "https://github.com/intlify/vue-i18n/tree/master/packages/shared#readme",
"publishConfig": {
"access": "public"
},
"engines": {
"node": ">= 22"
},
"type": "module",
"sideEffects": false,
"files": [

@@ -31,18 +40,5 @@ "dist"

"module": "dist/shared.js",
"types": "dist/shared.d.ts",
"engines": {
"node": ">= 16"
},
"buildOptions": {
"name": "IntlifyShared",
"formats": [
"mjs",
"browser"
]
},
"exports": {
".": {
"types": "./dist/shared.d.ts",
"import": "./dist/shared.js",
"browser": "./dist/shared.esm-browser.js",
"node": {

@@ -53,3 +49,5 @@ "import": {

}
}
},
"import": "./dist/shared.js",
"browser": "./dist/shared.esm-browser.js"
},

@@ -59,8 +57,10 @@ "./dist/*": "./dist/*",

},
"funding": "https://github.com/sponsors/kazupon",
"publishConfig": {
"access": "public"
},
"sideEffects": false,
"type": "module"
"types": "dist/shared.d.ts",
"buildOptions": {
"name": "IntlifyShared",
"formats": [
"mjs",
"browser"
]
}
}

@@ -6,2 +6,3 @@ # @intlify/shared

## Forks
The implementation of this module is contains code forked from other packages or projects:

@@ -8,0 +9,0 @@