MCPcopy Create free account
hub / github.com/breck7/scroll / _toTable

Method _toTable

external/.scrollLibs.js:16412–16436  ·  view source on GitHub ↗
(maxCharactersPerColumn, alignRight = false)

Source from the content-addressed store, hash-verified

16410 return this._toTable(maxCharactersPerColumn, alignRight)
16411 }
16412 _toTable(maxCharactersPerColumn, alignRight = false) {
16413 const header = this._getUnionNames()
16414 // Set initial column widths
16415 const widths = header.map(col => (col.length > maxCharactersPerColumn ? maxCharactersPerColumn : col.length))
16416 // Expand column widths if needed
16417 this.forEach(particle => {
16418 if (!particle.length) return true
16419 header.forEach((col, index) => {
16420 const atomValue = particle.get(col)
16421 if (!atomValue) return true
16422 const length = atomValue.toString().length
16423 if (length > widths[index]) widths[index] = length > maxCharactersPerColumn ? maxCharactersPerColumn : length
16424 })
16425 })
16426 const atomFn = (atomText, row, col) => {
16427 const width = widths[col]
16428 // Strip newlines in fixedWidth output
16429 const atomValue = atomText.toString().replace(/\n/g, "\\n")
16430 const atomLength = atomValue.length
16431 if (atomLength > width) return atomValue.substr(0, width) + "..."
16432 const padding = " ".repeat(width - atomLength)
16433 return alignRight ? padding + atomValue : atomValue + padding
16434 }
16435 return this._toDelimited(" ", header, atomFn)
16436 }
16437 get asSsv() {
16438 return this.toDelimited(" ")
16439 }

Callers 2

asTableMethod · 0.95
toFormattedTableMethod · 0.95

Calls 6

_getUnionNamesMethod · 0.95
forEachMethod · 0.95
_toDelimitedMethod · 0.95
mapMethod · 0.80
getMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected