123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- /*!
- * shared v9.2.2
- * (c) 2022 kazuya kawaguchi
- * Released under the MIT License.
- */
- 'use strict';
- Object.defineProperty(exports, '__esModule', { value: true });
- /**
- * Original Utilities
- * written by kazuya kawaguchi
- */
- const inBrowser = typeof window !== 'undefined';
- let mark;
- let measure;
- const RE_ARGS = /\{([0-9a-zA-Z]+)\}/g;
- /* eslint-disable */
- 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] : '';
- });
- }
- const hasSymbol = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
- const makeSymbol = (name) => hasSymbol ? Symbol(name) : 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 isEmptyObject = (val) => isPlainObject(val) && Object.keys(val).length === 0;
- function warn(msg, err) {
- if (typeof console !== 'undefined') {
- console.warn(`[intlify] ` + msg);
- /* istanbul ignore if */
- if (err) {
- console.warn(err.stack);
- }
- }
- }
- const assign = Object.assign;
- let _globalThis;
- const getGlobalThis = () => {
- // prettier-ignore
- return (_globalThis ||
- (_globalThis =
- typeof globalThis !== 'undefined'
- ? globalThis
- : typeof self !== 'undefined'
- ? self
- : typeof window !== 'undefined'
- ? window
- : typeof global !== 'undefined'
- ? global
- : {}));
- };
- function escapeHtml(rawText) {
- return rawText
- .replace(/</g, '<')
- .replace(/>/g, '>')
- .replace(/"/g, '"')
- .replace(/'/g, ''');
- }
- const hasOwnProperty = Object.prototype.hasOwnProperty;
- function hasOwn(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
- */
- 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';
- const isObject = (val) => // eslint-disable-line
- val !== null && typeof val === 'object';
- const isPromise = (val) => {
- 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 toDisplayString = (val) => {
- return val == null
- ? ''
- : isArray(val) || (isPlainObject(val) && val.toString === objectToString)
- ? JSON.stringify(val, null, 2)
- : String(val);
- };
- 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');
- }
- /**
- * 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
- */
- 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;
- }
- exports.assign = assign;
- exports.createEmitter = createEmitter;
- exports.escapeHtml = escapeHtml;
- exports.format = format;
- exports.friendlyJSONstringify = friendlyJSONstringify;
- exports.generateCodeFrame = generateCodeFrame;
- exports.generateFormatCacheKey = generateFormatCacheKey;
- exports.getGlobalThis = getGlobalThis;
- exports.hasOwn = hasOwn;
- exports.inBrowser = inBrowser;
- exports.isArray = isArray;
- exports.isBoolean = isBoolean;
- exports.isDate = isDate;
- exports.isEmptyObject = isEmptyObject;
- exports.isFunction = isFunction;
- exports.isNumber = isNumber;
- exports.isObject = isObject;
- exports.isPlainObject = isPlainObject;
- exports.isPromise = isPromise;
- exports.isRegExp = isRegExp;
- exports.isString = isString;
- exports.isSymbol = isSymbol;
- exports.makeSymbol = makeSymbol;
- exports.mark = mark;
- exports.measure = measure;
- exports.objectToString = objectToString;
- exports.toDisplayString = toDisplayString;
- exports.toTypeString = toTypeString;
- exports.warn = warn;
|