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

884 рядки
28 KiB

  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  3. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  4. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.loupe = {}));
  5. }(this, (function (exports) { 'use strict';
  6. function _typeof(obj) {
  7. "@babel/helpers - typeof";
  8. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  9. _typeof = function (obj) {
  10. return typeof obj;
  11. };
  12. } else {
  13. _typeof = function (obj) {
  14. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  15. };
  16. }
  17. return _typeof(obj);
  18. }
  19. function _slicedToArray(arr, i) {
  20. return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
  21. }
  22. function _arrayWithHoles(arr) {
  23. if (Array.isArray(arr)) return arr;
  24. }
  25. function _iterableToArrayLimit(arr, i) {
  26. if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
  27. var _arr = [];
  28. var _n = true;
  29. var _d = false;
  30. var _e = undefined;
  31. try {
  32. for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
  33. _arr.push(_s.value);
  34. if (i && _arr.length === i) break;
  35. }
  36. } catch (err) {
  37. _d = true;
  38. _e = err;
  39. } finally {
  40. try {
  41. if (!_n && _i["return"] != null) _i["return"]();
  42. } finally {
  43. if (_d) throw _e;
  44. }
  45. }
  46. return _arr;
  47. }
  48. function _unsupportedIterableToArray(o, minLen) {
  49. if (!o) return;
  50. if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  51. var n = Object.prototype.toString.call(o).slice(8, -1);
  52. if (n === "Object" && o.constructor) n = o.constructor.name;
  53. if (n === "Map" || n === "Set") return Array.from(o);
  54. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
  55. }
  56. function _arrayLikeToArray(arr, len) {
  57. if (len == null || len > arr.length) len = arr.length;
  58. for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
  59. return arr2;
  60. }
  61. function _nonIterableRest() {
  62. throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  63. }
  64. var ansiColors = {
  65. bold: ['1', '22'],
  66. dim: ['2', '22'],
  67. italic: ['3', '23'],
  68. underline: ['4', '24'],
  69. // 5 & 6 are blinking
  70. inverse: ['7', '27'],
  71. hidden: ['8', '28'],
  72. strike: ['9', '29'],
  73. // 10-20 are fonts
  74. // 21-29 are resets for 1-9
  75. black: ['30', '39'],
  76. red: ['31', '39'],
  77. green: ['32', '39'],
  78. yellow: ['33', '39'],
  79. blue: ['34', '39'],
  80. magenta: ['35', '39'],
  81. cyan: ['36', '39'],
  82. white: ['37', '39'],
  83. brightblack: ['30;1', '39'],
  84. brightred: ['31;1', '39'],
  85. brightgreen: ['32;1', '39'],
  86. brightyellow: ['33;1', '39'],
  87. brightblue: ['34;1', '39'],
  88. brightmagenta: ['35;1', '39'],
  89. brightcyan: ['36;1', '39'],
  90. brightwhite: ['37;1', '39'],
  91. grey: ['90', '39']
  92. };
  93. var styles = {
  94. special: 'cyan',
  95. number: 'yellow',
  96. bigint: 'yellow',
  97. boolean: 'yellow',
  98. undefined: 'grey',
  99. null: 'bold',
  100. string: 'green',
  101. symbol: 'green',
  102. date: 'magenta',
  103. regexp: 'red'
  104. };
  105. var truncator = '…';
  106. function colorise(value, styleType) {
  107. var color = ansiColors[styles[styleType]] || ansiColors[styleType];
  108. if (!color) {
  109. return String(value);
  110. }
  111. return "\x1B[".concat(color[0], "m").concat(String(value), "\x1B[").concat(color[1], "m");
  112. }
  113. function normaliseOptions() {
  114. var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
  115. _ref$showHidden = _ref.showHidden,
  116. showHidden = _ref$showHidden === void 0 ? false : _ref$showHidden,
  117. _ref$depth = _ref.depth,
  118. depth = _ref$depth === void 0 ? 2 : _ref$depth,
  119. _ref$colors = _ref.colors,
  120. colors = _ref$colors === void 0 ? false : _ref$colors,
  121. _ref$customInspect = _ref.customInspect,
  122. customInspect = _ref$customInspect === void 0 ? true : _ref$customInspect,
  123. _ref$showProxy = _ref.showProxy,
  124. showProxy = _ref$showProxy === void 0 ? false : _ref$showProxy,
  125. _ref$maxArrayLength = _ref.maxArrayLength,
  126. maxArrayLength = _ref$maxArrayLength === void 0 ? Infinity : _ref$maxArrayLength,
  127. _ref$breakLength = _ref.breakLength,
  128. breakLength = _ref$breakLength === void 0 ? Infinity : _ref$breakLength,
  129. _ref$seen = _ref.seen,
  130. seen = _ref$seen === void 0 ? [] : _ref$seen,
  131. _ref$truncate = _ref.truncate,
  132. truncate = _ref$truncate === void 0 ? Infinity : _ref$truncate,
  133. _ref$stylize = _ref.stylize,
  134. stylize = _ref$stylize === void 0 ? String : _ref$stylize;
  135. var options = {
  136. showHidden: Boolean(showHidden),
  137. depth: Number(depth),
  138. colors: Boolean(colors),
  139. customInspect: Boolean(customInspect),
  140. showProxy: Boolean(showProxy),
  141. maxArrayLength: Number(maxArrayLength),
  142. breakLength: Number(breakLength),
  143. truncate: Number(truncate),
  144. seen: seen,
  145. stylize: stylize
  146. };
  147. if (options.colors) {
  148. options.stylize = colorise;
  149. }
  150. return options;
  151. }
  152. function truncate(string, length) {
  153. var tail = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : truncator;
  154. string = String(string);
  155. var tailLength = tail.length;
  156. var stringLength = string.length;
  157. if (tailLength > length && stringLength > tailLength) {
  158. return tail;
  159. }
  160. if (stringLength > length && stringLength > tailLength) {
  161. return "".concat(string.slice(0, length - tailLength)).concat(tail);
  162. }
  163. return string;
  164. } // eslint-disable-next-line complexity
  165. function inspectList(list, options, inspectItem) {
  166. var separator = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ', ';
  167. inspectItem = inspectItem || options.inspect;
  168. var size = list.length;
  169. if (size === 0) return '';
  170. var originalLength = options.truncate;
  171. var output = '';
  172. var peek = '';
  173. var truncated = '';
  174. for (var i = 0; i < size; i += 1) {
  175. var last = i + 1 === list.length;
  176. var secondToLast = i + 2 === list.length;
  177. truncated = "".concat(truncator, "(").concat(list.length - i, ")");
  178. var value = list[i]; // If there is more than one remaining we need to account for a separator of `, `
  179. options.truncate = originalLength - output.length - (last ? 0 : separator.length);
  180. var string = peek || inspectItem(value, options) + (last ? '' : separator);
  181. var nextLength = output.length + string.length;
  182. var truncatedLength = nextLength + truncated.length; // If this is the last element, and adding it would
  183. // take us over length, but adding the truncator wouldn't - then break now
  184. if (last && nextLength > originalLength && output.length + truncated.length <= originalLength) {
  185. break;
  186. } // If this isn't the last or second to last element to scan,
  187. // but the string is already over length then break here
  188. if (!last && !secondToLast && truncatedLength > originalLength) {
  189. break;
  190. } // Peek at the next string to determine if we should
  191. // break early before adding this item to the output
  192. peek = last ? '' : inspectItem(list[i + 1], options) + (secondToLast ? '' : separator); // If we have one element left, but this element and
  193. // the next takes over length, the break early
  194. if (!last && secondToLast && truncatedLength > originalLength && nextLength + peek.length > originalLength) {
  195. break;
  196. }
  197. output += string; // If the next element takes us to length -
  198. // but there are more after that, then we should truncate now
  199. if (!last && !secondToLast && nextLength + peek.length >= originalLength) {
  200. truncated = "".concat(truncator, "(").concat(list.length - i - 1, ")");
  201. break;
  202. }
  203. truncated = '';
  204. }
  205. return "".concat(output).concat(truncated);
  206. }
  207. function quoteComplexKey(key) {
  208. if (key.match(/^[a-zA-Z_][a-zA-Z_0-9]*$/)) {
  209. return key;
  210. }
  211. return JSON.stringify(key).replace(/'/g, "\\'").replace(/\\"/g, '"').replace(/(^"|"$)/g, "'");
  212. }
  213. function inspectProperty(_ref2, options) {
  214. var _ref3 = _slicedToArray(_ref2, 2),
  215. key = _ref3[0],
  216. value = _ref3[1];
  217. options.truncate -= 2;
  218. if (typeof key === 'string') {
  219. key = quoteComplexKey(key);
  220. } else if (typeof key !== 'number') {
  221. key = "[".concat(options.inspect(key, options), "]");
  222. }
  223. options.truncate -= key.length;
  224. value = options.inspect(value, options);
  225. return "".concat(key, ": ").concat(value);
  226. }
  227. function inspectArray(array, options) {
  228. // Object.keys will always output the Array indices first, so we can slice by
  229. // `array.length` to get non-index properties
  230. var nonIndexProperties = Object.keys(array).slice(array.length);
  231. if (!array.length && !nonIndexProperties.length) return '[]';
  232. options.truncate -= 4;
  233. var listContents = inspectList(array, options);
  234. options.truncate -= listContents.length;
  235. var propertyContents = '';
  236. if (nonIndexProperties.length) {
  237. propertyContents = inspectList(nonIndexProperties.map(function (key) {
  238. return [key, array[key]];
  239. }), options, inspectProperty);
  240. }
  241. return "[ ".concat(listContents).concat(propertyContents ? ", ".concat(propertyContents) : '', " ]");
  242. }
  243. /* !
  244. * Chai - getFuncName utility
  245. * Copyright(c) 2012-2016 Jake Luer <jake@alogicalparadox.com>
  246. * MIT Licensed
  247. */
  248. /**
  249. * ### .getFuncName(constructorFn)
  250. *
  251. * Returns the name of a function.
  252. * When a non-function instance is passed, returns `null`.
  253. * This also includes a polyfill function if `aFunc.name` is not defined.
  254. *
  255. * @name getFuncName
  256. * @param {Function} funct
  257. * @namespace Utils
  258. * @api public
  259. */
  260. var toString = Function.prototype.toString;
  261. var functionNameMatch = /\s*function(?:\s|\s*\/\*[^(?:*\/)]+\*\/\s*)*([^\s\(\/]+)/;
  262. function getFuncName(aFunc) {
  263. if (typeof aFunc !== 'function') {
  264. return null;
  265. }
  266. var name = '';
  267. if (typeof Function.prototype.name === 'undefined' && typeof aFunc.name === 'undefined') {
  268. // Here we run a polyfill if Function does not support the `name` property and if aFunc.name is not defined
  269. var match = toString.call(aFunc).match(functionNameMatch);
  270. if (match) {
  271. name = match[1];
  272. }
  273. } else {
  274. // If we've got a `name` property we just use it
  275. name = aFunc.name;
  276. }
  277. return name;
  278. }
  279. var getFuncName_1 = getFuncName;
  280. var getArrayName = function getArrayName(array) {
  281. // We need to special case Node.js' Buffers, which report to be Uint8Array
  282. if (typeof Buffer === 'function' && array instanceof Buffer) {
  283. return 'Buffer';
  284. }
  285. if (array[Symbol.toStringTag]) {
  286. return array[Symbol.toStringTag];
  287. }
  288. return getFuncName_1(array.constructor);
  289. };
  290. function inspectTypedArray(array, options) {
  291. var name = getArrayName(array);
  292. options.truncate -= name.length + 4; // Object.keys will always output the Array indices first, so we can slice by
  293. // `array.length` to get non-index properties
  294. var nonIndexProperties = Object.keys(array).slice(array.length);
  295. if (!array.length && !nonIndexProperties.length) return "".concat(name, "[]"); // As we know TypedArrays only contain Unsigned Integers, we can skip inspecting each one and simply
  296. // stylise the toString() value of them
  297. var output = '';
  298. for (var i = 0; i < array.length; i++) {
  299. var string = "".concat(options.stylize(truncate(array[i], options.truncate), 'number')).concat(i === array.length - 1 ? '' : ', ');
  300. options.truncate -= string.length;
  301. if (array[i] !== array.length && options.truncate <= 3) {
  302. output += "".concat(truncator, "(").concat(array.length - array[i] + 1, ")");
  303. break;
  304. }
  305. output += string;
  306. }
  307. var propertyContents = '';
  308. if (nonIndexProperties.length) {
  309. propertyContents = inspectList(nonIndexProperties.map(function (key) {
  310. return [key, array[key]];
  311. }), options, inspectProperty);
  312. }
  313. return "".concat(name, "[ ").concat(output).concat(propertyContents ? ", ".concat(propertyContents) : '', " ]");
  314. }
  315. function inspectDate(dateObject, options) {
  316. var stringRepresentation = dateObject.toJSON();
  317. if (stringRepresentation === null) {
  318. return 'Invalid Date';
  319. }
  320. var split = stringRepresentation.split('T');
  321. var date = split[0]; // If we need to - truncate the time portion, but never the date
  322. return options.stylize("".concat(date, "T").concat(truncate(split[1], options.truncate - date.length - 1)), 'date');
  323. }
  324. function inspectFunction(func, options) {
  325. var name = getFuncName_1(func);
  326. if (!name) {
  327. return options.stylize('[Function]', 'special');
  328. }
  329. return options.stylize("[Function ".concat(truncate(name, options.truncate - 11), "]"), 'special');
  330. }
  331. function inspectMapEntry(_ref, options) {
  332. var _ref2 = _slicedToArray(_ref, 2),
  333. key = _ref2[0],
  334. value = _ref2[1];
  335. options.truncate -= 4;
  336. key = options.inspect(key, options);
  337. options.truncate -= key.length;
  338. value = options.inspect(value, options);
  339. return "".concat(key, " => ").concat(value);
  340. } // IE11 doesn't support `map.entries()`
  341. function mapToEntries(map) {
  342. var entries = [];
  343. map.forEach(function (value, key) {
  344. entries.push([key, value]);
  345. });
  346. return entries;
  347. }
  348. function inspectMap(map, options) {
  349. var size = map.size - 1;
  350. if (size <= 0) {
  351. return 'Map{}';
  352. }
  353. options.truncate -= 7;
  354. return "Map{ ".concat(inspectList(mapToEntries(map), options, inspectMapEntry), " }");
  355. }
  356. var isNaN = Number.isNaN || function (i) {
  357. return i !== i;
  358. }; // eslint-disable-line no-self-compare
  359. function inspectNumber(number, options) {
  360. if (isNaN(number)) {
  361. return options.stylize('NaN', 'number');
  362. }
  363. if (number === Infinity) {
  364. return options.stylize('Infinity', 'number');
  365. }
  366. if (number === -Infinity) {
  367. return options.stylize('-Infinity', 'number');
  368. }
  369. if (number === 0) {
  370. return options.stylize(1 / number === Infinity ? '+0' : '-0', 'number');
  371. }
  372. return options.stylize(truncate(number, options.truncate), 'number');
  373. }
  374. function inspectBigInt(number, options) {
  375. var nums = truncate(number.toString(), options.truncate - 1);
  376. if (nums !== truncator) nums += 'n';
  377. return options.stylize(nums, 'bigint');
  378. }
  379. function inspectRegExp(value, options) {
  380. var flags = value.toString().split('/')[2];
  381. var sourceLength = options.truncate - (2 + flags.length);
  382. var source = value.source;
  383. return options.stylize("/".concat(truncate(source, sourceLength), "/").concat(flags), 'regexp');
  384. }
  385. function arrayFromSet(set) {
  386. var values = [];
  387. set.forEach(function (value) {
  388. values.push(value);
  389. });
  390. return values;
  391. }
  392. function inspectSet(set, options) {
  393. if (set.size === 0) return 'Set{}';
  394. options.truncate -= 7;
  395. return "Set{ ".concat(inspectList(arrayFromSet(set), options), " }");
  396. }
  397. var stringEscapeChars = new RegExp("['\\u0000-\\u001f\\u007f-\\u009f\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5" + "\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]", 'g');
  398. var escapeCharacters = {
  399. '\b': '\\b',
  400. '\t': '\\t',
  401. '\n': '\\n',
  402. '\f': '\\f',
  403. '\r': '\\r',
  404. "'": "\\'",
  405. '\\': '\\\\'
  406. };
  407. var hex = 16;
  408. var unicodeLength = 4;
  409. function escape(char) {
  410. return escapeCharacters[char] || "\\u".concat("0000".concat(char.charCodeAt(0).toString(hex)).slice(-unicodeLength));
  411. }
  412. function inspectString(string, options) {
  413. if (stringEscapeChars.test(string)) {
  414. string = string.replace(stringEscapeChars, escape);
  415. }
  416. return options.stylize("'".concat(truncate(string, options.truncate - 2), "'"), 'string');
  417. }
  418. function inspectSymbol(value) {
  419. if ('description' in Symbol.prototype) {
  420. return value.description ? "Symbol(".concat(value.description, ")") : 'Symbol()';
  421. }
  422. return value.toString();
  423. }
  424. var getPromiseValue = function getPromiseValue() {
  425. return 'Promise{…}';
  426. };
  427. try {
  428. var _process$binding = process.binding('util'),
  429. getPromiseDetails = _process$binding.getPromiseDetails,
  430. kPending = _process$binding.kPending,
  431. kRejected = _process$binding.kRejected;
  432. if (Array.isArray(getPromiseDetails(Promise.resolve()))) {
  433. getPromiseValue = function getPromiseValue(value, options) {
  434. var _getPromiseDetails = getPromiseDetails(value),
  435. _getPromiseDetails2 = _slicedToArray(_getPromiseDetails, 2),
  436. state = _getPromiseDetails2[0],
  437. innerValue = _getPromiseDetails2[1];
  438. if (state === kPending) {
  439. return 'Promise{<pending>}';
  440. }
  441. return "Promise".concat(state === kRejected ? '!' : '', "{").concat(options.inspect(innerValue, options), "}");
  442. };
  443. }
  444. } catch (notNode) {
  445. /* ignore */
  446. }
  447. var inspectPromise = getPromiseValue;
  448. function inspectObject(object, options) {
  449. var properties = Object.getOwnPropertyNames(object);
  450. var symbols = Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(object) : [];
  451. if (properties.length === 0 && symbols.length === 0) {
  452. return '{}';
  453. }
  454. options.truncate -= 4;
  455. options.seen = options.seen || [];
  456. if (options.seen.indexOf(object) >= 0) {
  457. return '[Circular]';
  458. }
  459. options.seen.push(object);
  460. var propertyContents = inspectList(properties.map(function (key) {
  461. return [key, object[key]];
  462. }), options, inspectProperty);
  463. var symbolContents = inspectList(symbols.map(function (key) {
  464. return [key, object[key]];
  465. }), options, inspectProperty);
  466. options.seen.pop();
  467. var sep = '';
  468. if (propertyContents && symbolContents) {
  469. sep = ', ';
  470. }
  471. return "{ ".concat(propertyContents).concat(sep).concat(symbolContents, " }");
  472. }
  473. var toStringTag = typeof Symbol !== 'undefined' && Symbol.toStringTag ? Symbol.toStringTag : false;
  474. function inspectClass(value, options) {
  475. var name = '';
  476. if (toStringTag && toStringTag in value) {
  477. name = value[toStringTag];
  478. }
  479. name = name || getFuncName_1(value.constructor); // Babel transforms anonymous classes to the name `_class`
  480. if (!name || name === '_class') {
  481. name = '<Anonymous Class>';
  482. }
  483. options.truncate -= name.length;
  484. return "".concat(name).concat(inspectObject(value, options));
  485. }
  486. function inspectArguments(args, options) {
  487. if (args.length === 0) return 'Arguments[]';
  488. options.truncate -= 13;
  489. return "Arguments[ ".concat(inspectList(args, options), " ]");
  490. }
  491. var errorKeys = ['stack', 'line', 'column', 'name', 'message', 'fileName', 'lineNumber', 'columnNumber', 'number', 'description'];
  492. function inspectObject$1(error, options) {
  493. var properties = Object.getOwnPropertyNames(error).filter(function (key) {
  494. return errorKeys.indexOf(key) === -1;
  495. });
  496. var name = error.name;
  497. options.truncate -= name.length;
  498. var message = '';
  499. if (typeof error.message === 'string') {
  500. message = truncate(error.message, options.truncate);
  501. } else {
  502. properties.unshift('message');
  503. }
  504. message = message ? ": ".concat(message) : '';
  505. options.truncate -= message.length + 5;
  506. var propertyContents = inspectList(properties.map(function (key) {
  507. return [key, error[key]];
  508. }), options, inspectProperty);
  509. return "".concat(name).concat(message).concat(propertyContents ? " { ".concat(propertyContents, " }") : '');
  510. }
  511. function inspectAttribute(_ref, options) {
  512. var _ref2 = _slicedToArray(_ref, 2),
  513. key = _ref2[0],
  514. value = _ref2[1];
  515. options.truncate -= 3;
  516. if (!value) {
  517. return "".concat(options.stylize(key, 'yellow'));
  518. }
  519. return "".concat(options.stylize(key, 'yellow'), "=").concat(options.stylize("\"".concat(value, "\""), 'string'));
  520. }
  521. function inspectHTMLCollection(collection, options) {
  522. // eslint-disable-next-line no-use-before-define
  523. return inspectList(collection, options, inspectHTML, '\n');
  524. }
  525. function inspectHTML(element, options) {
  526. var properties = element.getAttributeNames();
  527. var name = element.tagName.toLowerCase();
  528. var head = options.stylize("<".concat(name), 'special');
  529. var headClose = options.stylize(">", 'special');
  530. var tail = options.stylize("</".concat(name, ">"), 'special');
  531. options.truncate -= name.length * 2 + 5;
  532. var propertyContents = '';
  533. if (properties.length > 0) {
  534. propertyContents += ' ';
  535. propertyContents += inspectList(properties.map(function (key) {
  536. return [key, element.getAttribute(key)];
  537. }), options, inspectAttribute, ' ');
  538. }
  539. options.truncate -= propertyContents.length;
  540. var truncate = options.truncate;
  541. var children = inspectHTMLCollection(element.children, options);
  542. if (children && children.length > truncate) {
  543. children = "".concat(truncator, "(").concat(element.children.length, ")");
  544. }
  545. return "".concat(head).concat(propertyContents).concat(headClose).concat(children).concat(tail);
  546. }
  547. var symbolsSupported = typeof Symbol === 'function' && typeof Symbol.for === 'function';
  548. var chaiInspect = symbolsSupported ? Symbol.for('chai/inspect') : '@@chai/inspect';
  549. var nodeInspect = false;
  550. try {
  551. // eslint-disable-next-line global-require
  552. var nodeUtil = require('util');
  553. nodeInspect = nodeUtil.inspect ? nodeUtil.inspect.custom : false;
  554. } catch (noNodeInspect) {
  555. nodeInspect = false;
  556. }
  557. function FakeMap() {
  558. // eslint-disable-next-line prefer-template
  559. this.key = 'chai/loupe__' + Math.random() + Date.now();
  560. }
  561. FakeMap.prototype = {
  562. // eslint-disable-next-line object-shorthand
  563. get: function get(key) {
  564. return key[this.key];
  565. },
  566. // eslint-disable-next-line object-shorthand
  567. has: function has(key) {
  568. return this.key in key;
  569. },
  570. // eslint-disable-next-line object-shorthand
  571. set: function set(key, value) {
  572. if (Object.isExtensible(key)) {
  573. Object.defineProperty(key, this.key, {
  574. // eslint-disable-next-line object-shorthand
  575. value: value,
  576. configurable: true
  577. });
  578. }
  579. }
  580. };
  581. var constructorMap = new (typeof WeakMap === 'function' ? WeakMap : FakeMap)();
  582. var stringTagMap = {};
  583. var baseTypesMap = {
  584. undefined: function undefined$1(value, options) {
  585. return options.stylize('undefined', 'undefined');
  586. },
  587. null: function _null(value, options) {
  588. return options.stylize(null, 'null');
  589. },
  590. boolean: function boolean(value, options) {
  591. return options.stylize(value, 'boolean');
  592. },
  593. Boolean: function Boolean(value, options) {
  594. return options.stylize(value, 'boolean');
  595. },
  596. number: inspectNumber,
  597. Number: inspectNumber,
  598. bigint: inspectBigInt,
  599. BigInt: inspectBigInt,
  600. string: inspectString,
  601. String: inspectString,
  602. function: inspectFunction,
  603. Function: inspectFunction,
  604. symbol: inspectSymbol,
  605. // A Symbol polyfill will return `Symbol` not `symbol` from typedetect
  606. Symbol: inspectSymbol,
  607. Array: inspectArray,
  608. Date: inspectDate,
  609. Map: inspectMap,
  610. Set: inspectSet,
  611. RegExp: inspectRegExp,
  612. Promise: inspectPromise,
  613. // WeakSet, WeakMap are totally opaque to us
  614. WeakSet: function WeakSet(value, options) {
  615. return options.stylize('WeakSet{…}', 'special');
  616. },
  617. WeakMap: function WeakMap(value, options) {
  618. return options.stylize('WeakMap{…}', 'special');
  619. },
  620. Arguments: inspectArguments,
  621. Int8Array: inspectTypedArray,
  622. Uint8Array: inspectTypedArray,
  623. Uint8ClampedArray: inspectTypedArray,
  624. Int16Array: inspectTypedArray,
  625. Uint16Array: inspectTypedArray,
  626. Int32Array: inspectTypedArray,
  627. Uint32Array: inspectTypedArray,
  628. Float32Array: inspectTypedArray,
  629. Float64Array: inspectTypedArray,
  630. Generator: function Generator() {
  631. return '';
  632. },
  633. DataView: function DataView() {
  634. return '';
  635. },
  636. ArrayBuffer: function ArrayBuffer() {
  637. return '';
  638. },
  639. Error: inspectObject$1,
  640. HTMLCollection: inspectHTMLCollection,
  641. NodeList: inspectHTMLCollection
  642. }; // eslint-disable-next-line complexity
  643. var inspectCustom = function inspectCustom(value, options, type) {
  644. if (chaiInspect in value && typeof value[chaiInspect] === 'function') {
  645. return value[chaiInspect](options);
  646. }
  647. if (nodeInspect && nodeInspect in value && typeof value[nodeInspect] === 'function') {
  648. return value[nodeInspect](options.depth, options);
  649. }
  650. if ('inspect' in value && typeof value.inspect === 'function') {
  651. return value.inspect(options.depth, options);
  652. }
  653. if ('constructor' in value && constructorMap.has(value.constructor)) {
  654. return constructorMap.get(value.constructor)(value, options);
  655. }
  656. if (stringTagMap[type]) {
  657. return stringTagMap[type](value, options);
  658. }
  659. return '';
  660. };
  661. var toString$1 = Object.prototype.toString; // eslint-disable-next-line complexity
  662. function inspect(value, options) {
  663. options = normaliseOptions(options);
  664. options.inspect = inspect;
  665. var _options = options,
  666. customInspect = _options.customInspect;
  667. var type = value === null ? 'null' : _typeof(value);
  668. if (type === 'object') {
  669. type = toString$1.call(value).slice(8, -1);
  670. } // If it is a base value that we already support, then use Loupe's inspector
  671. if (baseTypesMap[type]) {
  672. return baseTypesMap[type](value, options);
  673. } // If `options.customInspect` is set to true then try to use the custom inspector
  674. if (customInspect && value) {
  675. var output = inspectCustom(value, options, type);
  676. if (output) {
  677. if (typeof output === 'string') return output;
  678. return inspect(output, options);
  679. }
  680. }
  681. var proto = value ? Object.getPrototypeOf(value) : false; // If it's a plain Object then use Loupe's inspector
  682. if (proto === Object.prototype || proto === null) {
  683. return inspectObject(value, options);
  684. } // Specifically account for HTMLElements
  685. // eslint-disable-next-line no-undef
  686. if (value && typeof HTMLElement === 'function' && value instanceof HTMLElement) {
  687. return inspectHTML(value, options);
  688. }
  689. if ('constructor' in value) {
  690. // If it is a class, inspect it like an object but add the constructor name
  691. if (value.constructor !== Object) {
  692. return inspectClass(value, options);
  693. } // If it is an object with an anonymous prototype, display it as an object.
  694. return inspectObject(value, options);
  695. } // last chance to check if it's an object
  696. if (value === Object(value)) {
  697. return inspectObject(value, options);
  698. } // We have run out of options! Just stringify the value
  699. return options.stylize(String(value), type);
  700. }
  701. function registerConstructor(constructor, inspector) {
  702. if (constructorMap.has(constructor)) {
  703. return false;
  704. }
  705. constructorMap.set(constructor, inspector);
  706. return true;
  707. }
  708. function registerStringTag(stringTag, inspector) {
  709. if (stringTag in stringTagMap) {
  710. return false;
  711. }
  712. stringTagMap[stringTag] = inspector;
  713. return true;
  714. }
  715. var custom = chaiInspect;
  716. exports.custom = custom;
  717. exports.default = inspect;
  718. exports.inspect = inspect;
  719. exports.registerConstructor = registerConstructor;
  720. exports.registerStringTag = registerStringTag;
  721. Object.defineProperty(exports, '__esModule', { value: true });
  722. })));