版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

208 строки
7.1 KiB

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