source: imaps-frontend/node_modules/object-inspect/index.js@ 0c6b92a

main
Last change on this file since 0c6b92a was 0c6b92a, checked in by stefan toskovski <stefantoska84@…>, 5 weeks ago

Pred finalna verzija

  • Property mode set to 100644
File size: 18.8 KB
Line 
1var hasMap = typeof Map === 'function' && Map.prototype;
2var mapSizeDescriptor = Object.getOwnPropertyDescriptor && hasMap ? Object.getOwnPropertyDescriptor(Map.prototype, 'size') : null;
3var mapSize = hasMap && mapSizeDescriptor && typeof mapSizeDescriptor.get === 'function' ? mapSizeDescriptor.get : null;
4var mapForEach = hasMap && Map.prototype.forEach;
5var hasSet = typeof Set === 'function' && Set.prototype;
6var setSizeDescriptor = Object.getOwnPropertyDescriptor && hasSet ? Object.getOwnPropertyDescriptor(Set.prototype, 'size') : null;
7var setSize = hasSet && setSizeDescriptor && typeof setSizeDescriptor.get === 'function' ? setSizeDescriptor.get : null;
8var setForEach = hasSet && Set.prototype.forEach;
9var hasWeakMap = typeof WeakMap === 'function' && WeakMap.prototype;
10var weakMapHas = hasWeakMap ? WeakMap.prototype.has : null;
11var hasWeakSet = typeof WeakSet === 'function' && WeakSet.prototype;
12var weakSetHas = hasWeakSet ? WeakSet.prototype.has : null;
13var hasWeakRef = typeof WeakRef === 'function' && WeakRef.prototype;
14var weakRefDeref = hasWeakRef ? WeakRef.prototype.deref : null;
15var booleanValueOf = Boolean.prototype.valueOf;
16var objectToString = Object.prototype.toString;
17var functionToString = Function.prototype.toString;
18var $match = String.prototype.match;
19var $slice = String.prototype.slice;
20var $replace = String.prototype.replace;
21var $toUpperCase = String.prototype.toUpperCase;
22var $toLowerCase = String.prototype.toLowerCase;
23var $test = RegExp.prototype.test;
24var $concat = Array.prototype.concat;
25var $join = Array.prototype.join;
26var $arrSlice = Array.prototype.slice;
27var $floor = Math.floor;
28var bigIntValueOf = typeof BigInt === 'function' ? BigInt.prototype.valueOf : null;
29var gOPS = Object.getOwnPropertySymbols;
30var symToString = typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol' ? Symbol.prototype.toString : null;
31var hasShammedSymbols = typeof Symbol === 'function' && typeof Symbol.iterator === 'object';
32// ie, `has-tostringtag/shams
33var toStringTag = typeof Symbol === 'function' && Symbol.toStringTag && (typeof Symbol.toStringTag === hasShammedSymbols ? 'object' : 'symbol')
34 ? Symbol.toStringTag
35 : null;
36var isEnumerable = Object.prototype.propertyIsEnumerable;
37
38var gPO = (typeof Reflect === 'function' ? Reflect.getPrototypeOf : Object.getPrototypeOf) || (
39 [].__proto__ === Array.prototype // eslint-disable-line no-proto
40 ? function (O) {
41 return O.__proto__; // eslint-disable-line no-proto
42 }
43 : null
44);
45
46function addNumericSeparator(num, str) {
47 if (
48 num === Infinity
49 || num === -Infinity
50 || num !== num
51 || (num && num > -1000 && num < 1000)
52 || $test.call(/e/, str)
53 ) {
54 return str;
55 }
56 var sepRegex = /[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;
57 if (typeof num === 'number') {
58 var int = num < 0 ? -$floor(-num) : $floor(num); // trunc(num)
59 if (int !== num) {
60 var intStr = String(int);
61 var dec = $slice.call(str, intStr.length + 1);
62 return $replace.call(intStr, sepRegex, '$&_') + '.' + $replace.call($replace.call(dec, /([0-9]{3})/g, '$&_'), /_$/, '');
63 }
64 }
65 return $replace.call(str, sepRegex, '$&_');
66}
67
68var utilInspect = require('./util.inspect');
69var inspectCustom = utilInspect.custom;
70var inspectSymbol = isSymbol(inspectCustom) ? inspectCustom : null;
71
72var quotes = {
73 __proto__: null,
74 'double': '"',
75 single: "'"
76};
77var quoteREs = {
78 __proto__: null,
79 'double': /(["\\])/g,
80 single: /(['\\])/g
81};
82
83module.exports = function inspect_(obj, options, depth, seen) {
84 var opts = options || {};
85
86 if (has(opts, 'quoteStyle') && !has(quotes, opts.quoteStyle)) {
87 throw new TypeError('option "quoteStyle" must be "single" or "double"');
88 }
89 if (
90 has(opts, 'maxStringLength') && (typeof opts.maxStringLength === 'number'
91 ? opts.maxStringLength < 0 && opts.maxStringLength !== Infinity
92 : opts.maxStringLength !== null
93 )
94 ) {
95 throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');
96 }
97 var customInspect = has(opts, 'customInspect') ? opts.customInspect : true;
98 if (typeof customInspect !== 'boolean' && customInspect !== 'symbol') {
99 throw new TypeError('option "customInspect", if provided, must be `true`, `false`, or `\'symbol\'`');
100 }
101
102 if (
103 has(opts, 'indent')
104 && opts.indent !== null
105 && opts.indent !== '\t'
106 && !(parseInt(opts.indent, 10) === opts.indent && opts.indent > 0)
107 ) {
108 throw new TypeError('option "indent" must be "\\t", an integer > 0, or `null`');
109 }
110 if (has(opts, 'numericSeparator') && typeof opts.numericSeparator !== 'boolean') {
111 throw new TypeError('option "numericSeparator", if provided, must be `true` or `false`');
112 }
113 var numericSeparator = opts.numericSeparator;
114
115 if (typeof obj === 'undefined') {
116 return 'undefined';
117 }
118 if (obj === null) {
119 return 'null';
120 }
121 if (typeof obj === 'boolean') {
122 return obj ? 'true' : 'false';
123 }
124
125 if (typeof obj === 'string') {
126 return inspectString(obj, opts);
127 }
128 if (typeof obj === 'number') {
129 if (obj === 0) {
130 return Infinity / obj > 0 ? '0' : '-0';
131 }
132 var str = String(obj);
133 return numericSeparator ? addNumericSeparator(obj, str) : str;
134 }
135 if (typeof obj === 'bigint') {
136 var bigIntStr = String(obj) + 'n';
137 return numericSeparator ? addNumericSeparator(obj, bigIntStr) : bigIntStr;
138 }
139
140 var maxDepth = typeof opts.depth === 'undefined' ? 5 : opts.depth;
141 if (typeof depth === 'undefined') { depth = 0; }
142 if (depth >= maxDepth && maxDepth > 0 && typeof obj === 'object') {
143 return isArray(obj) ? '[Array]' : '[Object]';
144 }
145
146 var indent = getIndent(opts, depth);
147
148 if (typeof seen === 'undefined') {
149 seen = [];
150 } else if (indexOf(seen, obj) >= 0) {
151 return '[Circular]';
152 }
153
154 function inspect(value, from, noIndent) {
155 if (from) {
156 seen = $arrSlice.call(seen);
157 seen.push(from);
158 }
159 if (noIndent) {
160 var newOpts = {
161 depth: opts.depth
162 };
163 if (has(opts, 'quoteStyle')) {
164 newOpts.quoteStyle = opts.quoteStyle;
165 }
166 return inspect_(value, newOpts, depth + 1, seen);
167 }
168 return inspect_(value, opts, depth + 1, seen);
169 }
170
171 if (typeof obj === 'function' && !isRegExp(obj)) { // in older engines, regexes are callable
172 var name = nameOf(obj);
173 var keys = arrObjKeys(obj, inspect);
174 return '[Function' + (name ? ': ' + name : ' (anonymous)') + ']' + (keys.length > 0 ? ' { ' + $join.call(keys, ', ') + ' }' : '');
175 }
176 if (isSymbol(obj)) {
177 var symString = hasShammedSymbols ? $replace.call(String(obj), /^(Symbol\(.*\))_[^)]*$/, '$1') : symToString.call(obj);
178 return typeof obj === 'object' && !hasShammedSymbols ? markBoxed(symString) : symString;
179 }
180 if (isElement(obj)) {
181 var s = '<' + $toLowerCase.call(String(obj.nodeName));
182 var attrs = obj.attributes || [];
183 for (var i = 0; i < attrs.length; i++) {
184 s += ' ' + attrs[i].name + '=' + wrapQuotes(quote(attrs[i].value), 'double', opts);
185 }
186 s += '>';
187 if (obj.childNodes && obj.childNodes.length) { s += '...'; }
188 s += '</' + $toLowerCase.call(String(obj.nodeName)) + '>';
189 return s;
190 }
191 if (isArray(obj)) {
192 if (obj.length === 0) { return '[]'; }
193 var xs = arrObjKeys(obj, inspect);
194 if (indent && !singleLineValues(xs)) {
195 return '[' + indentedJoin(xs, indent) + ']';
196 }
197 return '[ ' + $join.call(xs, ', ') + ' ]';
198 }
199 if (isError(obj)) {
200 var parts = arrObjKeys(obj, inspect);
201 if (!('cause' in Error.prototype) && 'cause' in obj && !isEnumerable.call(obj, 'cause')) {
202 return '{ [' + String(obj) + '] ' + $join.call($concat.call('[cause]: ' + inspect(obj.cause), parts), ', ') + ' }';
203 }
204 if (parts.length === 0) { return '[' + String(obj) + ']'; }
205 return '{ [' + String(obj) + '] ' + $join.call(parts, ', ') + ' }';
206 }
207 if (typeof obj === 'object' && customInspect) {
208 if (inspectSymbol && typeof obj[inspectSymbol] === 'function' && utilInspect) {
209 return utilInspect(obj, { depth: maxDepth - depth });
210 } else if (customInspect !== 'symbol' && typeof obj.inspect === 'function') {
211 return obj.inspect();
212 }
213 }
214 if (isMap(obj)) {
215 var mapParts = [];
216 if (mapForEach) {
217 mapForEach.call(obj, function (value, key) {
218 mapParts.push(inspect(key, obj, true) + ' => ' + inspect(value, obj));
219 });
220 }
221 return collectionOf('Map', mapSize.call(obj), mapParts, indent);
222 }
223 if (isSet(obj)) {
224 var setParts = [];
225 if (setForEach) {
226 setForEach.call(obj, function (value) {
227 setParts.push(inspect(value, obj));
228 });
229 }
230 return collectionOf('Set', setSize.call(obj), setParts, indent);
231 }
232 if (isWeakMap(obj)) {
233 return weakCollectionOf('WeakMap');
234 }
235 if (isWeakSet(obj)) {
236 return weakCollectionOf('WeakSet');
237 }
238 if (isWeakRef(obj)) {
239 return weakCollectionOf('WeakRef');
240 }
241 if (isNumber(obj)) {
242 return markBoxed(inspect(Number(obj)));
243 }
244 if (isBigInt(obj)) {
245 return markBoxed(inspect(bigIntValueOf.call(obj)));
246 }
247 if (isBoolean(obj)) {
248 return markBoxed(booleanValueOf.call(obj));
249 }
250 if (isString(obj)) {
251 return markBoxed(inspect(String(obj)));
252 }
253 // note: in IE 8, sometimes `global !== window` but both are the prototypes of each other
254 /* eslint-env browser */
255 if (typeof window !== 'undefined' && obj === window) {
256 return '{ [object Window] }';
257 }
258 if (
259 (typeof globalThis !== 'undefined' && obj === globalThis)
260 || (typeof global !== 'undefined' && obj === global)
261 ) {
262 return '{ [object globalThis] }';
263 }
264 if (!isDate(obj) && !isRegExp(obj)) {
265 var ys = arrObjKeys(obj, inspect);
266 var isPlainObject = gPO ? gPO(obj) === Object.prototype : obj instanceof Object || obj.constructor === Object;
267 var protoTag = obj instanceof Object ? '' : 'null prototype';
268 var stringTag = !isPlainObject && toStringTag && Object(obj) === obj && toStringTag in obj ? $slice.call(toStr(obj), 8, -1) : protoTag ? 'Object' : '';
269 var constructorTag = isPlainObject || typeof obj.constructor !== 'function' ? '' : obj.constructor.name ? obj.constructor.name + ' ' : '';
270 var tag = constructorTag + (stringTag || protoTag ? '[' + $join.call($concat.call([], stringTag || [], protoTag || []), ': ') + '] ' : '');
271 if (ys.length === 0) { return tag + '{}'; }
272 if (indent) {
273 return tag + '{' + indentedJoin(ys, indent) + '}';
274 }
275 return tag + '{ ' + $join.call(ys, ', ') + ' }';
276 }
277 return String(obj);
278};
279
280function wrapQuotes(s, defaultStyle, opts) {
281 var style = opts.quoteStyle || defaultStyle;
282 var quoteChar = quotes[style];
283 return quoteChar + s + quoteChar;
284}
285
286function quote(s) {
287 return $replace.call(String(s), /"/g, '&quot;');
288}
289
290function isArray(obj) { return toStr(obj) === '[object Array]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); }
291function isDate(obj) { return toStr(obj) === '[object Date]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); }
292function isRegExp(obj) { return toStr(obj) === '[object RegExp]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); }
293function isError(obj) { return toStr(obj) === '[object Error]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); }
294function isString(obj) { return toStr(obj) === '[object String]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); }
295function isNumber(obj) { return toStr(obj) === '[object Number]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); }
296function isBoolean(obj) { return toStr(obj) === '[object Boolean]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); }
297
298// Symbol and BigInt do have Symbol.toStringTag by spec, so that can't be used to eliminate false positives
299function isSymbol(obj) {
300 if (hasShammedSymbols) {
301 return obj && typeof obj === 'object' && obj instanceof Symbol;
302 }
303 if (typeof obj === 'symbol') {
304 return true;
305 }
306 if (!obj || typeof obj !== 'object' || !symToString) {
307 return false;
308 }
309 try {
310 symToString.call(obj);
311 return true;
312 } catch (e) {}
313 return false;
314}
315
316function isBigInt(obj) {
317 if (!obj || typeof obj !== 'object' || !bigIntValueOf) {
318 return false;
319 }
320 try {
321 bigIntValueOf.call(obj);
322 return true;
323 } catch (e) {}
324 return false;
325}
326
327var hasOwn = Object.prototype.hasOwnProperty || function (key) { return key in this; };
328function has(obj, key) {
329 return hasOwn.call(obj, key);
330}
331
332function toStr(obj) {
333 return objectToString.call(obj);
334}
335
336function nameOf(f) {
337 if (f.name) { return f.name; }
338 var m = $match.call(functionToString.call(f), /^function\s*([\w$]+)/);
339 if (m) { return m[1]; }
340 return null;
341}
342
343function indexOf(xs, x) {
344 if (xs.indexOf) { return xs.indexOf(x); }
345 for (var i = 0, l = xs.length; i < l; i++) {
346 if (xs[i] === x) { return i; }
347 }
348 return -1;
349}
350
351function isMap(x) {
352 if (!mapSize || !x || typeof x !== 'object') {
353 return false;
354 }
355 try {
356 mapSize.call(x);
357 try {
358 setSize.call(x);
359 } catch (s) {
360 return true;
361 }
362 return x instanceof Map; // core-js workaround, pre-v2.5.0
363 } catch (e) {}
364 return false;
365}
366
367function isWeakMap(x) {
368 if (!weakMapHas || !x || typeof x !== 'object') {
369 return false;
370 }
371 try {
372 weakMapHas.call(x, weakMapHas);
373 try {
374 weakSetHas.call(x, weakSetHas);
375 } catch (s) {
376 return true;
377 }
378 return x instanceof WeakMap; // core-js workaround, pre-v2.5.0
379 } catch (e) {}
380 return false;
381}
382
383function isWeakRef(x) {
384 if (!weakRefDeref || !x || typeof x !== 'object') {
385 return false;
386 }
387 try {
388 weakRefDeref.call(x);
389 return true;
390 } catch (e) {}
391 return false;
392}
393
394function isSet(x) {
395 if (!setSize || !x || typeof x !== 'object') {
396 return false;
397 }
398 try {
399 setSize.call(x);
400 try {
401 mapSize.call(x);
402 } catch (m) {
403 return true;
404 }
405 return x instanceof Set; // core-js workaround, pre-v2.5.0
406 } catch (e) {}
407 return false;
408}
409
410function isWeakSet(x) {
411 if (!weakSetHas || !x || typeof x !== 'object') {
412 return false;
413 }
414 try {
415 weakSetHas.call(x, weakSetHas);
416 try {
417 weakMapHas.call(x, weakMapHas);
418 } catch (s) {
419 return true;
420 }
421 return x instanceof WeakSet; // core-js workaround, pre-v2.5.0
422 } catch (e) {}
423 return false;
424}
425
426function isElement(x) {
427 if (!x || typeof x !== 'object') { return false; }
428 if (typeof HTMLElement !== 'undefined' && x instanceof HTMLElement) {
429 return true;
430 }
431 return typeof x.nodeName === 'string' && typeof x.getAttribute === 'function';
432}
433
434function inspectString(str, opts) {
435 if (str.length > opts.maxStringLength) {
436 var remaining = str.length - opts.maxStringLength;
437 var trailer = '... ' + remaining + ' more character' + (remaining > 1 ? 's' : '');
438 return inspectString($slice.call(str, 0, opts.maxStringLength), opts) + trailer;
439 }
440 var quoteRE = quoteREs[opts.quoteStyle || 'single'];
441 quoteRE.lastIndex = 0;
442 // eslint-disable-next-line no-control-regex
443 var s = $replace.call($replace.call(str, quoteRE, '\\$1'), /[\x00-\x1f]/g, lowbyte);
444 return wrapQuotes(s, 'single', opts);
445}
446
447function lowbyte(c) {
448 var n = c.charCodeAt(0);
449 var x = {
450 8: 'b',
451 9: 't',
452 10: 'n',
453 12: 'f',
454 13: 'r'
455 }[n];
456 if (x) { return '\\' + x; }
457 return '\\x' + (n < 0x10 ? '0' : '') + $toUpperCase.call(n.toString(16));
458}
459
460function markBoxed(str) {
461 return 'Object(' + str + ')';
462}
463
464function weakCollectionOf(type) {
465 return type + ' { ? }';
466}
467
468function collectionOf(type, size, entries, indent) {
469 var joinedEntries = indent ? indentedJoin(entries, indent) : $join.call(entries, ', ');
470 return type + ' (' + size + ') {' + joinedEntries + '}';
471}
472
473function singleLineValues(xs) {
474 for (var i = 0; i < xs.length; i++) {
475 if (indexOf(xs[i], '\n') >= 0) {
476 return false;
477 }
478 }
479 return true;
480}
481
482function getIndent(opts, depth) {
483 var baseIndent;
484 if (opts.indent === '\t') {
485 baseIndent = '\t';
486 } else if (typeof opts.indent === 'number' && opts.indent > 0) {
487 baseIndent = $join.call(Array(opts.indent + 1), ' ');
488 } else {
489 return null;
490 }
491 return {
492 base: baseIndent,
493 prev: $join.call(Array(depth + 1), baseIndent)
494 };
495}
496
497function indentedJoin(xs, indent) {
498 if (xs.length === 0) { return ''; }
499 var lineJoiner = '\n' + indent.prev + indent.base;
500 return lineJoiner + $join.call(xs, ',' + lineJoiner) + '\n' + indent.prev;
501}
502
503function arrObjKeys(obj, inspect) {
504 var isArr = isArray(obj);
505 var xs = [];
506 if (isArr) {
507 xs.length = obj.length;
508 for (var i = 0; i < obj.length; i++) {
509 xs[i] = has(obj, i) ? inspect(obj[i], obj) : '';
510 }
511 }
512 var syms = typeof gOPS === 'function' ? gOPS(obj) : [];
513 var symMap;
514 if (hasShammedSymbols) {
515 symMap = {};
516 for (var k = 0; k < syms.length; k++) {
517 symMap['$' + syms[k]] = syms[k];
518 }
519 }
520
521 for (var key in obj) { // eslint-disable-line no-restricted-syntax
522 if (!has(obj, key)) { continue; } // eslint-disable-line no-restricted-syntax, no-continue
523 if (isArr && String(Number(key)) === key && key < obj.length) { continue; } // eslint-disable-line no-restricted-syntax, no-continue
524 if (hasShammedSymbols && symMap['$' + key] instanceof Symbol) {
525 // this is to prevent shammed Symbols, which are stored as strings, from being included in the string key section
526 continue; // eslint-disable-line no-restricted-syntax, no-continue
527 } else if ($test.call(/[^\w$]/, key)) {
528 xs.push(inspect(key, obj) + ': ' + inspect(obj[key], obj));
529 } else {
530 xs.push(key + ': ' + inspect(obj[key], obj));
531 }
532 }
533 if (typeof gOPS === 'function') {
534 for (var j = 0; j < syms.length; j++) {
535 if (isEnumerable.call(obj, syms[j])) {
536 xs.push('[' + inspect(syms[j]) + ']: ' + inspect(obj[syms[j]], obj));
537 }
538 }
539 }
540 return xs;
541}
Note: See TracBrowser for help on using the repository browser.