| | |
| | | ) { |
| | | obj = []; |
| | | obj[index] = leaf; |
| | | } else { |
| | | } else if (cleanRoot !== '__proto__') { |
| | | obj[cleanRoot] = leaf; |
| | | } |
| | | } |
| | |
| | | }; |
| | | |
| | | var isArray = Array.isArray; |
| | | var split = String.prototype.split; |
| | | var push = Array.prototype.push; |
| | | var pushToArray = function (arr, valueOrArray) { |
| | | push.apply(arr, isArray(valueOrArray) ? valueOrArray : [valueOrArray]); |
| | |
| | | || typeof v === 'bigint'; |
| | | }; |
| | | |
| | | var sentinel = {}; |
| | | |
| | | var stringify = function stringify( |
| | | object, |
| | | prefix, |
| | |
| | | ) { |
| | | var obj = object; |
| | | |
| | | if (sideChannel.has(object)) { |
| | | throw new RangeError('Cyclic object value'); |
| | | var tmpSc = sideChannel; |
| | | var step = 0; |
| | | var findFlag = false; |
| | | while ((tmpSc = tmpSc.get(sentinel)) !== void undefined && !findFlag) { |
| | | // Where object last appeared in the ref tree |
| | | var pos = tmpSc.get(object); |
| | | step += 1; |
| | | if (typeof pos !== 'undefined') { |
| | | if (pos === step) { |
| | | throw new RangeError('Cyclic object value'); |
| | | } else { |
| | | findFlag = true; // Break while |
| | | } |
| | | } |
| | | if (typeof tmpSc.get(sentinel) === 'undefined') { |
| | | step = 0; |
| | | } |
| | | } |
| | | |
| | | if (typeof filter === 'function') { |
| | |
| | | if (isNonNullishPrimitive(obj) || utils.isBuffer(obj)) { |
| | | if (encoder) { |
| | | var keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults.encoder, charset, 'key', format); |
| | | if (generateArrayPrefix === 'comma' && encodeValuesOnly) { |
| | | var valuesArray = split.call(String(obj), ','); |
| | | var valuesJoined = ''; |
| | | for (var i = 0; i < valuesArray.length; ++i) { |
| | | valuesJoined += (i === 0 ? '' : ',') + formatter(encoder(valuesArray[i], defaults.encoder, charset, 'value', format)); |
| | | } |
| | | return [formatter(keyValue) + '=' + valuesJoined]; |
| | | } |
| | | return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults.encoder, charset, 'value', format))]; |
| | | } |
| | | return [formatter(prefix) + '=' + formatter(String(obj))]; |
| | |
| | | var objKeys; |
| | | if (generateArrayPrefix === 'comma' && isArray(obj)) { |
| | | // we need to join elements in |
| | | objKeys = [{ value: obj.length > 0 ? obj.join(',') || null : undefined }]; |
| | | objKeys = [{ value: obj.length > 0 ? obj.join(',') || null : void undefined }]; |
| | | } else if (isArray(filter)) { |
| | | objKeys = filter; |
| | | } else { |
| | |
| | | objKeys = sort ? keys.sort(sort) : keys; |
| | | } |
| | | |
| | | for (var i = 0; i < objKeys.length; ++i) { |
| | | var key = objKeys[i]; |
| | | var value = typeof key === 'object' && key.value !== undefined ? key.value : obj[key]; |
| | | for (var j = 0; j < objKeys.length; ++j) { |
| | | var key = objKeys[j]; |
| | | var value = typeof key === 'object' && typeof key.value !== 'undefined' ? key.value : obj[key]; |
| | | |
| | | if (skipNulls && value === null) { |
| | | continue; |
| | |
| | | ? typeof generateArrayPrefix === 'function' ? generateArrayPrefix(prefix, key) : prefix |
| | | : prefix + (allowDots ? '.' + key : '[' + key + ']'); |
| | | |
| | | sideChannel.set(object, true); |
| | | sideChannel.set(object, step); |
| | | var valueSideChannel = getSideChannel(); |
| | | valueSideChannel.set(sentinel, sideChannel); |
| | | pushToArray(values, stringify( |
| | | value, |
| | | keyPrefix, |
| | |
| | | formatter, |
| | | encodeValuesOnly, |
| | | charset, |
| | | sideChannel |
| | | valueSideChannel |
| | | )); |
| | | } |
| | | |
| | |
| | | return defaults; |
| | | } |
| | | |
| | | if (opts.encoder !== null && opts.encoder !== undefined && typeof opts.encoder !== 'function') { |
| | | if (opts.encoder !== null && typeof opts.encoder !== 'undefined' && typeof opts.encoder !== 'function') { |
| | | throw new TypeError('Encoder has to be a function.'); |
| | | } |
| | | |
| | |
| | | |
| | | i += 1; |
| | | c = 0x10000 + (((c & 0x3FF) << 10) | (string.charCodeAt(i) & 0x3FF)); |
| | | /* eslint operator-linebreak: [2, "before"] */ |
| | | out += hexTable[0xF0 | (c >> 18)] |
| | | + hexTable[0x80 | ((c >> 12) & 0x3F)] |
| | | + hexTable[0x80 | ((c >> 6) & 0x3F)] |
| | |
| | | var weakMapHas = hasWeakMap ? WeakMap.prototype.has : null; |
| | | var hasWeakSet = typeof WeakSet === 'function' && WeakSet.prototype; |
| | | var weakSetHas = hasWeakSet ? WeakSet.prototype.has : null; |
| | | var hasWeakRef = typeof WeakRef === 'function' && WeakRef.prototype; |
| | | var weakRefDeref = hasWeakRef ? WeakRef.prototype.deref : null; |
| | | 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' ? Symbol.prototype.toString : null; |
| | | 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) || ( |
| | | [].__proto__ === Array.prototype // eslint-disable-line no-proto |
| | | ? function (O) { |
| | | return O.__proto__; // eslint-disable-line no-proto |
| | | } |
| | | : 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; |
| | |
| | | throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`'); |
| | | } |
| | | var customInspect = has(opts, 'customInspect') ? opts.customInspect : true; |
| | | if (typeof customInspect !== 'boolean') { |
| | | throw new TypeError('option "customInspect", if provided, must be `true` or `false`'); |
| | | if (typeof customInspect !== 'boolean' && customInspect !== 'symbol') { |
| | | throw new TypeError('option "customInspect", if provided, must be `true`, `false`, or `\'symbol\'`'); |
| | | } |
| | | |
| | | if ( |
| | |
| | | && 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 = symToString.call(obj); |
| | | return typeof obj === 'object' ? markBoxed(symString) : symString; |
| | | 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') { |
| | | return obj[inspectSymbol](); |
| | | } else if (typeof obj.inspect === 'function') { |
| | | } else if (customInspect !== 'symbol' && typeof obj.inspect === 'function') { |
| | | return obj.inspect(); |
| | | } |
| | | } |
| | |
| | | if (isWeakSet(obj)) { |
| | | return weakCollectionOf('WeakSet'); |
| | | } |
| | | if (isWeakRef(obj)) { |
| | | return weakCollectionOf('WeakRef'); |
| | | } |
| | | if (isNumber(obj)) { |
| | | return markBoxed(inspect(Number(obj))); |
| | | } |
| | |
| | | } |
| | | if (!isDate(obj) && !isRegExp(obj)) { |
| | | var ys = arrObjKeys(obj, inspect); |
| | | if (ys.length === 0) { return '{}'; } |
| | | 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 ? $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 ? '[' + $join.call($concat.call([], stringTag || [], protoTag || []), ': ') + '] ' : ''); |
| | | if (ys.length === 0) { return tag + '{}'; } |
| | | if (indent) { |
| | | return '{' + indentedJoin(ys, indent) + '}'; |
| | | return tag + '{' + indentedJoin(ys, indent) + '}'; |
| | | } |
| | | return '{ ' + 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]'; } |
| | | function isDate(obj) { return toStr(obj) === '[object Date]'; } |
| | | function isRegExp(obj) { return toStr(obj) === '[object RegExp]'; } |
| | | function isError(obj) { return toStr(obj) === '[object Error]'; } |
| | | function isSymbol(obj) { return toStr(obj) === '[object Symbol]'; } |
| | | function isString(obj) { return toStr(obj) === '[object String]'; } |
| | | function isNumber(obj) { return toStr(obj) === '[object Number]'; } |
| | | function isBigInt(obj) { return toStr(obj) === '[object BigInt]'; } |
| | | function isBoolean(obj) { return toStr(obj) === '[object Boolean]'; } |
| | | function isArray(obj) { return toStr(obj) === '[object Array]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); } |
| | | function isDate(obj) { return toStr(obj) === '[object Date]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); } |
| | | function isRegExp(obj) { return toStr(obj) === '[object RegExp]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); } |
| | | function isError(obj) { return toStr(obj) === '[object Error]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); } |
| | | function isString(obj) { return toStr(obj) === '[object String]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); } |
| | | function isNumber(obj) { return toStr(obj) === '[object Number]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); } |
| | | function isBoolean(obj) { return toStr(obj) === '[object Boolean]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); } |
| | | |
| | | // Symbol and BigInt do have Symbol.toStringTag by spec, so that can't be used to eliminate false positives |
| | | function isSymbol(obj) { |
| | | if (hasShammedSymbols) { |
| | | return obj && typeof obj === 'object' && obj instanceof Symbol; |
| | | } |
| | | if (typeof obj === 'symbol') { |
| | | return true; |
| | | } |
| | | if (!obj || typeof obj !== 'object' || !symToString) { |
| | | return false; |
| | | } |
| | | try { |
| | | symToString.call(obj); |
| | | return true; |
| | | } catch (e) {} |
| | | return false; |
| | | } |
| | | |
| | | function isBigInt(obj) { |
| | | if (!obj || typeof obj !== 'object' || !bigIntValueOf) { |
| | | return false; |
| | | } |
| | | try { |
| | | bigIntValueOf.call(obj); |
| | | return true; |
| | | } catch (e) {} |
| | | return false; |
| | | } |
| | | |
| | | var hasOwn = Object.prototype.hasOwnProperty || function (key) { return key in this; }; |
| | | function has(obj, key) { |
| | |
| | | |
| | | 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; |
| | | } |
| | |
| | | return true; |
| | | } |
| | | return x instanceof WeakMap; // core-js workaround, pre-v2.5.0 |
| | | } catch (e) {} |
| | | return false; |
| | | } |
| | | |
| | | function isWeakRef(x) { |
| | | if (!weakRefDeref || !x || typeof x !== 'object') { |
| | | return false; |
| | | } |
| | | try { |
| | | weakRefDeref.call(x); |
| | | return true; |
| | | } catch (e) {} |
| | | return false; |
| | | } |
| | |
| | | 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) { |
| | |
| | | xs[i] = has(obj, i) ? inspect(obj[i], obj) : ''; |
| | | } |
| | | } |
| | | var syms = typeof gOPS === 'function' ? gOPS(obj) : []; |
| | | var symMap; |
| | | if (hasShammedSymbols) { |
| | | symMap = {}; |
| | | for (var k = 0; k < syms.length; k++) { |
| | | symMap['$' + syms[k]] = syms[k]; |
| | | } |
| | | } |
| | | |
| | | for (var key in obj) { // eslint-disable-line no-restricted-syntax |
| | | if (!has(obj, key)) { continue; } // eslint-disable-line no-restricted-syntax, no-continue |
| | | if (isArr && String(Number(key)) === key && key < obj.length) { continue; } // eslint-disable-line no-restricted-syntax, no-continue |
| | | if ((/[^\w$]/).test(key)) { |
| | | 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 ($test.call(/[^\w$]/, key)) { |
| | | xs.push(inspect(key, obj) + ': ' + inspect(obj[key], obj)); |
| | | } else { |
| | | xs.push(key + ': ' + inspect(obj[key], obj)); |
| | | } |
| | | } |
| | | if (typeof gOPS === 'function') { |
| | | var syms = gOPS(obj); |
| | | for (var j = 0; j < syms.length; j++) { |
| | | if (isEnumerable.call(obj, syms[j])) { |
| | | xs.push('[' + inspect(syms[j]) + ']: ' + inspect(obj[syms[j]], obj)); |