|
'use strict'; |
|
|
|
Object.defineProperty(exports, '__esModule', { |
|
value: true |
|
}); |
|
exports.printIteratorEntries = printIteratorEntries; |
|
exports.printIteratorValues = printIteratorValues; |
|
exports.printListItems = printListItems; |
|
exports.printObjectProperties = printObjectProperties; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const getKeysOfEnumerableProperties = (object, compareKeys) => { |
|
const rawKeys = Object.keys(object); |
|
const keys = compareKeys !== null ? rawKeys.sort(compareKeys) : rawKeys; |
|
if (Object.getOwnPropertySymbols) { |
|
Object.getOwnPropertySymbols(object).forEach(symbol => { |
|
if (Object.getOwnPropertyDescriptor(object, symbol).enumerable) { |
|
keys.push(symbol); |
|
} |
|
}); |
|
} |
|
return keys; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
function printIteratorEntries( |
|
iterator, |
|
config, |
|
indentation, |
|
depth, |
|
refs, |
|
printer, |
|
|
|
|
|
|
|
separator = ': ' |
|
) { |
|
let result = ''; |
|
let width = 0; |
|
let current = iterator.next(); |
|
if (!current.done) { |
|
result += config.spacingOuter; |
|
const indentationNext = indentation + config.indent; |
|
while (!current.done) { |
|
result += indentationNext; |
|
if (width++ === config.maxWidth) { |
|
result += '…'; |
|
break; |
|
} |
|
const name = printer( |
|
current.value[0], |
|
config, |
|
indentationNext, |
|
depth, |
|
refs |
|
); |
|
const value = printer( |
|
current.value[1], |
|
config, |
|
indentationNext, |
|
depth, |
|
refs |
|
); |
|
result += name + separator + value; |
|
current = iterator.next(); |
|
if (!current.done) { |
|
result += `,${config.spacingInner}`; |
|
} else if (!config.min) { |
|
result += ','; |
|
} |
|
} |
|
result += config.spacingOuter + indentation; |
|
} |
|
return result; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
function printIteratorValues( |
|
iterator, |
|
config, |
|
indentation, |
|
depth, |
|
refs, |
|
printer |
|
) { |
|
let result = ''; |
|
let width = 0; |
|
let current = iterator.next(); |
|
if (!current.done) { |
|
result += config.spacingOuter; |
|
const indentationNext = indentation + config.indent; |
|
while (!current.done) { |
|
result += indentationNext; |
|
if (width++ === config.maxWidth) { |
|
result += '…'; |
|
break; |
|
} |
|
result += printer(current.value, config, indentationNext, depth, refs); |
|
current = iterator.next(); |
|
if (!current.done) { |
|
result += `,${config.spacingInner}`; |
|
} else if (!config.min) { |
|
result += ','; |
|
} |
|
} |
|
result += config.spacingOuter + indentation; |
|
} |
|
return result; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
function printListItems(list, config, indentation, depth, refs, printer) { |
|
let result = ''; |
|
if (list.length) { |
|
result += config.spacingOuter; |
|
const indentationNext = indentation + config.indent; |
|
for (let i = 0; i < list.length; i++) { |
|
result += indentationNext; |
|
if (i === config.maxWidth) { |
|
result += '…'; |
|
break; |
|
} |
|
if (i in list) { |
|
result += printer(list[i], config, indentationNext, depth, refs); |
|
} |
|
if (i < list.length - 1) { |
|
result += `,${config.spacingInner}`; |
|
} else if (!config.min) { |
|
result += ','; |
|
} |
|
} |
|
result += config.spacingOuter + indentation; |
|
} |
|
return result; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
function printObjectProperties(val, config, indentation, depth, refs, printer) { |
|
let result = ''; |
|
const keys = getKeysOfEnumerableProperties(val, config.compareKeys); |
|
if (keys.length) { |
|
result += config.spacingOuter; |
|
const indentationNext = indentation + config.indent; |
|
for (let i = 0; i < keys.length; i++) { |
|
const key = keys[i]; |
|
const name = printer(key, config, indentationNext, depth, refs); |
|
const value = printer(val[key], config, indentationNext, depth, refs); |
|
result += `${indentationNext + name}: ${value}`; |
|
if (i < keys.length - 1) { |
|
result += `,${config.spacingInner}`; |
|
} else if (!config.min) { |
|
result += ','; |
|
} |
|
} |
|
result += config.spacingOuter + indentation; |
|
} |
|
return result; |
|
} |
|
|