Comparing version 2.3.7 to 3.0.0
@@ -1,7 +0,10 @@ | ||
import { inspectList } from './helpers' | ||
export default function inspectArguments(args, options) { | ||
if (args.length === 0) return 'Arguments[]' | ||
options.truncate -= 13 | ||
return `Arguments[ ${inspectList(args, options)} ]` | ||
import { inspectList } from "./helpers.js"; | ||
function inspectArguments(args, options) { | ||
if (args.length === 0) | ||
return "Arguments[]"; | ||
options.truncate -= 13; | ||
return `Arguments[ ${inspectList(args, options)} ]`; | ||
} | ||
export { | ||
inspectArguments as default | ||
}; |
@@ -1,20 +0,21 @@ | ||
import { inspectProperty, inspectList } from './helpers' | ||
export default function inspectArray(array, options) { | ||
// Object.keys will always output the Array indices first, so we can slice by | ||
// `array.length` to get non-index properties | ||
const nonIndexProperties = Object.keys(array).slice(array.length) | ||
if (!array.length && !nonIndexProperties.length) return '[]' | ||
options.truncate -= 4 | ||
const listContents = inspectList(array, options) | ||
options.truncate -= listContents.length | ||
let propertyContents = '' | ||
import { inspectList, inspectProperty } from "./helpers.js"; | ||
function inspectArray(array, options) { | ||
const nonIndexProperties = Object.keys(array).slice(array.length); | ||
if (!array.length && !nonIndexProperties.length) | ||
return "[]"; | ||
options.truncate -= 4; | ||
const listContents = inspectList(array, options); | ||
options.truncate -= listContents.length; | ||
let propertyContents = ""; | ||
if (nonIndexProperties.length) { | ||
propertyContents = inspectList( | ||
nonIndexProperties.map(key => [key, array[key]]), | ||
nonIndexProperties.map((key) => [key, array[key]]), | ||
options, | ||
inspectProperty | ||
) | ||
); | ||
} | ||
return `[ ${listContents}${propertyContents ? `, ${propertyContents}` : ''} ]` | ||
return `[ ${listContents}${propertyContents ? `, ${propertyContents}` : ""} ]`; | ||
} | ||
export { | ||
inspectArray as default | ||
}; |
@@ -1,7 +0,10 @@ | ||
import { truncate, truncator } from './helpers' | ||
export default function inspectBigInt(number, options) { | ||
let nums = truncate(number.toString(), options.truncate - 1) | ||
if (nums !== truncator) nums += 'n' | ||
return options.stylize(nums, 'bigint') | ||
import { truncate, truncator } from "./helpers.js"; | ||
function inspectBigInt(number, options) { | ||
let nums = truncate(number.toString(), options.truncate - 1); | ||
if (nums !== truncator) | ||
nums += "n"; | ||
return options.stylize(nums, "bigint"); | ||
} | ||
export { | ||
inspectBigInt as default | ||
}; |
@@ -1,18 +0,17 @@ | ||
import getFuncName from 'get-func-name' | ||
import inspectObject from './object' | ||
const toStringTag = typeof Symbol !== 'undefined' && Symbol.toStringTag ? Symbol.toStringTag : false | ||
export default function inspectClass(value, options) { | ||
let name = '' | ||
import inspectObject from "./object.js"; | ||
const toStringTag = typeof Symbol !== "undefined" && Symbol.toStringTag ? Symbol.toStringTag : false; | ||
function inspectClass(value, options) { | ||
let name = ""; | ||
if (toStringTag && toStringTag in value) { | ||
name = value[toStringTag] | ||
name = value[toStringTag]; | ||
} | ||
name = name || getFuncName(value.constructor) | ||
// Babel transforms anonymous classes to the name `_class` | ||
if (!name || name === '_class') { | ||
name = '<Anonymous Class>' | ||
name = name || value.constructor.name; | ||
if (!name || name === "_class") { | ||
name = "<Anonymous Class>"; | ||
} | ||
options.truncate -= name.length | ||
return `${name}${inspectObject(value, options)}` | ||
options.truncate -= name.length; | ||
return `${name}${inspectObject(value, options)}`; | ||
} | ||
export { | ||
inspectClass as default | ||
}; |
@@ -1,14 +0,13 @@ | ||
import { truncate } from './helpers' | ||
export default function inspectDate(dateObject, options) { | ||
const stringRepresentation = dateObject.toJSON() | ||
import { truncate } from "./helpers.js"; | ||
function inspectDate(dateObject, options) { | ||
const stringRepresentation = dateObject.toJSON(); | ||
if (stringRepresentation === null) { | ||
return 'Invalid Date' | ||
return "Invalid Date"; | ||
} | ||
const split = stringRepresentation.split('T') | ||
const date = split[0] | ||
// If we need to - truncate the time portion, but never the date | ||
return options.stylize(`${date}T${truncate(split[1], options.truncate - date.length - 1)}`, 'date') | ||
const split = stringRepresentation.split("T"); | ||
const date = split[0]; | ||
return options.stylize(`${date}T${truncate(split[1], options.truncate - date.length - 1)}`, "date"); | ||
} | ||
export { | ||
inspectDate as default | ||
}; |
@@ -1,34 +0,35 @@ | ||
import { truncate, inspectList, inspectProperty } from './helpers' | ||
import { inspectList, inspectProperty, truncate } from "./helpers.js"; | ||
const errorKeys = [ | ||
'stack', | ||
'line', | ||
'column', | ||
'name', | ||
'message', | ||
'fileName', | ||
'lineNumber', | ||
'columnNumber', | ||
'number', | ||
'description', | ||
] | ||
export default function inspectObject(error, options) { | ||
const properties = Object.getOwnPropertyNames(error).filter(key => errorKeys.indexOf(key) === -1) | ||
const name = error.name | ||
options.truncate -= name.length | ||
let message = '' | ||
if (typeof error.message === 'string') { | ||
message = truncate(error.message, options.truncate) | ||
"stack", | ||
"line", | ||
"column", | ||
"name", | ||
"message", | ||
"fileName", | ||
"lineNumber", | ||
"columnNumber", | ||
"number", | ||
"description" | ||
]; | ||
function inspectObject(error, options) { | ||
const properties = Object.getOwnPropertyNames(error).filter((key) => errorKeys.indexOf(key) === -1); | ||
const name = error.name; | ||
options.truncate -= name.length; | ||
let message = ""; | ||
if (typeof error.message === "string") { | ||
message = truncate(error.message, options.truncate); | ||
} else { | ||
properties.unshift('message') | ||
properties.unshift("message"); | ||
} | ||
message = message ? `: ${message}` : '' | ||
options.truncate -= message.length + 5 | ||
message = message ? `: ${message}` : ""; | ||
options.truncate -= message.length + 5; | ||
const propertyContents = inspectList( | ||
properties.map(key => [key, error[key]]), | ||
properties.map((key) => [key, error[key]]), | ||
options, | ||
inspectProperty | ||
) | ||
return `${name}${message}${propertyContents ? ` { ${propertyContents} }` : ''}` | ||
); | ||
return `${name}${message}${propertyContents ? ` { ${propertyContents} }` : ""}`; | ||
} | ||
export { | ||
inspectObject as default | ||
}; |
@@ -1,10 +0,11 @@ | ||
import getFunctionName from 'get-func-name' | ||
import { truncate } from './helpers' | ||
export default function inspectFunction(func, options) { | ||
const name = getFunctionName(func) | ||
import { truncate } from "./helpers.js"; | ||
function inspectFunction(func, options) { | ||
const name = func.name; | ||
if (!name) { | ||
return options.stylize('[Function]', 'special') | ||
return options.stylize("[Function]", "special"); | ||
} | ||
return options.stylize(`[Function ${truncate(name, options.truncate - 11)}]`, 'special') | ||
return options.stylize(`[Function ${truncate(name, options.truncate - 11)}]`, "special"); | ||
} | ||
export { | ||
inspectFunction as default | ||
}; |
const ansiColors = { | ||
bold: ['1', '22'], | ||
dim: ['2', '22'], | ||
italic: ['3', '23'], | ||
underline: ['4', '24'], | ||
bold: ["1", "22"], | ||
dim: ["2", "22"], | ||
italic: ["3", "23"], | ||
underline: ["4", "24"], | ||
// 5 & 6 are blinking | ||
inverse: ['7', '27'], | ||
hidden: ['8', '28'], | ||
strike: ['9', '29'], | ||
inverse: ["7", "27"], | ||
hidden: ["8", "28"], | ||
strike: ["9", "29"], | ||
// 10-20 are fonts | ||
// 21-29 are resets for 1-9 | ||
black: ['30', '39'], | ||
red: ['31', '39'], | ||
green: ['32', '39'], | ||
yellow: ['33', '39'], | ||
blue: ['34', '39'], | ||
magenta: ['35', '39'], | ||
cyan: ['36', '39'], | ||
white: ['37', '39'], | ||
brightblack: ['30;1', '39'], | ||
brightred: ['31;1', '39'], | ||
brightgreen: ['32;1', '39'], | ||
brightyellow: ['33;1', '39'], | ||
brightblue: ['34;1', '39'], | ||
brightmagenta: ['35;1', '39'], | ||
brightcyan: ['36;1', '39'], | ||
brightwhite: ['37;1', '39'], | ||
grey: ['90', '39'], | ||
} | ||
black: ["30", "39"], | ||
red: ["31", "39"], | ||
green: ["32", "39"], | ||
yellow: ["33", "39"], | ||
blue: ["34", "39"], | ||
magenta: ["35", "39"], | ||
cyan: ["36", "39"], | ||
white: ["37", "39"], | ||
brightblack: ["30;1", "39"], | ||
brightred: ["31;1", "39"], | ||
brightgreen: ["32;1", "39"], | ||
brightyellow: ["33;1", "39"], | ||
brightblue: ["34;1", "39"], | ||
brightmagenta: ["35;1", "39"], | ||
brightcyan: ["36;1", "39"], | ||
brightwhite: ["37;1", "39"], | ||
grey: ["90", "39"] | ||
}; | ||
const styles = { | ||
special: 'cyan', | ||
number: 'yellow', | ||
bigint: 'yellow', | ||
boolean: 'yellow', | ||
undefined: 'grey', | ||
null: 'bold', | ||
string: 'green', | ||
symbol: 'green', | ||
date: 'magenta', | ||
regexp: 'red', | ||
} | ||
export const truncator = '…' | ||
special: "cyan", | ||
number: "yellow", | ||
bigint: "yellow", | ||
boolean: "yellow", | ||
undefined: "grey", | ||
null: "bold", | ||
string: "green", | ||
symbol: "green", | ||
date: "magenta", | ||
regexp: "red" | ||
}; | ||
const truncator = "\u2026"; | ||
function colorise(value, styleType) { | ||
const color = ansiColors[styles[styleType]] || ansiColors[styleType] | ||
const color = ansiColors[styles[styleType]] || ansiColors[styleType] || ""; | ||
if (!color) { | ||
return String(value) | ||
return String(value); | ||
} | ||
return `\u001b[${color[0]}m${String(value)}\u001b[${color[1]}m` | ||
return `\x1B[${color[0]}m${String(value)}\x1B[${color[1]}m`; | ||
} | ||
export function normaliseOptions({ | ||
function normaliseOptions({ | ||
showHidden = false, | ||
@@ -66,5 +60,5 @@ depth = 2, | ||
// eslint-disable-next-line no-shadow | ||
truncate = Infinity, | ||
stylize = String, | ||
} = {}) { | ||
truncate: truncate2 = Infinity, | ||
stylize = String | ||
} = {}, inspect) { | ||
const options = { | ||
@@ -78,102 +72,84 @@ showHidden: Boolean(showHidden), | ||
breakLength: Number(breakLength), | ||
truncate: Number(truncate), | ||
truncate: Number(truncate2), | ||
seen, | ||
stylize, | ||
} | ||
inspect, | ||
stylize | ||
}; | ||
if (options.colors) { | ||
options.stylize = colorise | ||
options.stylize = colorise; | ||
} | ||
return options | ||
return options; | ||
} | ||
export function truncate(string, length, tail = truncator) { | ||
string = String(string) | ||
const tailLength = tail.length | ||
const stringLength = string.length | ||
function truncate(string, length, tail = truncator) { | ||
string = String(string); | ||
const tailLength = tail.length; | ||
const stringLength = string.length; | ||
if (tailLength > length && stringLength > tailLength) { | ||
return tail | ||
return tail; | ||
} | ||
if (stringLength > length && stringLength > tailLength) { | ||
return `${string.slice(0, length - tailLength)}${tail}` | ||
return `${string.slice(0, length - tailLength)}${tail}`; | ||
} | ||
return string | ||
return string; | ||
} | ||
// eslint-disable-next-line complexity | ||
export function inspectList(list, options, inspectItem, separator = ', ') { | ||
inspectItem = inspectItem || options.inspect | ||
const size = list.length | ||
if (size === 0) return '' | ||
const originalLength = options.truncate | ||
let output = '' | ||
let peek = '' | ||
let truncated = '' | ||
function inspectList(list, options, inspectItem, separator = ", ") { | ||
inspectItem = inspectItem || options.inspect; | ||
const size = list.length; | ||
if (size === 0) | ||
return ""; | ||
const originalLength = options.truncate; | ||
let output = ""; | ||
let peek = ""; | ||
let truncated = ""; | ||
for (let i = 0; i < size; i += 1) { | ||
const last = i + 1 === list.length | ||
const secondToLast = i + 2 === list.length | ||
truncated = `${truncator}(${list.length - i})` | ||
const value = list[i] | ||
// If there is more than one remaining we need to account for a separator of `, ` | ||
options.truncate = originalLength - output.length - (last ? 0 : separator.length) | ||
const string = peek || inspectItem(value, options) + (last ? '' : separator) | ||
const nextLength = output.length + string.length | ||
const truncatedLength = nextLength + truncated.length | ||
// If this is the last element, and adding it would | ||
// take us over length, but adding the truncator wouldn't - then break now | ||
const last = i + 1 === list.length; | ||
const secondToLast = i + 2 === list.length; | ||
truncated = `${truncator}(${list.length - i})`; | ||
const value = list[i]; | ||
options.truncate = originalLength - output.length - (last ? 0 : separator.length); | ||
const string = peek || inspectItem(value, options) + (last ? "" : separator); | ||
const nextLength = output.length + string.length; | ||
const truncatedLength = nextLength + truncated.length; | ||
if (last && nextLength > originalLength && output.length + truncated.length <= originalLength) { | ||
break | ||
break; | ||
} | ||
// If this isn't the last or second to last element to scan, | ||
// but the string is already over length then break here | ||
if (!last && !secondToLast && truncatedLength > originalLength) { | ||
break | ||
break; | ||
} | ||
// Peek at the next string to determine if we should | ||
// break early before adding this item to the output | ||
peek = last ? '' : inspectItem(list[i + 1], options) + (secondToLast ? '' : separator) | ||
// If we have one element left, but this element and | ||
// the next takes over length, the break early | ||
peek = last ? "" : inspectItem(list[i + 1], options) + (secondToLast ? "" : separator); | ||
if (!last && secondToLast && truncatedLength > originalLength && nextLength + peek.length > originalLength) { | ||
break | ||
break; | ||
} | ||
output += string | ||
// If the next element takes us to length - | ||
// but there are more after that, then we should truncate now | ||
output += string; | ||
if (!last && !secondToLast && nextLength + peek.length >= originalLength) { | ||
truncated = `${truncator}(${list.length - i - 1})` | ||
break | ||
truncated = `${truncator}(${list.length - i - 1})`; | ||
break; | ||
} | ||
truncated = '' | ||
truncated = ""; | ||
} | ||
return `${output}${truncated}` | ||
return `${output}${truncated}`; | ||
} | ||
function quoteComplexKey(key) { | ||
if (key.match(/^[a-zA-Z_][a-zA-Z_0-9]*$/)) { | ||
return key | ||
return key; | ||
} | ||
return JSON.stringify(key) | ||
.replace(/'/g, "\\'") | ||
.replace(/\\"/g, '"') | ||
.replace(/(^"|"$)/g, "'") | ||
return JSON.stringify(key).replace(/'/g, "\\'").replace(/\\"/g, '"').replace(/(^"|"$)/g, "'"); | ||
} | ||
export function inspectProperty([key, value], options) { | ||
options.truncate -= 2 | ||
if (typeof key === 'string') { | ||
key = quoteComplexKey(key) | ||
} else if (typeof key !== 'number') { | ||
key = `[${options.inspect(key, options)}]` | ||
function inspectProperty([key, value], options) { | ||
options.truncate -= 2; | ||
if (typeof key === "string") { | ||
key = quoteComplexKey(key); | ||
} else if (typeof key !== "number") { | ||
key = `[${options.inspect(key, options)}]`; | ||
} | ||
options.truncate -= key.length | ||
value = options.inspect(value, options) | ||
return `${key}: ${value}` | ||
options.truncate -= key.length; | ||
value = options.inspect(value, options); | ||
return `${key}: ${value}`; | ||
} | ||
export { | ||
inspectList, | ||
inspectProperty, | ||
normaliseOptions, | ||
truncate, | ||
truncator | ||
}; |
@@ -1,40 +0,41 @@ | ||
import { truncator, inspectList } from './helpers' | ||
export function inspectAttribute([key, value], options) { | ||
options.truncate -= 3 | ||
import { inspectList, truncator } from "./helpers.js"; | ||
function inspectAttribute([key, value], options) { | ||
options.truncate -= 3; | ||
if (!value) { | ||
return `${options.stylize(key, 'yellow')}` | ||
return `${options.stylize(String(key), "yellow")}`; | ||
} | ||
return `${options.stylize(key, 'yellow')}=${options.stylize(`"${value}"`, 'string')}` | ||
return `${options.stylize(String(key), "yellow")}=${options.stylize(`"${value}"`, "string")}`; | ||
} | ||
export function inspectHTMLCollection(collection, options) { | ||
// eslint-disable-next-line no-use-before-define | ||
return inspectList(collection, options, inspectHTML, '\n') | ||
function inspectHTMLCollection(collection, options) { | ||
return inspectList(collection, options, inspectHTML, "\n"); | ||
} | ||
export default function inspectHTML(element, options) { | ||
const properties = element.getAttributeNames() | ||
const name = element.tagName.toLowerCase() | ||
const head = options.stylize(`<${name}`, 'special') | ||
const headClose = options.stylize(`>`, 'special') | ||
const tail = options.stylize(`</${name}>`, 'special') | ||
options.truncate -= name.length * 2 + 5 | ||
let propertyContents = '' | ||
function inspectHTML(element, options) { | ||
const properties = element.getAttributeNames(); | ||
const name = element.tagName.toLowerCase(); | ||
const head = options.stylize(`<${name}`, "special"); | ||
const headClose = options.stylize(`>`, "special"); | ||
const tail = options.stylize(`</${name}>`, "special"); | ||
options.truncate -= name.length * 2 + 5; | ||
let propertyContents = ""; | ||
if (properties.length > 0) { | ||
propertyContents += ' ' | ||
propertyContents += " "; | ||
propertyContents += inspectList( | ||
properties.map(key => [key, element.getAttribute(key)]), | ||
properties.map((key) => [key, element.getAttribute(key)]), | ||
options, | ||
inspectAttribute, | ||
' ' | ||
) | ||
" " | ||
); | ||
} | ||
options.truncate -= propertyContents.length | ||
const truncate = options.truncate | ||
let children = inspectHTMLCollection(element.children, options) | ||
options.truncate -= propertyContents.length; | ||
const truncate = options.truncate; | ||
let children = inspectHTMLCollection(element.children, options); | ||
if (children && children.length > truncate) { | ||
children = `${truncator}(${element.children.length})` | ||
children = `${truncator}(${element.children.length})`; | ||
} | ||
return `${head}${propertyContents}${headClose}${children}${tail}` | ||
return `${head}${propertyContents}${headClose}${children}${tail}`; | ||
} | ||
export { | ||
inspectHTML as default, | ||
inspectAttribute, | ||
inspectHTMLCollection | ||
}; |
@@ -1,27 +0,26 @@ | ||
import { inspectList } from './helpers' | ||
import { inspectList } from "./helpers.js"; | ||
function inspectMapEntry([key, value], options) { | ||
options.truncate -= 4 | ||
key = options.inspect(key, options) | ||
options.truncate -= key.length | ||
value = options.inspect(value, options) | ||
return `${key} => ${value}` | ||
options.truncate -= 4; | ||
key = options.inspect(key, options); | ||
options.truncate -= key.length; | ||
value = options.inspect(value, options); | ||
return `${key} => ${value}`; | ||
} | ||
// IE11 doesn't support `map.entries()` | ||
function mapToEntries(map) { | ||
const entries = [] | ||
const entries = []; | ||
map.forEach((value, key) => { | ||
entries.push([key, value]) | ||
}) | ||
return entries | ||
entries.push([key, value]); | ||
}); | ||
return entries; | ||
} | ||
export default function inspectMap(map, options) { | ||
const size = map.size - 1 | ||
function inspectMap(map, options) { | ||
const size = map.size - 1; | ||
if (size <= 0) { | ||
return 'Map{}' | ||
return "Map{}"; | ||
} | ||
options.truncate -= 7 | ||
return `Map{ ${inspectList(mapToEntries(map), options, inspectMapEntry)} }` | ||
options.truncate -= 7; | ||
return `Map{ ${inspectList(mapToEntries(map), options, inspectMapEntry)} }`; | ||
} | ||
export { | ||
inspectMap as default | ||
}; |
@@ -1,18 +0,20 @@ | ||
import { truncate } from './helpers' | ||
const isNaN = Number.isNaN || (i => i !== i) // eslint-disable-line no-self-compare | ||
export default function inspectNumber(number, options) { | ||
import { truncate } from "./helpers.js"; | ||
const isNaN = Number.isNaN || ((i) => i !== i); | ||
function inspectNumber(number, options) { | ||
if (isNaN(number)) { | ||
return options.stylize('NaN', 'number') | ||
return options.stylize("NaN", "number"); | ||
} | ||
if (number === Infinity) { | ||
return options.stylize('Infinity', 'number') | ||
return options.stylize("Infinity", "number"); | ||
} | ||
if (number === -Infinity) { | ||
return options.stylize('-Infinity', 'number') | ||
return options.stylize("-Infinity", "number"); | ||
} | ||
if (number === 0) { | ||
return options.stylize(1 / number === Infinity ? '+0' : '-0', 'number') | ||
return options.stylize(1 / number === Infinity ? "+0" : "-0", "number"); | ||
} | ||
return options.stylize(truncate(number, options.truncate), 'number') | ||
return options.stylize(truncate(String(number), options.truncate), "number"); | ||
} | ||
export { | ||
inspectNumber as default | ||
}; |
@@ -1,31 +0,33 @@ | ||
import { inspectProperty, inspectList } from './helpers' | ||
export default function inspectObject(object, options) { | ||
const properties = Object.getOwnPropertyNames(object) | ||
const symbols = Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(object) : [] | ||
import { inspectList, inspectProperty } from "./helpers.js"; | ||
function inspectObject(object, options) { | ||
const properties = Object.getOwnPropertyNames(object); | ||
const symbols = Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(object) : []; | ||
if (properties.length === 0 && symbols.length === 0) { | ||
return '{}' | ||
return "{}"; | ||
} | ||
options.truncate -= 4 | ||
options.seen = options.seen || [] | ||
options.truncate -= 4; | ||
options.seen = options.seen || []; | ||
if (options.seen.indexOf(object) >= 0) { | ||
return '[Circular]' | ||
return "[Circular]"; | ||
} | ||
options.seen.push(object) | ||
options.seen.push(object); | ||
const propertyContents = inspectList( | ||
properties.map(key => [key, object[key]]), | ||
properties.map((key) => [key, object[key]]), | ||
options, | ||
inspectProperty | ||
) | ||
); | ||
const symbolContents = inspectList( | ||
symbols.map(key => [key, object[key]]), | ||
symbols.map((key) => [key, object[key]]), | ||
options, | ||
inspectProperty | ||
) | ||
options.seen.pop() | ||
let sep = '' | ||
); | ||
options.seen.pop(); | ||
let sep = ""; | ||
if (propertyContents && symbolContents) { | ||
sep = ', ' | ||
sep = ", "; | ||
} | ||
return `{ ${propertyContents}${sep}${symbolContents} }` | ||
return `{ ${propertyContents}${sep}${symbolContents} }`; | ||
} | ||
export { | ||
inspectObject as default | ||
}; |
@@ -1,16 +0,18 @@ | ||
let getPromiseValue = () => 'Promise{…}' | ||
let getPromiseValue = () => "Promise{\u2026}"; | ||
try { | ||
const { getPromiseDetails, kPending, kRejected } = process.binding('util') | ||
const { getPromiseDetails, kPending, kRejected } = process.binding("util"); | ||
if (Array.isArray(getPromiseDetails(Promise.resolve()))) { | ||
getPromiseValue = (value, options) => { | ||
const [state, innerValue] = getPromiseDetails(value) | ||
const [state, innerValue] = getPromiseDetails(value); | ||
if (state === kPending) { | ||
return 'Promise{<pending>}' | ||
return "Promise{<pending>}"; | ||
} | ||
return `Promise${state === kRejected ? '!' : ''}{${options.inspect(innerValue, options)}}` | ||
} | ||
return `Promise${state === kRejected ? "!" : ""}{${options.inspect(innerValue, options)}}`; | ||
}; | ||
} | ||
} catch (notNode) { | ||
/* ignore */ | ||
} | ||
export default getPromiseValue | ||
var promise_default = getPromiseValue; | ||
export { | ||
promise_default as default | ||
}; |
@@ -1,8 +0,10 @@ | ||
import { truncate } from './helpers' | ||
export default function inspectRegExp(value, options) { | ||
const flags = value.toString().split('/')[2] | ||
const sourceLength = options.truncate - (2 + flags.length) | ||
const source = value.source | ||
return options.stylize(`/${truncate(source, sourceLength)}/${flags}`, 'regexp') | ||
import { truncate } from "./helpers.js"; | ||
function inspectRegExp(value, options) { | ||
const flags = value.toString().split("/")[2]; | ||
const sourceLength = options.truncate - (2 + flags.length); | ||
const source = value.source; | ||
return options.stylize(`/${truncate(source, sourceLength)}/${flags}`, "regexp"); | ||
} | ||
export { | ||
inspectRegExp as default | ||
}; |
@@ -1,16 +0,17 @@ | ||
import { inspectList } from './helpers' | ||
// IE11 doesn't support `Array.from(set)` | ||
import { inspectList } from "./helpers.js"; | ||
function arrayFromSet(set) { | ||
const values = [] | ||
set.forEach(value => { | ||
values.push(value) | ||
}) | ||
return values | ||
const values = []; | ||
set.forEach((value) => { | ||
values.push(value); | ||
}); | ||
return values; | ||
} | ||
export default function inspectSet(set, options) { | ||
if (set.size === 0) return 'Set{}' | ||
options.truncate -= 7 | ||
return `Set{ ${inspectList(arrayFromSet(set), options)} }` | ||
function inspectSet(set, options) { | ||
if (set.size === 0) | ||
return "Set{}"; | ||
options.truncate -= 7; | ||
return `Set{ ${inspectList(arrayFromSet(set), options)} }`; | ||
} | ||
export { | ||
inspectSet as default | ||
}; |
@@ -1,29 +0,28 @@ | ||
import { truncate } from './helpers' | ||
import { truncate } from "./helpers.js"; | ||
const stringEscapeChars = new RegExp( | ||
"['\\u0000-\\u001f\\u007f-\\u009f\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5" + | ||
'\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]', | ||
'g' | ||
) | ||
"['\\u0000-\\u001f\\u007f-\\u009f\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]", | ||
"g" | ||
); | ||
const escapeCharacters = { | ||
'\b': '\\b', | ||
'\t': '\\t', | ||
'\n': '\\n', | ||
'\f': '\\f', | ||
'\r': '\\r', | ||
"\b": "\\b", | ||
" ": "\\t", | ||
"\n": "\\n", | ||
"\f": "\\f", | ||
"\r": "\\r", | ||
"'": "\\'", | ||
'\\': '\\\\', | ||
} | ||
const hex = 16 | ||
const unicodeLength = 4 | ||
"\\": "\\\\" | ||
}; | ||
const hex = 16; | ||
const unicodeLength = 4; | ||
function escape(char) { | ||
return escapeCharacters[char] || `\\u${`0000${char.charCodeAt(0).toString(hex)}`.slice(-unicodeLength)}` | ||
return escapeCharacters[char] || `\\u${`0000${char.charCodeAt(0).toString(hex)}`.slice(-unicodeLength)}`; | ||
} | ||
export default function inspectString(string, options) { | ||
function inspectString(string, options) { | ||
if (stringEscapeChars.test(string)) { | ||
string = string.replace(stringEscapeChars, escape) | ||
string = string.replace(stringEscapeChars, escape); | ||
} | ||
return options.stylize(`'${truncate(string, options.truncate - 2)}'`, 'string') | ||
return options.stylize(`'${truncate(string, options.truncate - 2)}'`, "string"); | ||
} | ||
export { | ||
inspectString as default | ||
}; |
@@ -1,6 +0,9 @@ | ||
export default function inspectSymbol(value) { | ||
if ('description' in Symbol.prototype) { | ||
return value.description ? `Symbol(${value.description})` : 'Symbol()' | ||
function inspectSymbol(value) { | ||
if ("description" in Symbol.prototype) { | ||
return value.description ? `Symbol(${value.description})` : "Symbol()"; | ||
} | ||
return value.toString() | ||
return value.toString(); | ||
} | ||
export { | ||
inspectSymbol as default | ||
}; |
@@ -1,45 +0,39 @@ | ||
import getFuncName from 'get-func-name' | ||
import { truncator, truncate, inspectProperty, inspectList } from './helpers' | ||
const getArrayName = array => { | ||
// We need to special case Node.js' Buffers, which report to be Uint8Array | ||
if (typeof Buffer === 'function' && array instanceof Buffer) { | ||
return 'Buffer' | ||
import { inspectList, inspectProperty, truncate, truncator } from "./helpers.js"; | ||
const getArrayName = (array) => { | ||
if (typeof Buffer === "function" && array instanceof Buffer) { | ||
return "Buffer"; | ||
} | ||
if (array[Symbol.toStringTag]) { | ||
return array[Symbol.toStringTag] | ||
return array[Symbol.toStringTag]; | ||
} | ||
return getFuncName(array.constructor) | ||
} | ||
export default function inspectTypedArray(array, options) { | ||
const name = getArrayName(array) | ||
options.truncate -= name.length + 4 | ||
// Object.keys will always output the Array indices first, so we can slice by | ||
// `array.length` to get non-index properties | ||
const nonIndexProperties = Object.keys(array).slice(array.length) | ||
if (!array.length && !nonIndexProperties.length) return `${name}[]` | ||
// As we know TypedArrays only contain Unsigned Integers, we can skip inspecting each one and simply | ||
// stylise the toString() value of them | ||
let output = '' | ||
return array.constructor.name; | ||
}; | ||
function inspectTypedArray(array, options) { | ||
const name = getArrayName(array); | ||
options.truncate -= name.length + 4; | ||
const nonIndexProperties = Object.keys(array).slice(array.length); | ||
if (!array.length && !nonIndexProperties.length) | ||
return `${name}[]`; | ||
let output = ""; | ||
for (let i = 0; i < array.length; i++) { | ||
const string = `${options.stylize(truncate(array[i], options.truncate), 'number')}${ | ||
i === array.length - 1 ? '' : ', ' | ||
}` | ||
options.truncate -= string.length | ||
const string = `${options.stylize(truncate(array[i], options.truncate), "number")}${i === array.length - 1 ? "" : ", "}`; | ||
options.truncate -= string.length; | ||
if (array[i] !== array.length && options.truncate <= 3) { | ||
output += `${truncator}(${array.length - array[i] + 1})` | ||
break | ||
output += `${truncator}(${array.length - array[i] + 1})`; | ||
break; | ||
} | ||
output += string | ||
output += string; | ||
} | ||
let propertyContents = '' | ||
let propertyContents = ""; | ||
if (nonIndexProperties.length) { | ||
propertyContents = inspectList( | ||
nonIndexProperties.map(key => [key, array[key]]), | ||
nonIndexProperties.map((key) => [key, array[key]]), | ||
options, | ||
inspectProperty | ||
) | ||
); | ||
} | ||
return `${name}[ ${output}${propertyContents ? `, ${propertyContents}` : ''} ]` | ||
return `${name}[ ${output}${propertyContents ? `, ${propertyContents}` : ""} ]`; | ||
} | ||
export { | ||
inspectTypedArray as default | ||
}; |
1397
loupe.js
@@ -1,891 +0,636 @@ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.loupe = {})); | ||
}(this, (function (exports) { 'use strict'; | ||
function _typeof(obj) { | ||
"@babel/helpers - typeof"; | ||
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
_typeof = function (obj) { | ||
return typeof obj; | ||
}; | ||
} else { | ||
_typeof = function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
} | ||
return _typeof(obj); | ||
"use strict"; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __commonJS = (cb, mod) => function __require() { | ||
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; | ||
}; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
function _slicedToArray(arr, i) { | ||
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); | ||
// (disabled):util | ||
var require_util = __commonJS({ | ||
"(disabled):util"() { | ||
} | ||
}); | ||
function _arrayWithHoles(arr) { | ||
if (Array.isArray(arr)) return arr; | ||
} | ||
// src/index.ts | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
custom: () => custom, | ||
default: () => src_default, | ||
inspect: () => inspect, | ||
registerConstructor: () => registerConstructor, | ||
registerStringTag: () => registerStringTag | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
function _iterableToArrayLimit(arr, i) { | ||
if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _e = undefined; | ||
try { | ||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"] != null) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
return _arr; | ||
// src/helpers.ts | ||
var ansiColors = { | ||
bold: ["1", "22"], | ||
dim: ["2", "22"], | ||
italic: ["3", "23"], | ||
underline: ["4", "24"], | ||
// 5 & 6 are blinking | ||
inverse: ["7", "27"], | ||
hidden: ["8", "28"], | ||
strike: ["9", "29"], | ||
// 10-20 are fonts | ||
// 21-29 are resets for 1-9 | ||
black: ["30", "39"], | ||
red: ["31", "39"], | ||
green: ["32", "39"], | ||
yellow: ["33", "39"], | ||
blue: ["34", "39"], | ||
magenta: ["35", "39"], | ||
cyan: ["36", "39"], | ||
white: ["37", "39"], | ||
brightblack: ["30;1", "39"], | ||
brightred: ["31;1", "39"], | ||
brightgreen: ["32;1", "39"], | ||
brightyellow: ["33;1", "39"], | ||
brightblue: ["34;1", "39"], | ||
brightmagenta: ["35;1", "39"], | ||
brightcyan: ["36;1", "39"], | ||
brightwhite: ["37;1", "39"], | ||
grey: ["90", "39"] | ||
}; | ||
var styles = { | ||
special: "cyan", | ||
number: "yellow", | ||
bigint: "yellow", | ||
boolean: "yellow", | ||
undefined: "grey", | ||
null: "bold", | ||
string: "green", | ||
symbol: "green", | ||
date: "magenta", | ||
regexp: "red" | ||
}; | ||
var truncator = "\u2026"; | ||
function colorise(value, styleType) { | ||
const color = ansiColors[styles[styleType]] || ansiColors[styleType] || ""; | ||
if (!color) { | ||
return String(value); | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
if (!o) return; | ||
if (typeof o === "string") return _arrayLikeToArray(o, minLen); | ||
var n = Object.prototype.toString.call(o).slice(8, -1); | ||
if (n === "Object" && o.constructor) n = o.constructor.name; | ||
if (n === "Map" || n === "Set") return Array.from(o); | ||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); | ||
return `\x1B[${color[0]}m${String(value)}\x1B[${color[1]}m`; | ||
} | ||
function normaliseOptions({ | ||
showHidden = false, | ||
depth = 2, | ||
colors = false, | ||
customInspect = true, | ||
showProxy = false, | ||
maxArrayLength = Infinity, | ||
breakLength = Infinity, | ||
seen = [], | ||
// eslint-disable-next-line no-shadow | ||
truncate: truncate2 = Infinity, | ||
stylize = String | ||
} = {}, inspect2) { | ||
const options = { | ||
showHidden: Boolean(showHidden), | ||
depth: Number(depth), | ||
colors: Boolean(colors), | ||
customInspect: Boolean(customInspect), | ||
showProxy: Boolean(showProxy), | ||
maxArrayLength: Number(maxArrayLength), | ||
breakLength: Number(breakLength), | ||
truncate: Number(truncate2), | ||
seen, | ||
inspect: inspect2, | ||
stylize | ||
}; | ||
if (options.colors) { | ||
options.stylize = colorise; | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
return options; | ||
} | ||
function truncate(string, length, tail = truncator) { | ||
string = String(string); | ||
const tailLength = tail.length; | ||
const stringLength = string.length; | ||
if (tailLength > length && stringLength > tailLength) { | ||
return tail; | ||
} | ||
function _nonIterableRest() { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
if (stringLength > length && stringLength > tailLength) { | ||
return `${string.slice(0, length - tailLength)}${tail}`; | ||
} | ||
var ansiColors = { | ||
bold: ['1', '22'], | ||
dim: ['2', '22'], | ||
italic: ['3', '23'], | ||
underline: ['4', '24'], | ||
// 5 & 6 are blinking | ||
inverse: ['7', '27'], | ||
hidden: ['8', '28'], | ||
strike: ['9', '29'], | ||
// 10-20 are fonts | ||
// 21-29 are resets for 1-9 | ||
black: ['30', '39'], | ||
red: ['31', '39'], | ||
green: ['32', '39'], | ||
yellow: ['33', '39'], | ||
blue: ['34', '39'], | ||
magenta: ['35', '39'], | ||
cyan: ['36', '39'], | ||
white: ['37', '39'], | ||
brightblack: ['30;1', '39'], | ||
brightred: ['31;1', '39'], | ||
brightgreen: ['32;1', '39'], | ||
brightyellow: ['33;1', '39'], | ||
brightblue: ['34;1', '39'], | ||
brightmagenta: ['35;1', '39'], | ||
brightcyan: ['36;1', '39'], | ||
brightwhite: ['37;1', '39'], | ||
grey: ['90', '39'] | ||
}; | ||
var styles = { | ||
special: 'cyan', | ||
number: 'yellow', | ||
bigint: 'yellow', | ||
boolean: 'yellow', | ||
undefined: 'grey', | ||
null: 'bold', | ||
string: 'green', | ||
symbol: 'green', | ||
date: 'magenta', | ||
regexp: 'red' | ||
}; | ||
var truncator = '…'; | ||
function colorise(value, styleType) { | ||
var color = ansiColors[styles[styleType]] || ansiColors[styleType]; | ||
if (!color) { | ||
return String(value); | ||
return string; | ||
} | ||
function inspectList(list, options, inspectItem, separator = ", ") { | ||
inspectItem = inspectItem || options.inspect; | ||
const size = list.length; | ||
if (size === 0) | ||
return ""; | ||
const originalLength = options.truncate; | ||
let output = ""; | ||
let peek = ""; | ||
let truncated = ""; | ||
for (let i = 0; i < size; i += 1) { | ||
const last = i + 1 === list.length; | ||
const secondToLast = i + 2 === list.length; | ||
truncated = `${truncator}(${list.length - i})`; | ||
const value = list[i]; | ||
options.truncate = originalLength - output.length - (last ? 0 : separator.length); | ||
const string = peek || inspectItem(value, options) + (last ? "" : separator); | ||
const nextLength = output.length + string.length; | ||
const truncatedLength = nextLength + truncated.length; | ||
if (last && nextLength > originalLength && output.length + truncated.length <= originalLength) { | ||
break; | ||
} | ||
return "\x1B[".concat(color[0], "m").concat(String(value), "\x1B[").concat(color[1], "m"); | ||
} | ||
function normaliseOptions() { | ||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
_ref$showHidden = _ref.showHidden, | ||
showHidden = _ref$showHidden === void 0 ? false : _ref$showHidden, | ||
_ref$depth = _ref.depth, | ||
depth = _ref$depth === void 0 ? 2 : _ref$depth, | ||
_ref$colors = _ref.colors, | ||
colors = _ref$colors === void 0 ? false : _ref$colors, | ||
_ref$customInspect = _ref.customInspect, | ||
customInspect = _ref$customInspect === void 0 ? true : _ref$customInspect, | ||
_ref$showProxy = _ref.showProxy, | ||
showProxy = _ref$showProxy === void 0 ? false : _ref$showProxy, | ||
_ref$maxArrayLength = _ref.maxArrayLength, | ||
maxArrayLength = _ref$maxArrayLength === void 0 ? Infinity : _ref$maxArrayLength, | ||
_ref$breakLength = _ref.breakLength, | ||
breakLength = _ref$breakLength === void 0 ? Infinity : _ref$breakLength, | ||
_ref$seen = _ref.seen, | ||
seen = _ref$seen === void 0 ? [] : _ref$seen, | ||
_ref$truncate = _ref.truncate, | ||
truncate = _ref$truncate === void 0 ? Infinity : _ref$truncate, | ||
_ref$stylize = _ref.stylize, | ||
stylize = _ref$stylize === void 0 ? String : _ref$stylize; | ||
var options = { | ||
showHidden: Boolean(showHidden), | ||
depth: Number(depth), | ||
colors: Boolean(colors), | ||
customInspect: Boolean(customInspect), | ||
showProxy: Boolean(showProxy), | ||
maxArrayLength: Number(maxArrayLength), | ||
breakLength: Number(breakLength), | ||
truncate: Number(truncate), | ||
seen: seen, | ||
stylize: stylize | ||
}; | ||
if (options.colors) { | ||
options.stylize = colorise; | ||
if (!last && !secondToLast && truncatedLength > originalLength) { | ||
break; | ||
} | ||
return options; | ||
} | ||
function truncate(string, length) { | ||
var tail = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : truncator; | ||
string = String(string); | ||
var tailLength = tail.length; | ||
var stringLength = string.length; | ||
if (tailLength > length && stringLength > tailLength) { | ||
return tail; | ||
peek = last ? "" : inspectItem(list[i + 1], options) + (secondToLast ? "" : separator); | ||
if (!last && secondToLast && truncatedLength > originalLength && nextLength + peek.length > originalLength) { | ||
break; | ||
} | ||
if (stringLength > length && stringLength > tailLength) { | ||
return "".concat(string.slice(0, length - tailLength)).concat(tail); | ||
output += string; | ||
if (!last && !secondToLast && nextLength + peek.length >= originalLength) { | ||
truncated = `${truncator}(${list.length - i - 1})`; | ||
break; | ||
} | ||
return string; | ||
} // eslint-disable-next-line complexity | ||
function inspectList(list, options, inspectItem) { | ||
var separator = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ', '; | ||
inspectItem = inspectItem || options.inspect; | ||
var size = list.length; | ||
if (size === 0) return ''; | ||
var originalLength = options.truncate; | ||
var output = ''; | ||
var peek = ''; | ||
var truncated = ''; | ||
for (var i = 0; i < size; i += 1) { | ||
var last = i + 1 === list.length; | ||
var secondToLast = i + 2 === list.length; | ||
truncated = "".concat(truncator, "(").concat(list.length - i, ")"); | ||
var value = list[i]; // If there is more than one remaining we need to account for a separator of `, ` | ||
options.truncate = originalLength - output.length - (last ? 0 : separator.length); | ||
var string = peek || inspectItem(value, options) + (last ? '' : separator); | ||
var nextLength = output.length + string.length; | ||
var truncatedLength = nextLength + truncated.length; // If this is the last element, and adding it would | ||
// take us over length, but adding the truncator wouldn't - then break now | ||
if (last && nextLength > originalLength && output.length + truncated.length <= originalLength) { | ||
break; | ||
} // If this isn't the last or second to last element to scan, | ||
// but the string is already over length then break here | ||
if (!last && !secondToLast && truncatedLength > originalLength) { | ||
break; | ||
} // Peek at the next string to determine if we should | ||
// break early before adding this item to the output | ||
peek = last ? '' : inspectItem(list[i + 1], options) + (secondToLast ? '' : separator); // If we have one element left, but this element and | ||
// the next takes over length, the break early | ||
if (!last && secondToLast && truncatedLength > originalLength && nextLength + peek.length > originalLength) { | ||
break; | ||
} | ||
output += string; // If the next element takes us to length - | ||
// but there are more after that, then we should truncate now | ||
if (!last && !secondToLast && nextLength + peek.length >= originalLength) { | ||
truncated = "".concat(truncator, "(").concat(list.length - i - 1, ")"); | ||
break; | ||
} | ||
truncated = ''; | ||
} | ||
return "".concat(output).concat(truncated); | ||
truncated = ""; | ||
} | ||
function quoteComplexKey(key) { | ||
if (key.match(/^[a-zA-Z_][a-zA-Z_0-9]*$/)) { | ||
return key; | ||
} | ||
return JSON.stringify(key).replace(/'/g, "\\'").replace(/\\"/g, '"').replace(/(^"|"$)/g, "'"); | ||
return `${output}${truncated}`; | ||
} | ||
function quoteComplexKey(key) { | ||
if (key.match(/^[a-zA-Z_][a-zA-Z_0-9]*$/)) { | ||
return key; | ||
} | ||
function inspectProperty(_ref2, options) { | ||
var _ref3 = _slicedToArray(_ref2, 2), | ||
key = _ref3[0], | ||
value = _ref3[1]; | ||
options.truncate -= 2; | ||
if (typeof key === 'string') { | ||
key = quoteComplexKey(key); | ||
} else if (typeof key !== 'number') { | ||
key = "[".concat(options.inspect(key, options), "]"); | ||
} | ||
options.truncate -= key.length; | ||
value = options.inspect(value, options); | ||
return "".concat(key, ": ").concat(value); | ||
return JSON.stringify(key).replace(/'/g, "\\'").replace(/\\"/g, '"').replace(/(^"|"$)/g, "'"); | ||
} | ||
function inspectProperty([key, value], options) { | ||
options.truncate -= 2; | ||
if (typeof key === "string") { | ||
key = quoteComplexKey(key); | ||
} else if (typeof key !== "number") { | ||
key = `[${options.inspect(key, options)}]`; | ||
} | ||
options.truncate -= key.length; | ||
value = options.inspect(value, options); | ||
return `${key}: ${value}`; | ||
} | ||
function inspectArray(array, options) { | ||
// Object.keys will always output the Array indices first, so we can slice by | ||
// `array.length` to get non-index properties | ||
var nonIndexProperties = Object.keys(array).slice(array.length); | ||
if (!array.length && !nonIndexProperties.length) return '[]'; | ||
options.truncate -= 4; | ||
var listContents = inspectList(array, options); | ||
options.truncate -= listContents.length; | ||
var propertyContents = ''; | ||
if (nonIndexProperties.length) { | ||
propertyContents = inspectList(nonIndexProperties.map(function (key) { | ||
return [key, array[key]]; | ||
}), options, inspectProperty); | ||
} | ||
return "[ ".concat(listContents).concat(propertyContents ? ", ".concat(propertyContents) : '', " ]"); | ||
// src/array.ts | ||
function inspectArray(array, options) { | ||
const nonIndexProperties = Object.keys(array).slice(array.length); | ||
if (!array.length && !nonIndexProperties.length) | ||
return "[]"; | ||
options.truncate -= 4; | ||
const listContents = inspectList(array, options); | ||
options.truncate -= listContents.length; | ||
let propertyContents = ""; | ||
if (nonIndexProperties.length) { | ||
propertyContents = inspectList( | ||
nonIndexProperties.map((key) => [key, array[key]]), | ||
options, | ||
inspectProperty | ||
); | ||
} | ||
return `[ ${listContents}${propertyContents ? `, ${propertyContents}` : ""} ]`; | ||
} | ||
/* ! | ||
* Chai - getFuncName utility | ||
* Copyright(c) 2012-2016 Jake Luer <jake@alogicalparadox.com> | ||
* MIT Licensed | ||
*/ | ||
/** | ||
* ### .getFuncName(constructorFn) | ||
* | ||
* Returns the name of a function. | ||
* When a non-function instance is passed, returns `null`. | ||
* This also includes a polyfill function if `aFunc.name` is not defined. | ||
* | ||
* @name getFuncName | ||
* @param {Function} funct | ||
* @namespace Utils | ||
* @api public | ||
*/ | ||
var toString = Function.prototype.toString; | ||
var functionNameMatch = /\s*function(?:\s|\s*\/\*[^(?:*\/)]+\*\/\s*)*([^\s\(\/]+)/; | ||
var maxFunctionSourceLength = 512; | ||
function getFuncName(aFunc) { | ||
if (typeof aFunc !== 'function') { | ||
return null; | ||
} | ||
var name = ''; | ||
if (typeof Function.prototype.name === 'undefined' && typeof aFunc.name === 'undefined') { | ||
// eslint-disable-next-line prefer-reflect | ||
var functionSource = toString.call(aFunc); | ||
// To avoid unconstrained resource consumption due to pathalogically large function names, | ||
// we limit the available return value to be less than 512 characters. | ||
if (functionSource.indexOf('(') > maxFunctionSourceLength) { | ||
return name; | ||
} | ||
// Here we run a polyfill if Function does not support the `name` property and if aFunc.name is not defined | ||
var match = functionSource.match(functionNameMatch); | ||
if (match) { | ||
name = match[1]; | ||
} | ||
} else { | ||
// If we've got a `name` property we just use it | ||
name = aFunc.name; | ||
} | ||
return name; | ||
// src/typedarray.ts | ||
var getArrayName = (array) => { | ||
if (typeof Buffer === "function" && array instanceof Buffer) { | ||
return "Buffer"; | ||
} | ||
var getFuncName_1 = getFuncName; | ||
var getArrayName = function getArrayName(array) { | ||
// We need to special case Node.js' Buffers, which report to be Uint8Array | ||
if (typeof Buffer === 'function' && array instanceof Buffer) { | ||
return 'Buffer'; | ||
if (array[Symbol.toStringTag]) { | ||
return array[Symbol.toStringTag]; | ||
} | ||
return array.constructor.name; | ||
}; | ||
function inspectTypedArray(array, options) { | ||
const name = getArrayName(array); | ||
options.truncate -= name.length + 4; | ||
const nonIndexProperties = Object.keys(array).slice(array.length); | ||
if (!array.length && !nonIndexProperties.length) | ||
return `${name}[]`; | ||
let output = ""; | ||
for (let i = 0; i < array.length; i++) { | ||
const string = `${options.stylize(truncate(array[i], options.truncate), "number")}${i === array.length - 1 ? "" : ", "}`; | ||
options.truncate -= string.length; | ||
if (array[i] !== array.length && options.truncate <= 3) { | ||
output += `${truncator}(${array.length - array[i] + 1})`; | ||
break; | ||
} | ||
if (array[Symbol.toStringTag]) { | ||
return array[Symbol.toStringTag]; | ||
} | ||
return getFuncName_1(array.constructor); | ||
}; | ||
function inspectTypedArray(array, options) { | ||
var name = getArrayName(array); | ||
options.truncate -= name.length + 4; // Object.keys will always output the Array indices first, so we can slice by | ||
// `array.length` to get non-index properties | ||
var nonIndexProperties = Object.keys(array).slice(array.length); | ||
if (!array.length && !nonIndexProperties.length) return "".concat(name, "[]"); // As we know TypedArrays only contain Unsigned Integers, we can skip inspecting each one and simply | ||
// stylise the toString() value of them | ||
var output = ''; | ||
for (var i = 0; i < array.length; i++) { | ||
var string = "".concat(options.stylize(truncate(array[i], options.truncate), 'number')).concat(i === array.length - 1 ? '' : ', '); | ||
options.truncate -= string.length; | ||
if (array[i] !== array.length && options.truncate <= 3) { | ||
output += "".concat(truncator, "(").concat(array.length - array[i] + 1, ")"); | ||
break; | ||
} | ||
output += string; | ||
} | ||
var propertyContents = ''; | ||
if (nonIndexProperties.length) { | ||
propertyContents = inspectList(nonIndexProperties.map(function (key) { | ||
return [key, array[key]]; | ||
}), options, inspectProperty); | ||
} | ||
return "".concat(name, "[ ").concat(output).concat(propertyContents ? ", ".concat(propertyContents) : '', " ]"); | ||
output += string; | ||
} | ||
let propertyContents = ""; | ||
if (nonIndexProperties.length) { | ||
propertyContents = inspectList( | ||
nonIndexProperties.map((key) => [key, array[key]]), | ||
options, | ||
inspectProperty | ||
); | ||
} | ||
return `${name}[ ${output}${propertyContents ? `, ${propertyContents}` : ""} ]`; | ||
} | ||
function inspectDate(dateObject, options) { | ||
var stringRepresentation = dateObject.toJSON(); | ||
if (stringRepresentation === null) { | ||
return 'Invalid Date'; | ||
} | ||
var split = stringRepresentation.split('T'); | ||
var date = split[0]; // If we need to - truncate the time portion, but never the date | ||
return options.stylize("".concat(date, "T").concat(truncate(split[1], options.truncate - date.length - 1)), 'date'); | ||
// src/date.ts | ||
function inspectDate(dateObject, options) { | ||
const stringRepresentation = dateObject.toJSON(); | ||
if (stringRepresentation === null) { | ||
return "Invalid Date"; | ||
} | ||
const split = stringRepresentation.split("T"); | ||
const date = split[0]; | ||
return options.stylize(`${date}T${truncate(split[1], options.truncate - date.length - 1)}`, "date"); | ||
} | ||
function inspectFunction(func, options) { | ||
var name = getFuncName_1(func); | ||
if (!name) { | ||
return options.stylize('[Function]', 'special'); | ||
} | ||
return options.stylize("[Function ".concat(truncate(name, options.truncate - 11), "]"), 'special'); | ||
// src/function.ts | ||
function inspectFunction(func, options) { | ||
const name = func.name; | ||
if (!name) { | ||
return options.stylize("[Function]", "special"); | ||
} | ||
return options.stylize(`[Function ${truncate(name, options.truncate - 11)}]`, "special"); | ||
} | ||
function inspectMapEntry(_ref, options) { | ||
var _ref2 = _slicedToArray(_ref, 2), | ||
key = _ref2[0], | ||
value = _ref2[1]; | ||
options.truncate -= 4; | ||
key = options.inspect(key, options); | ||
options.truncate -= key.length; | ||
value = options.inspect(value, options); | ||
return "".concat(key, " => ").concat(value); | ||
} // IE11 doesn't support `map.entries()` | ||
function mapToEntries(map) { | ||
var entries = []; | ||
map.forEach(function (value, key) { | ||
entries.push([key, value]); | ||
}); | ||
return entries; | ||
// src/map.ts | ||
function inspectMapEntry([key, value], options) { | ||
options.truncate -= 4; | ||
key = options.inspect(key, options); | ||
options.truncate -= key.length; | ||
value = options.inspect(value, options); | ||
return `${key} => ${value}`; | ||
} | ||
function mapToEntries(map) { | ||
const entries = []; | ||
map.forEach((value, key) => { | ||
entries.push([key, value]); | ||
}); | ||
return entries; | ||
} | ||
function inspectMap(map, options) { | ||
const size = map.size - 1; | ||
if (size <= 0) { | ||
return "Map{}"; | ||
} | ||
options.truncate -= 7; | ||
return `Map{ ${inspectList(mapToEntries(map), options, inspectMapEntry)} }`; | ||
} | ||
function inspectMap(map, options) { | ||
var size = map.size - 1; | ||
if (size <= 0) { | ||
return 'Map{}'; | ||
} | ||
options.truncate -= 7; | ||
return "Map{ ".concat(inspectList(mapToEntries(map), options, inspectMapEntry), " }"); | ||
// src/number.ts | ||
var isNaN = Number.isNaN || ((i) => i !== i); | ||
function inspectNumber(number, options) { | ||
if (isNaN(number)) { | ||
return options.stylize("NaN", "number"); | ||
} | ||
if (number === Infinity) { | ||
return options.stylize("Infinity", "number"); | ||
} | ||
if (number === -Infinity) { | ||
return options.stylize("-Infinity", "number"); | ||
} | ||
if (number === 0) { | ||
return options.stylize(1 / number === Infinity ? "+0" : "-0", "number"); | ||
} | ||
return options.stylize(truncate(String(number), options.truncate), "number"); | ||
} | ||
var isNaN = Number.isNaN || function (i) { | ||
return i !== i; | ||
}; // eslint-disable-line no-self-compare | ||
// src/bigint.ts | ||
function inspectBigInt(number, options) { | ||
let nums = truncate(number.toString(), options.truncate - 1); | ||
if (nums !== truncator) | ||
nums += "n"; | ||
return options.stylize(nums, "bigint"); | ||
} | ||
// src/regexp.ts | ||
function inspectRegExp(value, options) { | ||
const flags = value.toString().split("/")[2]; | ||
const sourceLength = options.truncate - (2 + flags.length); | ||
const source = value.source; | ||
return options.stylize(`/${truncate(source, sourceLength)}/${flags}`, "regexp"); | ||
} | ||
function inspectNumber(number, options) { | ||
if (isNaN(number)) { | ||
return options.stylize('NaN', 'number'); | ||
} | ||
// src/set.ts | ||
function arrayFromSet(set) { | ||
const values = []; | ||
set.forEach((value) => { | ||
values.push(value); | ||
}); | ||
return values; | ||
} | ||
function inspectSet(set, options) { | ||
if (set.size === 0) | ||
return "Set{}"; | ||
options.truncate -= 7; | ||
return `Set{ ${inspectList(arrayFromSet(set), options)} }`; | ||
} | ||
if (number === Infinity) { | ||
return options.stylize('Infinity', 'number'); | ||
} | ||
if (number === -Infinity) { | ||
return options.stylize('-Infinity', 'number'); | ||
} | ||
if (number === 0) { | ||
return options.stylize(1 / number === Infinity ? '+0' : '-0', 'number'); | ||
} | ||
return options.stylize(truncate(number, options.truncate), 'number'); | ||
// src/string.ts | ||
var stringEscapeChars = new RegExp( | ||
"['\\u0000-\\u001f\\u007f-\\u009f\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]", | ||
"g" | ||
); | ||
var escapeCharacters = { | ||
"\b": "\\b", | ||
" ": "\\t", | ||
"\n": "\\n", | ||
"\f": "\\f", | ||
"\r": "\\r", | ||
"'": "\\'", | ||
"\\": "\\\\" | ||
}; | ||
var hex = 16; | ||
var unicodeLength = 4; | ||
function escape(char) { | ||
return escapeCharacters[char] || `\\u${`0000${char.charCodeAt(0).toString(hex)}`.slice(-unicodeLength)}`; | ||
} | ||
function inspectString(string, options) { | ||
if (stringEscapeChars.test(string)) { | ||
string = string.replace(stringEscapeChars, escape); | ||
} | ||
return options.stylize(`'${truncate(string, options.truncate - 2)}'`, "string"); | ||
} | ||
function inspectBigInt(number, options) { | ||
var nums = truncate(number.toString(), options.truncate - 1); | ||
if (nums !== truncator) nums += 'n'; | ||
return options.stylize(nums, 'bigint'); | ||
// src/symbol.ts | ||
function inspectSymbol(value) { | ||
if ("description" in Symbol.prototype) { | ||
return value.description ? `Symbol(${value.description})` : "Symbol()"; | ||
} | ||
return value.toString(); | ||
} | ||
function inspectRegExp(value, options) { | ||
var flags = value.toString().split('/')[2]; | ||
var sourceLength = options.truncate - (2 + flags.length); | ||
var source = value.source; | ||
return options.stylize("/".concat(truncate(source, sourceLength), "/").concat(flags), 'regexp'); | ||
// src/promise.ts | ||
var getPromiseValue = () => "Promise{\u2026}"; | ||
try { | ||
const { getPromiseDetails, kPending, kRejected } = process.binding("util"); | ||
if (Array.isArray(getPromiseDetails(Promise.resolve()))) { | ||
getPromiseValue = (value, options) => { | ||
const [state, innerValue] = getPromiseDetails(value); | ||
if (state === kPending) { | ||
return "Promise{<pending>}"; | ||
} | ||
return `Promise${state === kRejected ? "!" : ""}{${options.inspect(innerValue, options)}}`; | ||
}; | ||
} | ||
} catch (notNode) { | ||
} | ||
var promise_default = getPromiseValue; | ||
function arrayFromSet(set) { | ||
var values = []; | ||
set.forEach(function (value) { | ||
values.push(value); | ||
}); | ||
return values; | ||
// src/object.ts | ||
function inspectObject(object, options) { | ||
const properties = Object.getOwnPropertyNames(object); | ||
const symbols = Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(object) : []; | ||
if (properties.length === 0 && symbols.length === 0) { | ||
return "{}"; | ||
} | ||
function inspectSet(set, options) { | ||
if (set.size === 0) return 'Set{}'; | ||
options.truncate -= 7; | ||
return "Set{ ".concat(inspectList(arrayFromSet(set), options), " }"); | ||
options.truncate -= 4; | ||
options.seen = options.seen || []; | ||
if (options.seen.indexOf(object) >= 0) { | ||
return "[Circular]"; | ||
} | ||
var stringEscapeChars = new RegExp("['\\u0000-\\u001f\\u007f-\\u009f\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5" + "\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]", 'g'); | ||
var escapeCharacters = { | ||
'\b': '\\b', | ||
'\t': '\\t', | ||
'\n': '\\n', | ||
'\f': '\\f', | ||
'\r': '\\r', | ||
"'": "\\'", | ||
'\\': '\\\\' | ||
}; | ||
var hex = 16; | ||
var unicodeLength = 4; | ||
function escape(char) { | ||
return escapeCharacters[char] || "\\u".concat("0000".concat(char.charCodeAt(0).toString(hex)).slice(-unicodeLength)); | ||
options.seen.push(object); | ||
const propertyContents = inspectList( | ||
properties.map((key) => [key, object[key]]), | ||
options, | ||
inspectProperty | ||
); | ||
const symbolContents = inspectList( | ||
symbols.map((key) => [key, object[key]]), | ||
options, | ||
inspectProperty | ||
); | ||
options.seen.pop(); | ||
let sep = ""; | ||
if (propertyContents && symbolContents) { | ||
sep = ", "; | ||
} | ||
return `{ ${propertyContents}${sep}${symbolContents} }`; | ||
} | ||
function inspectString(string, options) { | ||
if (stringEscapeChars.test(string)) { | ||
string = string.replace(stringEscapeChars, escape); | ||
} | ||
return options.stylize("'".concat(truncate(string, options.truncate - 2), "'"), 'string'); | ||
// src/class.ts | ||
var toStringTag = typeof Symbol !== "undefined" && Symbol.toStringTag ? Symbol.toStringTag : false; | ||
function inspectClass(value, options) { | ||
let name = ""; | ||
if (toStringTag && toStringTag in value) { | ||
name = value[toStringTag]; | ||
} | ||
function inspectSymbol(value) { | ||
if ('description' in Symbol.prototype) { | ||
return value.description ? "Symbol(".concat(value.description, ")") : 'Symbol()'; | ||
} | ||
return value.toString(); | ||
name = name || value.constructor.name; | ||
if (!name || name === "_class") { | ||
name = "<Anonymous Class>"; | ||
} | ||
options.truncate -= name.length; | ||
return `${name}${inspectObject(value, options)}`; | ||
} | ||
var getPromiseValue = function getPromiseValue() { | ||
return 'Promise{…}'; | ||
}; | ||
// src/arguments.ts | ||
function inspectArguments(args, options) { | ||
if (args.length === 0) | ||
return "Arguments[]"; | ||
options.truncate -= 13; | ||
return `Arguments[ ${inspectList(args, options)} ]`; | ||
} | ||
try { | ||
var _process$binding = process.binding('util'), | ||
getPromiseDetails = _process$binding.getPromiseDetails, | ||
kPending = _process$binding.kPending, | ||
kRejected = _process$binding.kRejected; | ||
if (Array.isArray(getPromiseDetails(Promise.resolve()))) { | ||
getPromiseValue = function getPromiseValue(value, options) { | ||
var _getPromiseDetails = getPromiseDetails(value), | ||
_getPromiseDetails2 = _slicedToArray(_getPromiseDetails, 2), | ||
state = _getPromiseDetails2[0], | ||
innerValue = _getPromiseDetails2[1]; | ||
if (state === kPending) { | ||
return 'Promise{<pending>}'; | ||
} | ||
return "Promise".concat(state === kRejected ? '!' : '', "{").concat(options.inspect(innerValue, options), "}"); | ||
}; | ||
} | ||
} catch (notNode) { | ||
/* ignore */ | ||
// src/error.ts | ||
var errorKeys = [ | ||
"stack", | ||
"line", | ||
"column", | ||
"name", | ||
"message", | ||
"fileName", | ||
"lineNumber", | ||
"columnNumber", | ||
"number", | ||
"description" | ||
]; | ||
function inspectObject2(error, options) { | ||
const properties = Object.getOwnPropertyNames(error).filter((key) => errorKeys.indexOf(key) === -1); | ||
const name = error.name; | ||
options.truncate -= name.length; | ||
let message = ""; | ||
if (typeof error.message === "string") { | ||
message = truncate(error.message, options.truncate); | ||
} else { | ||
properties.unshift("message"); | ||
} | ||
message = message ? `: ${message}` : ""; | ||
options.truncate -= message.length + 5; | ||
const propertyContents = inspectList( | ||
properties.map((key) => [key, error[key]]), | ||
options, | ||
inspectProperty | ||
); | ||
return `${name}${message}${propertyContents ? ` { ${propertyContents} }` : ""}`; | ||
} | ||
var inspectPromise = getPromiseValue; | ||
function inspectObject(object, options) { | ||
var properties = Object.getOwnPropertyNames(object); | ||
var symbols = Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(object) : []; | ||
if (properties.length === 0 && symbols.length === 0) { | ||
return '{}'; | ||
} | ||
options.truncate -= 4; | ||
options.seen = options.seen || []; | ||
if (options.seen.indexOf(object) >= 0) { | ||
return '[Circular]'; | ||
} | ||
options.seen.push(object); | ||
var propertyContents = inspectList(properties.map(function (key) { | ||
return [key, object[key]]; | ||
}), options, inspectProperty); | ||
var symbolContents = inspectList(symbols.map(function (key) { | ||
return [key, object[key]]; | ||
}), options, inspectProperty); | ||
options.seen.pop(); | ||
var sep = ''; | ||
if (propertyContents && symbolContents) { | ||
sep = ', '; | ||
} | ||
return "{ ".concat(propertyContents).concat(sep).concat(symbolContents, " }"); | ||
// src/html.ts | ||
function inspectAttribute([key, value], options) { | ||
options.truncate -= 3; | ||
if (!value) { | ||
return `${options.stylize(String(key), "yellow")}`; | ||
} | ||
var toStringTag = typeof Symbol !== 'undefined' && Symbol.toStringTag ? Symbol.toStringTag : false; | ||
function inspectClass(value, options) { | ||
var name = ''; | ||
if (toStringTag && toStringTag in value) { | ||
name = value[toStringTag]; | ||
} | ||
name = name || getFuncName_1(value.constructor); // Babel transforms anonymous classes to the name `_class` | ||
if (!name || name === '_class') { | ||
name = '<Anonymous Class>'; | ||
} | ||
options.truncate -= name.length; | ||
return "".concat(name).concat(inspectObject(value, options)); | ||
return `${options.stylize(String(key), "yellow")}=${options.stylize(`"${value}"`, "string")}`; | ||
} | ||
function inspectHTMLCollection(collection, options) { | ||
return inspectList(collection, options, inspectHTML, "\n"); | ||
} | ||
function inspectHTML(element, options) { | ||
const properties = element.getAttributeNames(); | ||
const name = element.tagName.toLowerCase(); | ||
const head = options.stylize(`<${name}`, "special"); | ||
const headClose = options.stylize(`>`, "special"); | ||
const tail = options.stylize(`</${name}>`, "special"); | ||
options.truncate -= name.length * 2 + 5; | ||
let propertyContents = ""; | ||
if (properties.length > 0) { | ||
propertyContents += " "; | ||
propertyContents += inspectList( | ||
properties.map((key) => [key, element.getAttribute(key)]), | ||
options, | ||
inspectAttribute, | ||
" " | ||
); | ||
} | ||
function inspectArguments(args, options) { | ||
if (args.length === 0) return 'Arguments[]'; | ||
options.truncate -= 13; | ||
return "Arguments[ ".concat(inspectList(args, options), " ]"); | ||
options.truncate -= propertyContents.length; | ||
const truncate2 = options.truncate; | ||
let children = inspectHTMLCollection(element.children, options); | ||
if (children && children.length > truncate2) { | ||
children = `${truncator}(${element.children.length})`; | ||
} | ||
return `${head}${propertyContents}${headClose}${children}${tail}`; | ||
} | ||
var errorKeys = ['stack', 'line', 'column', 'name', 'message', 'fileName', 'lineNumber', 'columnNumber', 'number', 'description']; | ||
function inspectObject$1(error, options) { | ||
var properties = Object.getOwnPropertyNames(error).filter(function (key) { | ||
return errorKeys.indexOf(key) === -1; | ||
}); | ||
var name = error.name; | ||
options.truncate -= name.length; | ||
var message = ''; | ||
if (typeof error.message === 'string') { | ||
message = truncate(error.message, options.truncate); | ||
} else { | ||
properties.unshift('message'); | ||
} | ||
message = message ? ": ".concat(message) : ''; | ||
options.truncate -= message.length + 5; | ||
var propertyContents = inspectList(properties.map(function (key) { | ||
return [key, error[key]]; | ||
}), options, inspectProperty); | ||
return "".concat(name).concat(message).concat(propertyContents ? " { ".concat(propertyContents, " }") : ''); | ||
// src/index.ts | ||
var symbolsSupported = typeof Symbol === "function" && typeof Symbol.for === "function"; | ||
var chaiInspect = symbolsSupported ? Symbol.for("chai/inspect") : "@@chai/inspect"; | ||
var nodeInspect = false; | ||
try { | ||
const nodeUtil = require_util(); | ||
nodeInspect = nodeUtil.inspect ? nodeUtil.inspect.custom : false; | ||
} catch (noNodeInspect) { | ||
nodeInspect = false; | ||
} | ||
var constructorMap = /* @__PURE__ */ new WeakMap(); | ||
var stringTagMap = {}; | ||
var baseTypesMap = { | ||
undefined: (value, options) => options.stylize("undefined", "undefined"), | ||
null: (value, options) => options.stylize("null", "null"), | ||
boolean: (value, options) => options.stylize(String(value), "boolean"), | ||
Boolean: (value, options) => options.stylize(String(value), "boolean"), | ||
number: inspectNumber, | ||
Number: inspectNumber, | ||
bigint: inspectBigInt, | ||
BigInt: inspectBigInt, | ||
string: inspectString, | ||
String: inspectString, | ||
function: inspectFunction, | ||
Function: inspectFunction, | ||
symbol: inspectSymbol, | ||
// A Symbol polyfill will return `Symbol` not `symbol` from typedetect | ||
Symbol: inspectSymbol, | ||
Array: inspectArray, | ||
Date: inspectDate, | ||
Map: inspectMap, | ||
Set: inspectSet, | ||
RegExp: inspectRegExp, | ||
Promise: promise_default, | ||
// WeakSet, WeakMap are totally opaque to us | ||
WeakSet: (value, options) => options.stylize("WeakSet{\u2026}", "special"), | ||
WeakMap: (value, options) => options.stylize("WeakMap{\u2026}", "special"), | ||
Arguments: inspectArguments, | ||
Int8Array: inspectTypedArray, | ||
Uint8Array: inspectTypedArray, | ||
Uint8ClampedArray: inspectTypedArray, | ||
Int16Array: inspectTypedArray, | ||
Uint16Array: inspectTypedArray, | ||
Int32Array: inspectTypedArray, | ||
Uint32Array: inspectTypedArray, | ||
Float32Array: inspectTypedArray, | ||
Float64Array: inspectTypedArray, | ||
Generator: () => "", | ||
DataView: () => "", | ||
ArrayBuffer: () => "", | ||
Error: inspectObject2, | ||
HTMLCollection: inspectHTMLCollection, | ||
NodeList: inspectHTMLCollection | ||
}; | ||
var inspectCustom = (value, options, type) => { | ||
if (chaiInspect in value && typeof value[chaiInspect] === "function") { | ||
return value[chaiInspect](options); | ||
} | ||
function inspectAttribute(_ref, options) { | ||
var _ref2 = _slicedToArray(_ref, 2), | ||
key = _ref2[0], | ||
value = _ref2[1]; | ||
options.truncate -= 3; | ||
if (!value) { | ||
return "".concat(options.stylize(key, 'yellow')); | ||
} | ||
return "".concat(options.stylize(key, 'yellow'), "=").concat(options.stylize("\"".concat(value, "\""), 'string')); | ||
if (nodeInspect && nodeInspect in value && typeof value[nodeInspect] === "function") { | ||
return value[nodeInspect](options.depth, options); | ||
} | ||
function inspectHTMLCollection(collection, options) { | ||
// eslint-disable-next-line no-use-before-define | ||
return inspectList(collection, options, inspectHTML, '\n'); | ||
if ("inspect" in value && typeof value.inspect === "function") { | ||
return value.inspect(options.depth, options); | ||
} | ||
function inspectHTML(element, options) { | ||
var properties = element.getAttributeNames(); | ||
var name = element.tagName.toLowerCase(); | ||
var head = options.stylize("<".concat(name), 'special'); | ||
var headClose = options.stylize(">", 'special'); | ||
var tail = options.stylize("</".concat(name, ">"), 'special'); | ||
options.truncate -= name.length * 2 + 5; | ||
var propertyContents = ''; | ||
if (properties.length > 0) { | ||
propertyContents += ' '; | ||
propertyContents += inspectList(properties.map(function (key) { | ||
return [key, element.getAttribute(key)]; | ||
}), options, inspectAttribute, ' '); | ||
} | ||
options.truncate -= propertyContents.length; | ||
var truncate = options.truncate; | ||
var children = inspectHTMLCollection(element.children, options); | ||
if (children && children.length > truncate) { | ||
children = "".concat(truncator, "(").concat(element.children.length, ")"); | ||
} | ||
return "".concat(head).concat(propertyContents).concat(headClose).concat(children).concat(tail); | ||
if ("constructor" in value && constructorMap.has(value.constructor)) { | ||
return constructorMap.get(value.constructor)(value, options); | ||
} | ||
var symbolsSupported = typeof Symbol === 'function' && typeof Symbol.for === 'function'; | ||
var chaiInspect = symbolsSupported ? Symbol.for('chai/inspect') : '@@chai/inspect'; | ||
var nodeInspect = false; | ||
try { | ||
// eslint-disable-next-line global-require | ||
var nodeUtil = require('util'); | ||
nodeInspect = nodeUtil.inspect ? nodeUtil.inspect.custom : false; | ||
} catch (noNodeInspect) { | ||
nodeInspect = false; | ||
if (stringTagMap[type]) { | ||
return stringTagMap[type](value, options); | ||
} | ||
function FakeMap() { | ||
// eslint-disable-next-line prefer-template | ||
this.key = 'chai/loupe__' + Math.random() + Date.now(); | ||
return ""; | ||
}; | ||
var toString = Object.prototype.toString; | ||
function inspect(value, opts = {}) { | ||
const options = normaliseOptions(opts, inspect); | ||
const { customInspect } = options; | ||
let type = value === null ? "null" : typeof value; | ||
if (type === "object") { | ||
type = toString.call(value).slice(8, -1); | ||
} | ||
FakeMap.prototype = { | ||
// eslint-disable-next-line object-shorthand | ||
get: function get(key) { | ||
return key[this.key]; | ||
}, | ||
// eslint-disable-next-line object-shorthand | ||
has: function has(key) { | ||
return this.key in key; | ||
}, | ||
// eslint-disable-next-line object-shorthand | ||
set: function set(key, value) { | ||
if (Object.isExtensible(key)) { | ||
Object.defineProperty(key, this.key, { | ||
// eslint-disable-next-line object-shorthand | ||
value: value, | ||
configurable: true | ||
}); | ||
} | ||
} | ||
}; | ||
var constructorMap = new (typeof WeakMap === 'function' ? WeakMap : FakeMap)(); | ||
var stringTagMap = {}; | ||
var baseTypesMap = { | ||
undefined: function undefined$1(value, options) { | ||
return options.stylize('undefined', 'undefined'); | ||
}, | ||
null: function _null(value, options) { | ||
return options.stylize(null, 'null'); | ||
}, | ||
boolean: function boolean(value, options) { | ||
return options.stylize(value, 'boolean'); | ||
}, | ||
Boolean: function Boolean(value, options) { | ||
return options.stylize(value, 'boolean'); | ||
}, | ||
number: inspectNumber, | ||
Number: inspectNumber, | ||
bigint: inspectBigInt, | ||
BigInt: inspectBigInt, | ||
string: inspectString, | ||
String: inspectString, | ||
function: inspectFunction, | ||
Function: inspectFunction, | ||
symbol: inspectSymbol, | ||
// A Symbol polyfill will return `Symbol` not `symbol` from typedetect | ||
Symbol: inspectSymbol, | ||
Array: inspectArray, | ||
Date: inspectDate, | ||
Map: inspectMap, | ||
Set: inspectSet, | ||
RegExp: inspectRegExp, | ||
Promise: inspectPromise, | ||
// WeakSet, WeakMap are totally opaque to us | ||
WeakSet: function WeakSet(value, options) { | ||
return options.stylize('WeakSet{…}', 'special'); | ||
}, | ||
WeakMap: function WeakMap(value, options) { | ||
return options.stylize('WeakMap{…}', 'special'); | ||
}, | ||
Arguments: inspectArguments, | ||
Int8Array: inspectTypedArray, | ||
Uint8Array: inspectTypedArray, | ||
Uint8ClampedArray: inspectTypedArray, | ||
Int16Array: inspectTypedArray, | ||
Uint16Array: inspectTypedArray, | ||
Int32Array: inspectTypedArray, | ||
Uint32Array: inspectTypedArray, | ||
Float32Array: inspectTypedArray, | ||
Float64Array: inspectTypedArray, | ||
Generator: function Generator() { | ||
return ''; | ||
}, | ||
DataView: function DataView() { | ||
return ''; | ||
}, | ||
ArrayBuffer: function ArrayBuffer() { | ||
return ''; | ||
}, | ||
Error: inspectObject$1, | ||
HTMLCollection: inspectHTMLCollection, | ||
NodeList: inspectHTMLCollection | ||
}; // eslint-disable-next-line complexity | ||
var inspectCustom = function inspectCustom(value, options, type) { | ||
if (chaiInspect in value && typeof value[chaiInspect] === 'function') { | ||
return value[chaiInspect](options); | ||
} | ||
if (nodeInspect && nodeInspect in value && typeof value[nodeInspect] === 'function') { | ||
return value[nodeInspect](options.depth, options); | ||
} | ||
if ('inspect' in value && typeof value.inspect === 'function') { | ||
return value.inspect(options.depth, options); | ||
} | ||
if ('constructor' in value && constructorMap.has(value.constructor)) { | ||
return constructorMap.get(value.constructor)(value, options); | ||
} | ||
if (stringTagMap[type]) { | ||
return stringTagMap[type](value, options); | ||
} | ||
return ''; | ||
}; | ||
var toString$1 = Object.prototype.toString; // eslint-disable-next-line complexity | ||
function inspect(value, options) { | ||
options = normaliseOptions(options); | ||
options.inspect = inspect; | ||
var _options = options, | ||
customInspect = _options.customInspect; | ||
var type = value === null ? 'null' : _typeof(value); | ||
if (type === 'object') { | ||
type = toString$1.call(value).slice(8, -1); | ||
} // If it is a base value that we already support, then use Loupe's inspector | ||
if (baseTypesMap[type]) { | ||
return baseTypesMap[type](value, options); | ||
} // If `options.customInspect` is set to true then try to use the custom inspector | ||
if (customInspect && value) { | ||
var output = inspectCustom(value, options, type); | ||
if (output) { | ||
if (typeof output === 'string') return output; | ||
return inspect(output, options); | ||
} | ||
} | ||
var proto = value ? Object.getPrototypeOf(value) : false; // If it's a plain Object then use Loupe's inspector | ||
if (proto === Object.prototype || proto === null) { | ||
return inspectObject(value, options); | ||
} // Specifically account for HTMLElements | ||
// eslint-disable-next-line no-undef | ||
if (value && typeof HTMLElement === 'function' && value instanceof HTMLElement) { | ||
return inspectHTML(value, options); | ||
} | ||
if ('constructor' in value) { | ||
// If it is a class, inspect it like an object but add the constructor name | ||
if (value.constructor !== Object) { | ||
return inspectClass(value, options); | ||
} // If it is an object with an anonymous prototype, display it as an object. | ||
return inspectObject(value, options); | ||
} // last chance to check if it's an object | ||
if (value === Object(value)) { | ||
return inspectObject(value, options); | ||
} // We have run out of options! Just stringify the value | ||
return options.stylize(String(value), type); | ||
if (type in baseTypesMap) { | ||
return baseTypesMap[type](value, options); | ||
} | ||
function registerConstructor(constructor, inspector) { | ||
if (constructorMap.has(constructor)) { | ||
return false; | ||
if (customInspect && value) { | ||
const output = inspectCustom(value, options, type); | ||
if (output) { | ||
if (typeof output === "string") | ||
return output; | ||
return inspect(output, options); | ||
} | ||
constructorMap.set(constructor, inspector); | ||
return true; | ||
} | ||
function registerStringTag(stringTag, inspector) { | ||
if (stringTag in stringTagMap) { | ||
return false; | ||
const proto = value ? Object.getPrototypeOf(value) : false; | ||
if (proto === Object.prototype || proto === null) { | ||
return inspectObject(value, options); | ||
} | ||
if (value && typeof HTMLElement === "function" && value instanceof HTMLElement) { | ||
return inspectHTML(value, options); | ||
} | ||
if ("constructor" in value) { | ||
if (value.constructor !== Object) { | ||
return inspectClass(value, options); | ||
} | ||
stringTagMap[stringTag] = inspector; | ||
return true; | ||
return inspectObject(value, options); | ||
} | ||
var custom = chaiInspect; | ||
exports.custom = custom; | ||
exports.default = inspect; | ||
exports.inspect = inspect; | ||
exports.registerConstructor = registerConstructor; | ||
exports.registerStringTag = registerStringTag; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); | ||
if (value === Object(value)) { | ||
return inspectObject(value, options); | ||
} | ||
return options.stylize(String(value), type); | ||
} | ||
function registerConstructor(constructor, inspector) { | ||
if (constructorMap.has(constructor)) { | ||
return false; | ||
} | ||
constructorMap.set(constructor, inspector); | ||
return true; | ||
} | ||
function registerStringTag(stringTag, inspector) { | ||
if (stringTag in stringTagMap) { | ||
return false; | ||
} | ||
stringTagMap[stringTag] = inspector; | ||
return true; | ||
} | ||
var custom = chaiInspect; | ||
var src_default = inspect; |
{ | ||
"name": "loupe", | ||
"version": "2.3.7", | ||
"version": "3.0.0", | ||
"description": "Inspect utility for Node.js and browsers", | ||
@@ -11,4 +11,5 @@ "homepage": "https://github.com/chaijs/loupe", | ||
], | ||
"main": "./loupe.js", | ||
"module": "./index.js", | ||
"type": "module", | ||
"main": "./lib/index.js", | ||
"module": "./lib/index.js", | ||
"browser": { | ||
@@ -24,18 +25,19 @@ "./index.js": "./loupe.js", | ||
"loupe.js", | ||
"index.js", | ||
"lib/*" | ||
], | ||
"scripts": { | ||
"bench": "node -r esm bench", | ||
"commit-msg": "commitlint -x angular", | ||
"bench": "node bench", | ||
"lint": "eslint --ignore-path .gitignore .", | ||
"prepare": "rollup -c rollup.conf.js", | ||
"semantic-release": "semantic-release pre && npm publish && semantic-release post", | ||
"test": "npm run test:node && npm run test:browser", | ||
"pretest:browser": "npm run prepare", | ||
"test:browser": "karma start --singleRun=true", | ||
"posttest:browser": "npm run upload-coverage", | ||
"test:node": "nyc mocha -r esm", | ||
"posttest:node": "nyc report --report-dir \"coverage/node-$(node --version)\" --reporter=lcovonly && npm run upload-coverage", | ||
"upload-coverage": "codecov" | ||
"pretest:browser": "npm run build", | ||
"test:browser": "wtr", | ||
"pretest:node": "npm run build", | ||
"test:node": "mocha", | ||
"build": "npm run build:lib && npm run build:esm-bundle && npm run build:cjs-bundle", | ||
"build:lib": "esbuild \"src/*.ts\" --outdir=lib --format=esm", | ||
"build:esm-bundle": "esbuild --bundle src/index.ts --outfile=loupe.js --format=esm", | ||
"build:cjs-bundle": "esbuild --bundle src/index.ts --outfile=loupe.js --format=cjs", | ||
"upload-coverage": "codecov", | ||
"postinstall": "npx playwright install" | ||
}, | ||
@@ -106,13 +108,11 @@ "eslintConfig": { | ||
"devDependencies": { | ||
"@babel/core": "^7.12.10", | ||
"@babel/preset-env": "^7.12.11", | ||
"@commitlint/cli": "^11.0.0", | ||
"@rollup/plugin-commonjs": "^17.0.0", | ||
"@rollup/plugin-node-resolve": "^11.1.0", | ||
"@web/dev-server-esbuild": "^0.4.2", | ||
"@web/test-runner": "^0.17.2", | ||
"@web/test-runner-playwright": "^0.10.1", | ||
"benchmark": "^2.1.4", | ||
"chai": "^4.2.0", | ||
"chai": "^5.0.0-alpha.0", | ||
"codecov": "^3.8.1", | ||
"commitlint-config-angular": "^11.0.0", | ||
"core-js": "^3.8.3", | ||
"cross-env": "^7.0.3", | ||
"esbuild": "^0.19.5", | ||
"eslint": "^7.18.0", | ||
@@ -122,24 +122,10 @@ "eslint-config-strict": "^14.0.1", | ||
"eslint-plugin-prettier": "^3.3.1", | ||
"esm": "^3.2.25", | ||
"husky": "^4.3.8", | ||
"karma": "^5.2.3", | ||
"karma-chrome-launcher": "^3.1.0", | ||
"karma-coverage": "^2.0.3", | ||
"karma-edge-launcher": "^0.4.2", | ||
"karma-firefox-launcher": "^2.1.0", | ||
"karma-ie-launcher": "^1.0.0", | ||
"karma-mocha": "^2.0.1", | ||
"karma-opera-launcher": "^1.0.0", | ||
"karma-safari-launcher": "^1.0.0", | ||
"karma-safaritechpreview-launcher": "^2.0.2", | ||
"karma-sauce-launcher": "^4.3.4", | ||
"mocha": "^8.2.1", | ||
"mocha": "^10.2.0", | ||
"nyc": "^15.1.0", | ||
"prettier": "^2.2.1", | ||
"rollup": "^2.37.1", | ||
"rollup-plugin-babel": "^4.4.0", | ||
"rollup-plugin-istanbul": "^3.0.0", | ||
"semantic-release": "^17.3.6", | ||
"simple-assert": "^1.0.0" | ||
"simple-assert": "^1.0.0", | ||
"typescript": "^5.0.0-beta" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
20
Yes
46181
1275
1