Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

index.js 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. var hasMap = typeof Map === 'function' && Map.prototype;
  2. var mapSizeDescriptor = Object.getOwnPropertyDescriptor && hasMap ? Object.getOwnPropertyDescriptor(Map.prototype, 'size') : null;
  3. var mapSize = hasMap && mapSizeDescriptor && typeof mapSizeDescriptor.get === 'function' ? mapSizeDescriptor.get : null;
  4. var mapForEach = hasMap && Map.prototype.forEach;
  5. var hasSet = typeof Set === 'function' && Set.prototype;
  6. var setSizeDescriptor = Object.getOwnPropertyDescriptor && hasSet ? Object.getOwnPropertyDescriptor(Set.prototype, 'size') : null;
  7. var setSize = hasSet && setSizeDescriptor && typeof setSizeDescriptor.get === 'function' ? setSizeDescriptor.get : null;
  8. var setForEach = hasSet && Set.prototype.forEach;
  9. var booleanValueOf = Boolean.prototype.valueOf;
  10. var objectToString = Object.prototype.toString;
  11. var bigIntValueOf = typeof BigInt === 'function' ? BigInt.prototype.valueOf : null;
  12. var inspectCustom = require('./util.inspect').custom;
  13. var inspectSymbol = (inspectCustom && isSymbol(inspectCustom)) ? inspectCustom : null;
  14. module.exports = function inspect_ (obj, opts, depth, seen) {
  15. if (!opts) opts = {};
  16. if (has(opts, 'quoteStyle') && (opts.quoteStyle !== 'single' && opts.quoteStyle !== 'double')) {
  17. throw new TypeError('option "quoteStyle" must be "single" or "double"');
  18. }
  19. if (typeof obj === 'undefined') {
  20. return 'undefined';
  21. }
  22. if (obj === null) {
  23. return 'null';
  24. }
  25. if (typeof obj === 'boolean') {
  26. return obj ? 'true' : 'false';
  27. }
  28. if (typeof obj === 'string') {
  29. return inspectString(obj, opts);
  30. }
  31. if (typeof obj === 'number') {
  32. if (obj === 0) {
  33. return Infinity / obj > 0 ? '0' : '-0';
  34. }
  35. return String(obj);
  36. }
  37. if (typeof obj === 'bigint') {
  38. return String(obj) + 'n';
  39. }
  40. var maxDepth = typeof opts.depth === 'undefined' ? 5 : opts.depth;
  41. if (typeof depth === 'undefined') depth = 0;
  42. if (depth >= maxDepth && maxDepth > 0 && typeof obj === 'object') {
  43. return '[Object]';
  44. }
  45. if (typeof seen === 'undefined') seen = [];
  46. else if (indexOf(seen, obj) >= 0) {
  47. return '[Circular]';
  48. }
  49. function inspect (value, from) {
  50. if (from) {
  51. seen = seen.slice();
  52. seen.push(from);
  53. }
  54. return inspect_(value, opts, depth + 1, seen);
  55. }
  56. if (typeof obj === 'function') {
  57. var name = nameOf(obj);
  58. return '[Function' + (name ? ': ' + name : '') + ']';
  59. }
  60. if (isSymbol(obj)) {
  61. var symString = Symbol.prototype.toString.call(obj);
  62. return typeof obj === 'object' ? markBoxed(symString) : symString;
  63. }
  64. if (isElement(obj)) {
  65. var s = '<' + String(obj.nodeName).toLowerCase();
  66. var attrs = obj.attributes || [];
  67. for (var i = 0; i < attrs.length; i++) {
  68. s += ' ' + attrs[i].name + '=' + wrapQuotes(quote(attrs[i].value), 'double', opts);
  69. }
  70. s += '>';
  71. if (obj.childNodes && obj.childNodes.length) s += '...';
  72. s += '</' + String(obj.nodeName).toLowerCase() + '>';
  73. return s;
  74. }
  75. if (isArray(obj)) {
  76. if (obj.length === 0) return '[]';
  77. return '[ ' + arrObjKeys(obj, inspect).join(', ') + ' ]';
  78. }
  79. if (isError(obj)) {
  80. var parts = arrObjKeys(obj, inspect);
  81. if (parts.length === 0) return '[' + String(obj) + ']';
  82. return '{ [' + String(obj) + '] ' + parts.join(', ') + ' }';
  83. }
  84. if (typeof obj === 'object') {
  85. if (inspectSymbol && typeof obj[inspectSymbol] === 'function') {
  86. return obj[inspectSymbol]();
  87. } else if (typeof obj.inspect === 'function') {
  88. return obj.inspect();
  89. }
  90. }
  91. if (isMap(obj)) {
  92. var parts = [];
  93. mapForEach.call(obj, function (value, key) {
  94. parts.push(inspect(key, obj) + ' => ' + inspect(value, obj));
  95. });
  96. return collectionOf('Map', mapSize.call(obj), parts);
  97. }
  98. if (isSet(obj)) {
  99. var parts = [];
  100. setForEach.call(obj, function (value ) {
  101. parts.push(inspect(value, obj));
  102. });
  103. return collectionOf('Set', setSize.call(obj), parts);
  104. }
  105. if (isNumber(obj)) {
  106. return markBoxed(inspect(Number(obj)));
  107. }
  108. if (isBigInt(obj)) {
  109. return markBoxed(inspect(bigIntValueOf.call(obj)));
  110. }
  111. if (isBoolean(obj)) {
  112. return markBoxed(booleanValueOf.call(obj));
  113. }
  114. if (isString(obj)) {
  115. return markBoxed(inspect(String(obj)));
  116. }
  117. if (!isDate(obj) && !isRegExp(obj)) {
  118. var xs = arrObjKeys(obj, inspect);
  119. if (xs.length === 0) return '{}';
  120. return '{ ' + xs.join(', ') + ' }';
  121. }
  122. return String(obj);
  123. };
  124. function wrapQuotes (s, defaultStyle, opts) {
  125. var quoteChar = (opts.quoteStyle || defaultStyle) === 'double' ? '"' : "'";
  126. return quoteChar + s + quoteChar;
  127. }
  128. function quote (s) {
  129. return String(s).replace(/"/g, '&quot;');
  130. }
  131. function isArray (obj) { return toStr(obj) === '[object Array]'; }
  132. function isDate (obj) { return toStr(obj) === '[object Date]'; }
  133. function isRegExp (obj) { return toStr(obj) === '[object RegExp]'; }
  134. function isError (obj) { return toStr(obj) === '[object Error]'; }
  135. function isSymbol (obj) { return toStr(obj) === '[object Symbol]'; }
  136. function isString (obj) { return toStr(obj) === '[object String]'; }
  137. function isNumber (obj) { return toStr(obj) === '[object Number]'; }
  138. function isBigInt (obj) { return toStr(obj) === '[object BigInt]'; }
  139. function isBoolean (obj) { return toStr(obj) === '[object Boolean]'; }
  140. var hasOwn = Object.prototype.hasOwnProperty || function (key) { return key in this; };
  141. function has (obj, key) {
  142. return hasOwn.call(obj, key);
  143. }
  144. function toStr (obj) {
  145. return objectToString.call(obj);
  146. }
  147. function nameOf (f) {
  148. if (f.name) return f.name;
  149. var m = String(f).match(/^function\s*([\w$]+)/);
  150. if (m) return m[1];
  151. }
  152. function indexOf (xs, x) {
  153. if (xs.indexOf) return xs.indexOf(x);
  154. for (var i = 0, l = xs.length; i < l; i++) {
  155. if (xs[i] === x) return i;
  156. }
  157. return -1;
  158. }
  159. function isMap (x) {
  160. if (!mapSize) {
  161. return false;
  162. }
  163. try {
  164. mapSize.call(x);
  165. try {
  166. setSize.call(x);
  167. } catch (s) {
  168. return true;
  169. }
  170. return x instanceof Map; // core-js workaround, pre-v2.5.0
  171. } catch (e) {}
  172. return false;
  173. }
  174. function isSet (x) {
  175. if (!setSize) {
  176. return false;
  177. }
  178. try {
  179. setSize.call(x);
  180. try {
  181. mapSize.call(x);
  182. } catch (m) {
  183. return true;
  184. }
  185. return x instanceof Set; // core-js workaround, pre-v2.5.0
  186. } catch (e) {}
  187. return false;
  188. }
  189. function isElement (x) {
  190. if (!x || typeof x !== 'object') return false;
  191. if (typeof HTMLElement !== 'undefined' && x instanceof HTMLElement) {
  192. return true;
  193. }
  194. return typeof x.nodeName === 'string'
  195. && typeof x.getAttribute === 'function'
  196. ;
  197. }
  198. function inspectString (str, opts) {
  199. var s = str.replace(/(['\\])/g, '\\$1').replace(/[\x00-\x1f]/g, lowbyte);
  200. return wrapQuotes(s, 'single', opts);
  201. }
  202. function lowbyte (c) {
  203. var n = c.charCodeAt(0);
  204. var x = { 8: 'b', 9: 't', 10: 'n', 12: 'f', 13: 'r' }[n];
  205. if (x) return '\\' + x;
  206. return '\\x' + (n < 0x10 ? '0' : '') + n.toString(16);
  207. }
  208. function markBoxed (str) {
  209. return 'Object(' + str + ')';
  210. }
  211. function collectionOf (type, size, entries) {
  212. return type + ' (' + size + ') {' + entries.join(', ') + '}';
  213. }
  214. function arrObjKeys (obj, inspect) {
  215. var isArr = isArray(obj);
  216. var xs = [];
  217. if (isArr) {
  218. xs.length = obj.length;
  219. for (var i = 0; i < obj.length; i++) {
  220. xs[i] = has(obj, i) ? inspect(obj[i], obj) : '';
  221. }
  222. }
  223. for (var key in obj) {
  224. if (!has(obj, key)) continue;
  225. if (isArr && String(Number(key)) === key && key < obj.length) continue;
  226. if (/[^\w$]/.test(key)) {
  227. xs.push(inspect(key, obj) + ': ' + inspect(obj[key], obj));
  228. } else {
  229. xs.push(key + ': ' + inspect(obj[key], obj));
  230. }
  231. }
  232. return xs;
  233. }