$
This commit is contained in:
7
node_modules/loupe/lib/arguments.js
generated
vendored
Normal file
7
node_modules/loupe/lib/arguments.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import { inspectList } from './helpers'
|
||||
|
||||
export default function inspectArguments(args, options) {
|
||||
if (args.length === 0) return 'Arguments[]'
|
||||
options.truncate -= 13
|
||||
return `Arguments[ ${inspectList(args, options)} ]`
|
||||
}
|
20
node_modules/loupe/lib/array.js
generated
vendored
Normal file
20
node_modules/loupe/lib/array.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
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 = ''
|
||||
if (nonIndexProperties.length) {
|
||||
propertyContents = inspectList(
|
||||
nonIndexProperties.map(key => [key, array[key]]),
|
||||
options,
|
||||
inspectProperty
|
||||
)
|
||||
}
|
||||
return `[ ${listContents}${propertyContents ? `, ${propertyContents}` : ''} ]`
|
||||
}
|
7
node_modules/loupe/lib/bigint.js
generated
vendored
Normal file
7
node_modules/loupe/lib/bigint.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
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')
|
||||
}
|
18
node_modules/loupe/lib/class.js
generated
vendored
Normal file
18
node_modules/loupe/lib/class.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
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 = ''
|
||||
if (toStringTag && toStringTag in value) {
|
||||
name = value[toStringTag]
|
||||
}
|
||||
name = name || getFuncName(value.constructor)
|
||||
// Babel transforms anonymous classes to the name `_class`
|
||||
if (!name || name === '_class') {
|
||||
name = '<Anonymous Class>'
|
||||
}
|
||||
options.truncate -= name.length
|
||||
return `${name}${inspectObject(value, options)}`
|
||||
}
|
8
node_modules/loupe/lib/date.js
generated
vendored
Normal file
8
node_modules/loupe/lib/date.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { truncate } from './helpers'
|
||||
|
||||
export default function inspectDate(dateObject, options) {
|
||||
// If we need to - truncate the time portion, but never the date
|
||||
const split = dateObject.toJSON().split('T')
|
||||
const date = split[0]
|
||||
return options.stylize(`${date}T${truncate(split[1], options.truncate - date.length - 1)}`, 'date')
|
||||
}
|
34
node_modules/loupe/lib/error.js
generated
vendored
Normal file
34
node_modules/loupe/lib/error.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
import { truncate, inspectList, inspectProperty } from './helpers'
|
||||
|
||||
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)
|
||||
} 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} }` : ''}`
|
||||
}
|
10
node_modules/loupe/lib/function.js
generated
vendored
Normal file
10
node_modules/loupe/lib/function.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import getFunctionName from 'get-func-name'
|
||||
import { truncate } from './helpers'
|
||||
|
||||
export default function inspectFunction(func, options) {
|
||||
const name = getFunctionName(func)
|
||||
if (!name) {
|
||||
return options.stylize('[Function]', 'special')
|
||||
}
|
||||
return options.stylize(`[Function ${truncate(name, options.truncate - 11)}]`, 'special')
|
||||
}
|
177
node_modules/loupe/lib/helpers.js
generated
vendored
Normal file
177
node_modules/loupe/lib/helpers.js
generated
vendored
Normal file
@@ -0,0 +1,177 @@
|
||||
const 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'],
|
||||
}
|
||||
|
||||
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 = '…'
|
||||
|
||||
function colorise(value, styleType) {
|
||||
const color = ansiColors[styles[styleType]] || ansiColors[styleType]
|
||||
if (!color) {
|
||||
return String(value)
|
||||
}
|
||||
return `\u001b[${color[0]}m${String(value)}\u001b[${color[1]}m`
|
||||
}
|
||||
|
||||
export function normaliseOptions({
|
||||
showHidden = false,
|
||||
depth = 2,
|
||||
colors = false,
|
||||
customInspect = true,
|
||||
showProxy = false,
|
||||
maxArrayLength = Infinity,
|
||||
breakLength = Infinity,
|
||||
seen = [],
|
||||
// eslint-disable-next-line no-shadow
|
||||
truncate = Infinity,
|
||||
stylize = String,
|
||||
} = {}) {
|
||||
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(truncate),
|
||||
seen,
|
||||
stylize,
|
||||
}
|
||||
if (options.colors) {
|
||||
options.stylize = colorise
|
||||
}
|
||||
return options
|
||||
}
|
||||
|
||||
export function truncate(string, length, tail = truncator) {
|
||||
string = String(string)
|
||||
const tailLength = tail.length
|
||||
const stringLength = string.length
|
||||
if (tailLength > length && stringLength > tailLength) {
|
||||
return tail
|
||||
}
|
||||
if (stringLength > length && stringLength > tailLength) {
|
||||
return `${string.slice(0, length - tailLength)}${tail}`
|
||||
}
|
||||
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 = ''
|
||||
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
|
||||
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 = `${truncator}(${list.length - i - 1})`
|
||||
break
|
||||
}
|
||||
|
||||
truncated = ''
|
||||
}
|
||||
return `${output}${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, "'")
|
||||
}
|
||||
|
||||
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)}]`
|
||||
}
|
||||
options.truncate -= key.length
|
||||
value = options.inspect(value, options)
|
||||
return `${key}: ${value}`
|
||||
}
|
40
node_modules/loupe/lib/html.js
generated
vendored
Normal file
40
node_modules/loupe/lib/html.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
import { truncator, inspectList } from './helpers'
|
||||
|
||||
export function inspectAttribute([key, value], options) {
|
||||
options.truncate -= 3
|
||||
if (!value) {
|
||||
return `${options.stylize(key, 'yellow')}`
|
||||
}
|
||||
return `${options.stylize(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')
|
||||
}
|
||||
|
||||
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 = ''
|
||||
if (properties.length > 0) {
|
||||
propertyContents += ' '
|
||||
propertyContents += inspectList(
|
||||
properties.map(key => [key, element.getAttribute(key)]),
|
||||
options,
|
||||
inspectAttribute,
|
||||
' '
|
||||
)
|
||||
}
|
||||
options.truncate -= propertyContents.length
|
||||
const truncate = options.truncate
|
||||
let children = inspectHTMLCollection(element.children, options)
|
||||
if (children && children.length > truncate) {
|
||||
children = `${truncator}(${element.children.length})`
|
||||
}
|
||||
return `${head}${propertyContents}${headClose}${children}${tail}`
|
||||
}
|
27
node_modules/loupe/lib/map.js
generated
vendored
Normal file
27
node_modules/loupe/lib/map.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
import { inspectList } from './helpers'
|
||||
|
||||
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}`
|
||||
}
|
||||
|
||||
// IE11 doesn't support `map.entries()`
|
||||
function mapToEntries(map) {
|
||||
const entries = []
|
||||
map.forEach((value, key) => {
|
||||
entries.push([key, value])
|
||||
})
|
||||
return entries
|
||||
}
|
||||
|
||||
export default function inspectMap(map, options) {
|
||||
const size = map.size - 1
|
||||
if (size <= 0) {
|
||||
return 'Map{}'
|
||||
}
|
||||
options.truncate -= 7
|
||||
return `Map{ ${inspectList(mapToEntries(map), options, inspectMapEntry)} }`
|
||||
}
|
18
node_modules/loupe/lib/number.js
generated
vendored
Normal file
18
node_modules/loupe/lib/number.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
import { truncate } from './helpers'
|
||||
|
||||
const isNaN = Number.isNaN || (i => i !== i) // eslint-disable-line no-self-compare
|
||||
export default 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(number, options.truncate), 'number')
|
||||
}
|
31
node_modules/loupe/lib/object.js
generated
vendored
Normal file
31
node_modules/loupe/lib/object.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
import { inspectProperty, inspectList } from './helpers'
|
||||
|
||||
export default function inspectObject(object, options) {
|
||||
const properties = Object.getOwnPropertyNames(object)
|
||||
const 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)
|
||||
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} }`
|
||||
}
|
16
node_modules/loupe/lib/promise.js
generated
vendored
Normal file
16
node_modules/loupe/lib/promise.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
let getPromiseValue = () => 'Promise{…}'
|
||||
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) {
|
||||
/* ignore */
|
||||
}
|
||||
export default getPromiseValue
|
8
node_modules/loupe/lib/regexp.js
generated
vendored
Normal file
8
node_modules/loupe/lib/regexp.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
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')
|
||||
}
|
16
node_modules/loupe/lib/set.js
generated
vendored
Normal file
16
node_modules/loupe/lib/set.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import { inspectList } from './helpers'
|
||||
|
||||
// IE11 doesn't support `Array.from(set)`
|
||||
function arrayFromSet(set) {
|
||||
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)} }`
|
||||
}
|
29
node_modules/loupe/lib/string.js
generated
vendored
Normal file
29
node_modules/loupe/lib/string.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
import { truncate } from './helpers'
|
||||
|
||||
const stringEscapeChars = new RegExp(
|
||||
"['\\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',
|
||||
"'": "\\'",
|
||||
'\\': '\\\\',
|
||||
}
|
||||
const hex = 16
|
||||
const unicodeLength = 4
|
||||
function escape(char) {
|
||||
return escapeCharacters[char] || `\\u${`0000${char.charCodeAt(0).toString(hex)}`.slice(-unicodeLength)}`
|
||||
}
|
||||
|
||||
export default function inspectString(string, options) {
|
||||
if (stringEscapeChars.test(string)) {
|
||||
string = string.replace(stringEscapeChars, escape)
|
||||
}
|
||||
return options.stylize(`'${truncate(string, options.truncate - 2)}'`, 'string')
|
||||
}
|
6
node_modules/loupe/lib/symbol.js
generated
vendored
Normal file
6
node_modules/loupe/lib/symbol.js
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
export default function inspectSymbol(value) {
|
||||
if ('description' in Symbol.prototype) {
|
||||
return value.description ? `Symbol(${value.description})` : 'Symbol()'
|
||||
}
|
||||
return value.toString()
|
||||
}
|
45
node_modules/loupe/lib/typedarray.js
generated
vendored
Normal file
45
node_modules/loupe/lib/typedarray.js
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
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'
|
||||
}
|
||||
if (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 = ''
|
||||
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
|
||||
}
|
||||
output += string
|
||||
}
|
||||
let propertyContents = ''
|
||||
if (nonIndexProperties.length) {
|
||||
propertyContents = inspectList(
|
||||
nonIndexProperties.map(key => [key, array[key]]),
|
||||
options,
|
||||
inspectProperty
|
||||
)
|
||||
}
|
||||
return `${name}[ ${output}${propertyContents ? `, ${propertyContents}` : ''} ]`
|
||||
}
|
Reference in New Issue
Block a user