| | |
| | | var booleanValueOf = Boolean.prototype.valueOf; |
| | | var objectToString = Object.prototype.toString; |
| | | var functionToString = Function.prototype.toString; |
| | | var match = String.prototype.match; |
| | | var $match = String.prototype.match; |
| | | var $slice = String.prototype.slice; |
| | | var $replace = String.prototype.replace; |
| | | var $toUpperCase = String.prototype.toUpperCase; |
| | | var $toLowerCase = String.prototype.toLowerCase; |
| | | var $test = RegExp.prototype.test; |
| | | var $concat = Array.prototype.concat; |
| | | var $join = Array.prototype.join; |
| | | var $arrSlice = Array.prototype.slice; |
| | | var $floor = Math.floor; |
| | | var bigIntValueOf = typeof BigInt === 'function' ? BigInt.prototype.valueOf : null; |
| | | var gOPS = Object.getOwnPropertySymbols; |
| | | var symToString = typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol' ? Symbol.prototype.toString : null; |
| | | var hasShammedSymbols = typeof Symbol === 'function' && typeof Symbol.iterator === 'object'; |
| | | // ie, `has-tostringtag/shams |
| | | var toStringTag = typeof Symbol === 'function' && Symbol.toStringTag && (typeof Symbol.toStringTag === hasShammedSymbols ? 'object' : 'symbol') |
| | | ? Symbol.toStringTag |
| | | : null; |
| | | var isEnumerable = Object.prototype.propertyIsEnumerable; |
| | | |
| | | var gPO = (typeof Reflect === 'function' ? Reflect.getPrototypeOf : Object.getPrototypeOf) || ( |
| | |
| | | : null |
| | | ); |
| | | |
| | | function addNumericSeparator(num, str) { |
| | | if ( |
| | | num === Infinity |
| | | || num === -Infinity |
| | | || num !== num |
| | | || (num && num > -1000 && num < 1000) |
| | | || $test.call(/e/, str) |
| | | ) { |
| | | return str; |
| | | } |
| | | var sepRegex = /[0-9](?=(?:[0-9]{3})+(?![0-9]))/g; |
| | | if (typeof num === 'number') { |
| | | var int = num < 0 ? -$floor(-num) : $floor(num); // trunc(num) |
| | | if (int !== num) { |
| | | var intStr = String(int); |
| | | var dec = $slice.call(str, intStr.length + 1); |
| | | return $replace.call(intStr, sepRegex, '$&_') + '.' + $replace.call($replace.call(dec, /([0-9]{3})/g, '$&_'), /_$/, ''); |
| | | } |
| | | } |
| | | return $replace.call(str, sepRegex, '$&_'); |
| | | } |
| | | |
| | | var inspectCustom = require('./util.inspect').custom; |
| | | var inspectSymbol = inspectCustom && isSymbol(inspectCustom) ? inspectCustom : null; |
| | | var toStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag !== 'undefined' ? Symbol.toStringTag : null; |
| | | |
| | | module.exports = function inspect_(obj, options, depth, seen) { |
| | | var opts = options || {}; |
| | |
| | | && opts.indent !== '\t' |
| | | && !(parseInt(opts.indent, 10) === opts.indent && opts.indent > 0) |
| | | ) { |
| | | throw new TypeError('options "indent" must be "\\t", an integer > 0, or `null`'); |
| | | throw new TypeError('option "indent" must be "\\t", an integer > 0, or `null`'); |
| | | } |
| | | if (has(opts, 'numericSeparator') && typeof opts.numericSeparator !== 'boolean') { |
| | | throw new TypeError('option "numericSeparator", if provided, must be `true` or `false`'); |
| | | } |
| | | var numericSeparator = opts.numericSeparator; |
| | | |
| | | if (typeof obj === 'undefined') { |
| | | return 'undefined'; |
| | |
| | | if (obj === 0) { |
| | | return Infinity / obj > 0 ? '0' : '-0'; |
| | | } |
| | | return String(obj); |
| | | var str = String(obj); |
| | | return numericSeparator ? addNumericSeparator(obj, str) : str; |
| | | } |
| | | if (typeof obj === 'bigint') { |
| | | return String(obj) + 'n'; |
| | | var bigIntStr = String(obj) + 'n'; |
| | | return numericSeparator ? addNumericSeparator(obj, bigIntStr) : bigIntStr; |
| | | } |
| | | |
| | | var maxDepth = typeof opts.depth === 'undefined' ? 5 : opts.depth; |
| | |
| | | |
| | | function inspect(value, from, noIndent) { |
| | | if (from) { |
| | | seen = seen.slice(); |
| | | seen = $arrSlice.call(seen); |
| | | seen.push(from); |
| | | } |
| | | if (noIndent) { |
| | |
| | | if (typeof obj === 'function') { |
| | | var name = nameOf(obj); |
| | | var keys = arrObjKeys(obj, inspect); |
| | | return '[Function' + (name ? ': ' + name : ' (anonymous)') + ']' + (keys.length > 0 ? ' { ' + keys.join(', ') + ' }' : ''); |
| | | return '[Function' + (name ? ': ' + name : ' (anonymous)') + ']' + (keys.length > 0 ? ' { ' + $join.call(keys, ', ') + ' }' : ''); |
| | | } |
| | | if (isSymbol(obj)) { |
| | | var symString = hasShammedSymbols ? String(obj).replace(/^(Symbol\(.*\))_[^)]*$/, '$1') : symToString.call(obj); |
| | | var symString = hasShammedSymbols ? $replace.call(String(obj), /^(Symbol\(.*\))_[^)]*$/, '$1') : symToString.call(obj); |
| | | return typeof obj === 'object' && !hasShammedSymbols ? markBoxed(symString) : symString; |
| | | } |
| | | if (isElement(obj)) { |
| | | var s = '<' + String(obj.nodeName).toLowerCase(); |
| | | var s = '<' + $toLowerCase.call(String(obj.nodeName)); |
| | | var attrs = obj.attributes || []; |
| | | for (var i = 0; i < attrs.length; i++) { |
| | | s += ' ' + attrs[i].name + '=' + wrapQuotes(quote(attrs[i].value), 'double', opts); |
| | | } |
| | | s += '>'; |
| | | if (obj.childNodes && obj.childNodes.length) { s += '...'; } |
| | | s += '</' + String(obj.nodeName).toLowerCase() + '>'; |
| | | s += '</' + $toLowerCase.call(String(obj.nodeName)) + '>'; |
| | | return s; |
| | | } |
| | | if (isArray(obj)) { |
| | |
| | | if (indent && !singleLineValues(xs)) { |
| | | return '[' + indentedJoin(xs, indent) + ']'; |
| | | } |
| | | return '[ ' + xs.join(', ') + ' ]'; |
| | | return '[ ' + $join.call(xs, ', ') + ' ]'; |
| | | } |
| | | if (isError(obj)) { |
| | | var parts = arrObjKeys(obj, inspect); |
| | | if ('cause' in obj && !isEnumerable.call(obj, 'cause')) { |
| | | return '{ [' + String(obj) + '] ' + $join.call($concat.call('[cause]: ' + inspect(obj.cause), parts), ', ') + ' }'; |
| | | } |
| | | if (parts.length === 0) { return '[' + String(obj) + ']'; } |
| | | return '{ [' + String(obj) + '] ' + parts.join(', ') + ' }'; |
| | | return '{ [' + String(obj) + '] ' + $join.call(parts, ', ') + ' }'; |
| | | } |
| | | if (typeof obj === 'object' && customInspect) { |
| | | if (inspectSymbol && typeof obj[inspectSymbol] === 'function') { |
| | |
| | | var ys = arrObjKeys(obj, inspect); |
| | | var isPlainObject = gPO ? gPO(obj) === Object.prototype : obj instanceof Object || obj.constructor === Object; |
| | | var protoTag = obj instanceof Object ? '' : 'null prototype'; |
| | | var stringTag = !isPlainObject && toStringTag && Object(obj) === obj && toStringTag in obj ? toStr(obj).slice(8, -1) : protoTag ? 'Object' : ''; |
| | | var stringTag = !isPlainObject && toStringTag && Object(obj) === obj && toStringTag in obj ? $slice.call(toStr(obj), 8, -1) : protoTag ? 'Object' : ''; |
| | | var constructorTag = isPlainObject || typeof obj.constructor !== 'function' ? '' : obj.constructor.name ? obj.constructor.name + ' ' : ''; |
| | | var tag = constructorTag + (stringTag || protoTag ? '[' + [].concat(stringTag || [], protoTag || []).join(': ') + '] ' : ''); |
| | | var tag = constructorTag + (stringTag || protoTag ? '[' + $join.call($concat.call([], stringTag || [], protoTag || []), ': ') + '] ' : ''); |
| | | if (ys.length === 0) { return tag + '{}'; } |
| | | if (indent) { |
| | | return tag + '{' + indentedJoin(ys, indent) + '}'; |
| | | } |
| | | return tag + '{ ' + ys.join(', ') + ' }'; |
| | | return tag + '{ ' + $join.call(ys, ', ') + ' }'; |
| | | } |
| | | return String(obj); |
| | | }; |
| | |
| | | } |
| | | |
| | | function quote(s) { |
| | | return String(s).replace(/"/g, '"'); |
| | | return $replace.call(String(s), /"/g, '"'); |
| | | } |
| | | |
| | | function isArray(obj) { return toStr(obj) === '[object Array]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); } |
| | |
| | | |
| | | function nameOf(f) { |
| | | if (f.name) { return f.name; } |
| | | var m = match.call(functionToString.call(f), /^function\s*([\w$]+)/); |
| | | var m = $match.call(functionToString.call(f), /^function\s*([\w$]+)/); |
| | | if (m) { return m[1]; } |
| | | return null; |
| | | } |
| | |
| | | if (str.length > opts.maxStringLength) { |
| | | var remaining = str.length - opts.maxStringLength; |
| | | var trailer = '... ' + remaining + ' more character' + (remaining > 1 ? 's' : ''); |
| | | return inspectString(str.slice(0, opts.maxStringLength), opts) + trailer; |
| | | return inspectString($slice.call(str, 0, opts.maxStringLength), opts) + trailer; |
| | | } |
| | | // eslint-disable-next-line no-control-regex |
| | | var s = str.replace(/(['\\])/g, '\\$1').replace(/[\x00-\x1f]/g, lowbyte); |
| | | var s = $replace.call($replace.call(str, /(['\\])/g, '\\$1'), /[\x00-\x1f]/g, lowbyte); |
| | | return wrapQuotes(s, 'single', opts); |
| | | } |
| | | |
| | |
| | | 13: 'r' |
| | | }[n]; |
| | | if (x) { return '\\' + x; } |
| | | return '\\x' + (n < 0x10 ? '0' : '') + n.toString(16).toUpperCase(); |
| | | return '\\x' + (n < 0x10 ? '0' : '') + $toUpperCase.call(n.toString(16)); |
| | | } |
| | | |
| | | function markBoxed(str) { |
| | |
| | | } |
| | | |
| | | function collectionOf(type, size, entries, indent) { |
| | | var joinedEntries = indent ? indentedJoin(entries, indent) : entries.join(', '); |
| | | var joinedEntries = indent ? indentedJoin(entries, indent) : $join.call(entries, ', '); |
| | | return type + ' (' + size + ') {' + joinedEntries + '}'; |
| | | } |
| | | |
| | |
| | | if (opts.indent === '\t') { |
| | | baseIndent = '\t'; |
| | | } else if (typeof opts.indent === 'number' && opts.indent > 0) { |
| | | baseIndent = Array(opts.indent + 1).join(' '); |
| | | baseIndent = $join.call(Array(opts.indent + 1), ' '); |
| | | } else { |
| | | return null; |
| | | } |
| | | return { |
| | | base: baseIndent, |
| | | prev: Array(depth + 1).join(baseIndent) |
| | | prev: $join.call(Array(depth + 1), baseIndent) |
| | | }; |
| | | } |
| | | |
| | | function indentedJoin(xs, indent) { |
| | | if (xs.length === 0) { return ''; } |
| | | var lineJoiner = '\n' + indent.prev + indent.base; |
| | | return lineJoiner + xs.join(',' + lineJoiner) + '\n' + indent.prev; |
| | | return lineJoiner + $join.call(xs, ',' + lineJoiner) + '\n' + indent.prev; |
| | | } |
| | | |
| | | function arrObjKeys(obj, inspect) { |
| | |
| | | if (hasShammedSymbols && symMap['$' + key] instanceof Symbol) { |
| | | // this is to prevent shammed Symbols, which are stored as strings, from being included in the string key section |
| | | continue; // eslint-disable-line no-restricted-syntax, no-continue |
| | | } else if ((/[^\w$]/).test(key)) { |
| | | } else if ($test.call(/[^\w$]/, key)) { |
| | | xs.push(inspect(key, obj) + ': ' + inspect(obj[key], obj)); |
| | | } else { |
| | | xs.push(key + ': ' + inspect(obj[key], obj)); |