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

196 строки
7.0 KiB

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