(maxCharactersPerColumn, alignRight = false)
| 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 | } |
no test coverage detected