shared.cjs.prod.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*!
  2. * shared v9.2.2
  3. * (c) 2022 kazuya kawaguchi
  4. * Released under the MIT License.
  5. */
  6. 'use strict';
  7. Object.defineProperty(exports, '__esModule', { value: true });
  8. /**
  9. * Original Utilities
  10. * written by kazuya kawaguchi
  11. */
  12. const inBrowser = typeof window !== 'undefined';
  13. let mark;
  14. let measure;
  15. const RE_ARGS = /\{([0-9a-zA-Z]+)\}/g;
  16. /* eslint-disable */
  17. function format(message, ...args) {
  18. if (args.length === 1 && isObject(args[0])) {
  19. args = args[0];
  20. }
  21. if (!args || !args.hasOwnProperty) {
  22. args = {};
  23. }
  24. return message.replace(RE_ARGS, (match, identifier) => {
  25. return args.hasOwnProperty(identifier) ? args[identifier] : '';
  26. });
  27. }
  28. const hasSymbol = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
  29. const makeSymbol = (name) => hasSymbol ? Symbol(name) : name;
  30. const generateFormatCacheKey = (locale, key, source) => friendlyJSONstringify({ l: locale, k: key, s: source });
  31. const friendlyJSONstringify = (json) => JSON.stringify(json)
  32. .replace(/\u2028/g, '\\u2028')
  33. .replace(/\u2029/g, '\\u2029')
  34. .replace(/\u0027/g, '\\u0027');
  35. const isNumber = (val) => typeof val === 'number' && isFinite(val);
  36. const isDate = (val) => toTypeString(val) === '[object Date]';
  37. const isRegExp = (val) => toTypeString(val) === '[object RegExp]';
  38. const isEmptyObject = (val) => isPlainObject(val) && Object.keys(val).length === 0;
  39. function warn(msg, err) {
  40. if (typeof console !== 'undefined') {
  41. console.warn(`[intlify] ` + msg);
  42. /* istanbul ignore if */
  43. if (err) {
  44. console.warn(err.stack);
  45. }
  46. }
  47. }
  48. const assign = Object.assign;
  49. let _globalThis;
  50. const getGlobalThis = () => {
  51. // prettier-ignore
  52. return (_globalThis ||
  53. (_globalThis =
  54. typeof globalThis !== 'undefined'
  55. ? globalThis
  56. : typeof self !== 'undefined'
  57. ? self
  58. : typeof window !== 'undefined'
  59. ? window
  60. : typeof global !== 'undefined'
  61. ? global
  62. : {}));
  63. };
  64. function escapeHtml(rawText) {
  65. return rawText
  66. .replace(/</g, '&lt;')
  67. .replace(/>/g, '&gt;')
  68. .replace(/"/g, '&quot;')
  69. .replace(/'/g, '&apos;');
  70. }
  71. const hasOwnProperty = Object.prototype.hasOwnProperty;
  72. function hasOwn(obj, key) {
  73. return hasOwnProperty.call(obj, key);
  74. }
  75. /* eslint-enable */
  76. /**
  77. * Useful Utilities By Evan you
  78. * Modified by kazuya kawaguchi
  79. * MIT License
  80. * https://github.com/vuejs/vue-next/blob/master/packages/shared/src/index.ts
  81. * https://github.com/vuejs/vue-next/blob/master/packages/shared/src/codeframe.ts
  82. */
  83. const isArray = Array.isArray;
  84. const isFunction = (val) => typeof val === 'function';
  85. const isString = (val) => typeof val === 'string';
  86. const isBoolean = (val) => typeof val === 'boolean';
  87. const isSymbol = (val) => typeof val === 'symbol';
  88. const isObject = (val) => // eslint-disable-line
  89. val !== null && typeof val === 'object';
  90. const isPromise = (val) => {
  91. return isObject(val) && isFunction(val.then) && isFunction(val.catch);
  92. };
  93. const objectToString = Object.prototype.toString;
  94. const toTypeString = (value) => objectToString.call(value);
  95. const isPlainObject = (val) => toTypeString(val) === '[object Object]';
  96. // for converting list and named values to displayed strings.
  97. const toDisplayString = (val) => {
  98. return val == null
  99. ? ''
  100. : isArray(val) || (isPlainObject(val) && val.toString === objectToString)
  101. ? JSON.stringify(val, null, 2)
  102. : String(val);
  103. };
  104. const RANGE = 2;
  105. function generateCodeFrame(source, start = 0, end = source.length) {
  106. const lines = source.split(/\r?\n/);
  107. let count = 0;
  108. const res = [];
  109. for (let i = 0; i < lines.length; i++) {
  110. count += lines[i].length + 1;
  111. if (count >= start) {
  112. for (let j = i - RANGE; j <= i + RANGE || end > count; j++) {
  113. if (j < 0 || j >= lines.length)
  114. continue;
  115. const line = j + 1;
  116. res.push(`${line}${' '.repeat(3 - String(line).length)}| ${lines[j]}`);
  117. const lineLength = lines[j].length;
  118. if (j === i) {
  119. // push underline
  120. const pad = start - (count - lineLength) + 1;
  121. const length = Math.max(1, end > count ? lineLength - pad : end - start);
  122. res.push(` | ` + ' '.repeat(pad) + '^'.repeat(length));
  123. }
  124. else if (j > i) {
  125. if (end > count) {
  126. const length = Math.max(Math.min(end - count, lineLength), 1);
  127. res.push(` | ` + '^'.repeat(length));
  128. }
  129. count += lineLength + 1;
  130. }
  131. }
  132. break;
  133. }
  134. }
  135. return res.join('\n');
  136. }
  137. /**
  138. * Event emitter, forked from the below:
  139. * - original repository url: https://github.com/developit/mitt
  140. * - code url: https://github.com/developit/mitt/blob/master/src/index.ts
  141. * - author: Jason Miller (https://github.com/developit)
  142. * - license: MIT
  143. */
  144. /**
  145. * Create a event emitter
  146. *
  147. * @returns An event emitter
  148. */
  149. function createEmitter() {
  150. const events = new Map();
  151. const emitter = {
  152. events,
  153. on(event, handler) {
  154. const handlers = events.get(event);
  155. const added = handlers && handlers.push(handler);
  156. if (!added) {
  157. events.set(event, [handler]);
  158. }
  159. },
  160. off(event, handler) {
  161. const handlers = events.get(event);
  162. if (handlers) {
  163. handlers.splice(handlers.indexOf(handler) >>> 0, 1);
  164. }
  165. },
  166. emit(event, payload) {
  167. (events.get(event) || [])
  168. .slice()
  169. .map(handler => handler(payload));
  170. (events.get('*') || [])
  171. .slice()
  172. .map(handler => handler(event, payload));
  173. }
  174. };
  175. return emitter;
  176. }
  177. exports.assign = assign;
  178. exports.createEmitter = createEmitter;
  179. exports.escapeHtml = escapeHtml;
  180. exports.format = format;
  181. exports.friendlyJSONstringify = friendlyJSONstringify;
  182. exports.generateCodeFrame = generateCodeFrame;
  183. exports.generateFormatCacheKey = generateFormatCacheKey;
  184. exports.getGlobalThis = getGlobalThis;
  185. exports.hasOwn = hasOwn;
  186. exports.inBrowser = inBrowser;
  187. exports.isArray = isArray;
  188. exports.isBoolean = isBoolean;
  189. exports.isDate = isDate;
  190. exports.isEmptyObject = isEmptyObject;
  191. exports.isFunction = isFunction;
  192. exports.isNumber = isNumber;
  193. exports.isObject = isObject;
  194. exports.isPlainObject = isPlainObject;
  195. exports.isPromise = isPromise;
  196. exports.isRegExp = isRegExp;
  197. exports.isString = isString;
  198. exports.isSymbol = isSymbol;
  199. exports.makeSymbol = makeSymbol;
  200. exports.mark = mark;
  201. exports.measure = measure;
  202. exports.objectToString = objectToString;
  203. exports.toDisplayString = toDisplayString;
  204. exports.toTypeString = toTypeString;
  205. exports.warn = warn;