Comparing version 6.5.1 to 6.6.0
@@ -1,3 +0,2 @@ | ||
import type { ColumnUserConfig } from './types/api'; | ||
declare const _default: (subject: string, containerWidth: number, alignment: ColumnUserConfig['alignment']) => string; | ||
import type { Alignment } from './types/api'; | ||
/** | ||
@@ -7,2 +6,2 @@ * Pads a string to the left and/or right to position the subject | ||
*/ | ||
export default _default; | ||
export declare const alignString: (subject: string, containerWidth: number, alignment: Alignment) => string; |
@@ -6,3 +6,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.alignString = void 0; | ||
const string_width_1 = __importDefault(require("string-width")); | ||
const utils_1 = require("./utils"); | ||
const alignLeft = (subject, width) => { | ||
@@ -25,2 +27,16 @@ return subject + ' '.repeat(width); | ||
}; | ||
const alignJustify = (subject, width) => { | ||
const spaceSequenceCount = utils_1.countSpaceSequence(subject); | ||
if (spaceSequenceCount === 0) { | ||
return alignLeft(subject, width); | ||
} | ||
const addingSpaces = utils_1.distributeUnevenly(width, spaceSequenceCount); | ||
if (Math.max(...addingSpaces) > 3) { | ||
return alignLeft(subject, width); | ||
} | ||
let spaceSequenceIndex = 0; | ||
return subject.replace(/\s+/g, (groupSpace) => { | ||
return groupSpace + ' '.repeat(addingSpaces[spaceSequenceIndex++]); | ||
}); | ||
}; | ||
/** | ||
@@ -30,6 +46,3 @@ * Pads a string to the left and/or right to position the subject | ||
*/ | ||
exports.default = (subject, containerWidth, alignment) => { | ||
if (typeof subject !== 'string') { | ||
throw new TypeError('Subject parameter value must be a string.'); | ||
} | ||
const alignString = (subject, containerWidth, alignment) => { | ||
const subjectWidth = string_width_1.default(subject); | ||
@@ -49,3 +62,7 @@ if (subjectWidth > containerWidth) { | ||
} | ||
if (alignment === 'justify') { | ||
return alignJustify(subject, availableWidth); | ||
} | ||
return alignCenter(subject, availableWidth); | ||
}; | ||
exports.alignString = alignString; |
import type { BaseConfig, Row } from './types/internal'; | ||
declare const _default: (rows: Row[], config: BaseConfig) => Row[]; | ||
export default _default; | ||
export declare const alignTableData: (rows: Row[], config: BaseConfig) => Row[]; |
@@ -6,8 +6,9 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.alignTableData = void 0; | ||
const string_width_1 = __importDefault(require("string-width")); | ||
const alignString_1 = __importDefault(require("./alignString")); | ||
exports.default = (rows, config) => { | ||
const alignString_1 = require("./alignString"); | ||
const alignTableData = (rows, config) => { | ||
return rows.map((row) => { | ||
return row.map((cell, index) => { | ||
const column = config.columns[index]; | ||
return row.map((cell, cellIndex) => { | ||
const column = config.columns[cellIndex]; | ||
if (string_width_1.default(cell) === column.width) { | ||
@@ -17,3 +18,3 @@ return cell; | ||
else { | ||
return alignString_1.default(cell, column.width, column.alignment); | ||
return alignString_1.alignString(cell, column.width, column.alignment); | ||
} | ||
@@ -23,1 +24,2 @@ }); | ||
}; | ||
exports.alignTableData = alignTableData; |
@@ -1,2 +0,4 @@ | ||
declare const _default: (value: string, columnWidth: number, useWrapWord?: boolean) => number; | ||
export default _default; | ||
/** | ||
* Calculates height of cell content in regard to its width and word wrapping. | ||
*/ | ||
export declare const calculateCellHeight: (value: string, columnWidth: number, useWrapWord?: boolean) => number; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const wrapCell_1 = __importDefault(require("./wrapCell")); | ||
exports.default = (value, columnWidth, useWrapWord = false) => { | ||
if (typeof value !== 'string') { | ||
throw new TypeError('Value must be a string.'); | ||
} | ||
return wrapCell_1.default(value, columnWidth, useWrapWord).length; | ||
exports.calculateCellHeight = void 0; | ||
const wrapCell_1 = require("./wrapCell"); | ||
/** | ||
* Calculates height of cell content in regard to its width and word wrapping. | ||
*/ | ||
const calculateCellHeight = (value, columnWidth, useWrapWord = false) => { | ||
return wrapCell_1.wrapCell(value, columnWidth, useWrapWord).length; | ||
}; | ||
exports.calculateCellHeight = calculateCellHeight; |
import type { StreamUserConfig, WritableStream } from './types/api'; | ||
declare const _default: (userConfig: StreamUserConfig) => WritableStream; | ||
export default _default; | ||
export declare const createStream: (userConfig: StreamUserConfig) => WritableStream; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const alignTableData_1 = __importDefault(require("./alignTableData")); | ||
const calculateRowHeightIndex_1 = __importDefault(require("./calculateRowHeightIndex")); | ||
exports.createStream = void 0; | ||
const alignTableData_1 = require("./alignTableData"); | ||
const calculateRowHeights_1 = require("./calculateRowHeights"); | ||
const drawBorder_1 = require("./drawBorder"); | ||
const drawRow_1 = __importDefault(require("./drawRow")); | ||
const makeStreamConfig_1 = __importDefault(require("./makeStreamConfig")); | ||
const mapDataUsingRowHeightIndex_1 = __importDefault(require("./mapDataUsingRowHeightIndex")); | ||
const padTableData_1 = __importDefault(require("./padTableData")); | ||
const stringifyTableData_1 = __importDefault(require("./stringifyTableData")); | ||
const truncateTableData_1 = __importDefault(require("./truncateTableData")); | ||
const drawRow_1 = require("./drawRow"); | ||
const makeStreamConfig_1 = require("./makeStreamConfig"); | ||
const mapDataUsingRowHeights_1 = require("./mapDataUsingRowHeights"); | ||
const padTableData_1 = require("./padTableData"); | ||
const stringifyTableData_1 = require("./stringifyTableData"); | ||
const truncateTableData_1 = require("./truncateTableData"); | ||
const prepareData = (data, config) => { | ||
let rows = stringifyTableData_1.default(data); | ||
rows = truncateTableData_1.default(rows, config); | ||
const rowHeightIndex = calculateRowHeightIndex_1.default(rows, config); | ||
rows = mapDataUsingRowHeightIndex_1.default(rows, rowHeightIndex, config); | ||
rows = alignTableData_1.default(rows, config); | ||
rows = padTableData_1.default(rows, config); | ||
let rows = stringifyTableData_1.stringifyTableData(data); | ||
rows = truncateTableData_1.truncateTableData(rows, config); | ||
const rowHeights = calculateRowHeights_1.calculateRowHeights(rows, config); | ||
rows = mapDataUsingRowHeights_1.mapDataUsingRowHeights(rows, rowHeights, config); | ||
rows = alignTableData_1.alignTableData(rows, config); | ||
rows = padTableData_1.padTableData(rows, config); | ||
return rows; | ||
}; | ||
const create = (row, columnWidthIndex, config) => { | ||
const create = (row, columnWidths, config) => { | ||
const rows = prepareData([row], config); | ||
const body = rows.map((literalRow) => { | ||
return drawRow_1.default(literalRow, config); | ||
return drawRow_1.drawRow(literalRow, config); | ||
}).join(''); | ||
let output; | ||
output = ''; | ||
output += drawBorder_1.drawBorderTop(columnWidthIndex, config); | ||
output += drawBorder_1.drawBorderTop(columnWidths, config); | ||
output += body; | ||
output += drawBorder_1.drawBorderBottom(columnWidthIndex, config); | ||
output += drawBorder_1.drawBorderBottom(columnWidths, config); | ||
output = output.trimEnd(); | ||
process.stdout.write(output); | ||
}; | ||
const append = (row, columnWidthIndex, config) => { | ||
const append = (row, columnWidths, config) => { | ||
const rows = prepareData([row], config); | ||
const body = rows.map((literalRow) => { | ||
return drawRow_1.default(literalRow, config); | ||
return drawRow_1.drawRow(literalRow, config); | ||
}).join(''); | ||
let output = ''; | ||
const bottom = drawBorder_1.drawBorderBottom(columnWidthIndex, config); | ||
const bottom = drawBorder_1.drawBorderBottom(columnWidths, config); | ||
if (bottom !== '\n') { | ||
output = '\r\u001B[K'; | ||
} | ||
output += drawBorder_1.drawBorderJoin(columnWidthIndex, config); | ||
output += drawBorder_1.drawBorderJoin(columnWidths, config); | ||
output += body; | ||
@@ -53,5 +51,5 @@ output += bottom; | ||
}; | ||
exports.default = (userConfig) => { | ||
const config = makeStreamConfig_1.default(userConfig); | ||
const columnWidthIndex = Object.values(config.columns).map((column) => { | ||
const createStream = (userConfig) => { | ||
const config = makeStreamConfig_1.makeStreamConfig(userConfig); | ||
const columnWidths = Object.values(config.columns).map((column) => { | ||
return column.width + column.paddingLeft + column.paddingRight; | ||
@@ -67,6 +65,6 @@ }); | ||
empty = false; | ||
create(row, columnWidthIndex, config); | ||
create(row, columnWidths, config); | ||
} | ||
else { | ||
append(row, columnWidthIndex, config); | ||
append(row, columnWidths, config); | ||
} | ||
@@ -76,1 +74,2 @@ }, | ||
}; | ||
exports.createStream = createStream; |
@@ -9,15 +9,15 @@ import type { DrawVerticalLine } from './types/api'; | ||
}; | ||
declare const drawBorder: (columnSizeIndex: number[], config: { | ||
declare const drawBorder: (columnWidths: number[], config: { | ||
separator: Separator; | ||
drawVerticalLine: DrawVerticalLine; | ||
}) => string; | ||
declare const drawBorderTop: (columnSizeIndex: number[], config: { | ||
declare const drawBorderTop: (columnWidths: number[], config: { | ||
border: TopBorderConfig; | ||
drawVerticalLine: DrawVerticalLine; | ||
}) => string; | ||
declare const drawBorderJoin: (columnSizeIndex: number[], config: { | ||
declare const drawBorderJoin: (columnWidths: number[], config: { | ||
border: JoinBorderConfig; | ||
drawVerticalLine: DrawVerticalLine; | ||
}) => string; | ||
declare const drawBorderBottom: (columnSizeIndex: number[], config: { | ||
declare const drawBorderBottom: (columnWidths: number[], config: { | ||
border: BottomBorderConfig; | ||
@@ -24,0 +24,0 @@ drawVerticalLine: DrawVerticalLine; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.drawBorderTop = exports.drawBorderJoin = exports.drawBorderBottom = exports.drawBorder = void 0; | ||
const drawHorizontalContent_1 = __importDefault(require("./drawHorizontalContent")); | ||
const drawBorder = (columnSizeIndex, config) => { | ||
const columns = columnSizeIndex.map((size) => { | ||
const drawContent_1 = require("./drawContent"); | ||
const drawBorder = (columnWidths, config) => { | ||
const { separator, drawVerticalLine } = config; | ||
const columns = columnWidths.map((size) => { | ||
return config.separator.body.repeat(size); | ||
}); | ||
return drawHorizontalContent_1.default(columns, config); | ||
return drawContent_1.drawContent(columns, { | ||
drawSeparator: drawVerticalLine, | ||
endSeparator: separator.right, | ||
middleSeparator: separator.join, | ||
startSeparator: separator.left, | ||
}) + '\n'; | ||
}; | ||
exports.drawBorder = drawBorder; | ||
const drawBorderTop = (columnSizeIndex, config) => { | ||
const result = drawBorder(columnSizeIndex, { | ||
const drawBorderTop = (columnWidths, config) => { | ||
const result = drawBorder(columnWidths, { | ||
...config, | ||
@@ -31,4 +34,4 @@ separator: { | ||
exports.drawBorderTop = drawBorderTop; | ||
const drawBorderJoin = (columnSizeIndex, config) => { | ||
return drawBorder(columnSizeIndex, { | ||
const drawBorderJoin = (columnWidths, config) => { | ||
return drawBorder(columnWidths, { | ||
...config, | ||
@@ -44,4 +47,4 @@ separator: { | ||
exports.drawBorderJoin = drawBorderJoin; | ||
const drawBorderBottom = (columnSizeIndex, config) => { | ||
return drawBorder(columnSizeIndex, { | ||
const drawBorderBottom = (columnWidths, config) => { | ||
return drawBorder(columnWidths, { | ||
...config, | ||
@@ -48,0 +51,0 @@ separator: { |
import type { DrawVerticalLine } from './types/api'; | ||
import type { BodyBorderConfig, Row } from './types/internal'; | ||
declare const _default: (row: Row, config: { | ||
export declare const drawRow: (row: Row, config: { | ||
border: BodyBorderConfig; | ||
drawVerticalLine: DrawVerticalLine; | ||
}) => string; | ||
export default _default; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const drawHorizontalContent_1 = __importDefault(require("./drawHorizontalContent")); | ||
exports.default = (row, config) => { | ||
return drawHorizontalContent_1.default(row, { | ||
...config, | ||
separator: { | ||
join: config.border.bodyJoin, | ||
left: config.border.bodyLeft, | ||
right: config.border.bodyRight, | ||
}, | ||
}); | ||
exports.drawRow = void 0; | ||
const drawContent_1 = require("./drawContent"); | ||
const drawRow = (row, config) => { | ||
const { border, drawVerticalLine } = config; | ||
return drawContent_1.drawContent(row, { | ||
drawSeparator: drawVerticalLine, | ||
endSeparator: border.bodyRight, | ||
middleSeparator: border.bodyJoin, | ||
startSeparator: border.bodyLeft, | ||
}) + '\n'; | ||
}; | ||
exports.drawRow = drawRow; |
import type { TableConfig, Row } from './types/internal'; | ||
declare const _default: (rows: Row[], columnWidths: number[], rowHeights: number[], config: TableConfig) => string; | ||
export default _default; | ||
export declare const drawTable: (rows: Row[], columnWidths: number[], rowHeights: number[], config: TableConfig) => string; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.drawTable = void 0; | ||
const drawBorder_1 = require("./drawBorder"); | ||
const drawRow_1 = __importDefault(require("./drawRow")); | ||
/** | ||
* Group the array into sub-arrays by sizes. | ||
* | ||
* @example | ||
* chunkBySizes(['a', 'b', 'c', 'd', 'e'], [2, 1, 2]) = [ ['a', 'b'], ['c'], ['d', 'e'] ] | ||
*/ | ||
const groupBySizes = (array, sizes) => { | ||
let startIndex = 0; | ||
return sizes.map((rowHeight) => { | ||
const chunk = array.slice(startIndex, startIndex + rowHeight); | ||
startIndex += rowHeight; | ||
return chunk; | ||
}); | ||
}; | ||
const shouldDrawBorderJoin = (rowIndex, rowCount, config) => { | ||
const { singleLine, drawHorizontalLine } = config; | ||
return !singleLine && rowIndex + 1 < rowCount && drawHorizontalLine(rowIndex + 1, rowCount); | ||
}; | ||
exports.default = (rows, columnWidths, rowHeights, config) => { | ||
const { drawHorizontalLine, } = config; | ||
const groupedRows = groupBySizes(rows, rowHeights).map((group) => { | ||
const drawContent_1 = require("./drawContent"); | ||
const drawRow_1 = require("./drawRow"); | ||
const utils_1 = require("./utils"); | ||
const drawTable = (rows, columnWidths, rowHeights, config) => { | ||
const { drawHorizontalLine, singleLine, } = config; | ||
const contents = utils_1.groupBySizes(rows, rowHeights).map((group) => { | ||
return group.map((row) => { | ||
return drawRow_1.default(row, config); | ||
return drawRow_1.drawRow(row, config); | ||
}).join(''); | ||
}); | ||
const rowCount = groupedRows.length; | ||
let output = ''; | ||
if (drawHorizontalLine(0, rowCount)) { | ||
output += drawBorder_1.drawBorderTop(columnWidths, config); | ||
} | ||
groupedRows.forEach((row, rowIndex) => { | ||
output += row; | ||
if (shouldDrawBorderJoin(rowIndex, rowCount, config)) { | ||
output += drawBorder_1.drawBorderJoin(columnWidths, config); | ||
} | ||
return drawContent_1.drawContent(contents, { | ||
drawSeparator: (index, size) => { | ||
// Top/bottom border | ||
if (index === 0 || index === size) { | ||
return drawHorizontalLine(index, size); | ||
} | ||
return !singleLine && drawHorizontalLine(index, size); | ||
}, | ||
endSeparator: drawBorder_1.drawBorderBottom(columnWidths, config), | ||
middleSeparator: drawBorder_1.drawBorderJoin(columnWidths, config), | ||
startSeparator: drawBorder_1.drawBorderTop(columnWidths, config), | ||
}); | ||
if (drawHorizontalLine(rowCount, rowCount)) { | ||
output += drawBorder_1.drawBorderBottom(columnWidths, config); | ||
} | ||
return output; | ||
}; | ||
exports.drawTable = drawTable; |
@@ -7,3 +7,3 @@ declare function validate43(data: any, { instancePath, parentData, parentDataProperty, rootData }?: { | ||
}): boolean; | ||
declare function validate70(data: any, { instancePath, parentData, parentDataProperty, rootData }?: { | ||
declare function validate73(data: any, { instancePath, parentData, parentDataProperty, rootData }?: { | ||
instancePath?: string | undefined; | ||
@@ -14,2 +14,2 @@ parentData: any; | ||
}): boolean; | ||
export { validate43 as _config_json, validate70 as _streamConfig_json }; | ||
export { validate43 as _config_json, validate73 as _streamConfig_json }; |
@@ -341,8 +341,6 @@ "use strict"; | ||
"type": "string", | ||
"enum": ["left", "right", "center"] | ||
"enum": ["left", "right", "center", "justify"] | ||
}, | ||
"width": { | ||
"type": "number", | ||
"minimum": 1, | ||
"multipleOf": 1 | ||
"$ref": "#/definitions/naturalNumber" | ||
}, | ||
@@ -365,2 +363,71 @@ "wrapWord": { | ||
const func0 = require("ajv/dist/runtime/equal").default; | ||
const schema19 = { | ||
"type": "number", | ||
"minimum": 1, | ||
"multipleOf": 1 | ||
}; | ||
function validate65(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) { | ||
let vErrors = null; | ||
let errors = 0; | ||
if ((typeof data == "number") && (isFinite(data))) { | ||
if (data < 1 || isNaN(data)) { | ||
const err0 = { | ||
instancePath, | ||
schemaPath: "#/minimum", | ||
keyword: "minimum", | ||
params: { | ||
comparison: ">=", | ||
limit: 1 | ||
}, | ||
message: "must be >= 1" | ||
}; | ||
if (vErrors === null) { | ||
vErrors = [err0]; | ||
} | ||
else { | ||
vErrors.push(err0); | ||
} | ||
errors++; | ||
} | ||
let res0; | ||
if ((1 === 0 || (res0 = data / 1, res0 !== parseInt(res0)))) { | ||
const err1 = { | ||
instancePath, | ||
schemaPath: "#/multipleOf", | ||
keyword: "multipleOf", | ||
params: { | ||
multipleOf: 1 | ||
}, | ||
message: "must be multiple of 1" | ||
}; | ||
if (vErrors === null) { | ||
vErrors = [err1]; | ||
} | ||
else { | ||
vErrors.push(err1); | ||
} | ||
errors++; | ||
} | ||
} | ||
else { | ||
const err2 = { | ||
instancePath, | ||
schemaPath: "#/type", | ||
keyword: "type", | ||
params: { | ||
type: "number" | ||
}, | ||
message: "must be number" | ||
}; | ||
if (vErrors === null) { | ||
vErrors = [err2]; | ||
} | ||
else { | ||
vErrors.push(err2); | ||
} | ||
errors++; | ||
} | ||
validate65.errors = vErrors; | ||
return errors === 0; | ||
} | ||
function validate64(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) { | ||
@@ -410,3 +477,3 @@ let vErrors = null; | ||
} | ||
if (!(((data0 === "left") || (data0 === "right")) || (data0 === "center"))) { | ||
if (!((((data0 === "left") || (data0 === "right")) || (data0 === "center")) || (data0 === "justify"))) { | ||
const err2 = { | ||
@@ -431,65 +498,15 @@ instancePath: instancePath + "/alignment", | ||
if (data.width !== undefined) { | ||
let data1 = data.width; | ||
if ((typeof data1 == "number") && (isFinite(data1))) { | ||
if (data1 < 1 || isNaN(data1)) { | ||
const err3 = { | ||
instancePath: instancePath + "/width", | ||
schemaPath: "#/properties/width/minimum", | ||
keyword: "minimum", | ||
params: { | ||
comparison: ">=", | ||
limit: 1 | ||
}, | ||
message: "must be >= 1" | ||
}; | ||
if (vErrors === null) { | ||
vErrors = [err3]; | ||
} | ||
else { | ||
vErrors.push(err3); | ||
} | ||
errors++; | ||
} | ||
let res0; | ||
if ((1 === 0 || (res0 = data1 / 1, res0 !== parseInt(res0)))) { | ||
const err4 = { | ||
instancePath: instancePath + "/width", | ||
schemaPath: "#/properties/width/multipleOf", | ||
keyword: "multipleOf", | ||
params: { | ||
multipleOf: 1 | ||
}, | ||
message: "must be multiple of 1" | ||
}; | ||
if (vErrors === null) { | ||
vErrors = [err4]; | ||
} | ||
else { | ||
vErrors.push(err4); | ||
} | ||
errors++; | ||
} | ||
if (!(validate65(data.width, { | ||
instancePath: instancePath + "/width", | ||
parentData: data, | ||
parentDataProperty: "width", | ||
rootData | ||
}))) { | ||
vErrors = vErrors === null ? validate65.errors : vErrors.concat(validate65.errors); | ||
errors = vErrors.length; | ||
} | ||
else { | ||
const err5 = { | ||
instancePath: instancePath + "/width", | ||
schemaPath: "#/properties/width/type", | ||
keyword: "type", | ||
params: { | ||
type: "number" | ||
}, | ||
message: "must be number" | ||
}; | ||
if (vErrors === null) { | ||
vErrors = [err5]; | ||
} | ||
else { | ||
vErrors.push(err5); | ||
} | ||
errors++; | ||
} | ||
} | ||
if (data.wrapWord !== undefined) { | ||
if (typeof data.wrapWord !== "boolean") { | ||
const err6 = { | ||
const err3 = { | ||
instancePath: instancePath + "/wrapWord", | ||
@@ -504,6 +521,6 @@ schemaPath: "#/properties/wrapWord/type", | ||
if (vErrors === null) { | ||
vErrors = [err6]; | ||
vErrors = [err3]; | ||
} | ||
else { | ||
vErrors.push(err6); | ||
vErrors.push(err3); | ||
} | ||
@@ -516,3 +533,3 @@ errors++; | ||
if (!((typeof data3 == "number") && (isFinite(data3)))) { | ||
const err7 = { | ||
const err4 = { | ||
instancePath: instancePath + "/truncate", | ||
@@ -527,6 +544,6 @@ schemaPath: "#/properties/truncate/type", | ||
if (vErrors === null) { | ||
vErrors = [err7]; | ||
vErrors = [err4]; | ||
} | ||
else { | ||
vErrors.push(err7); | ||
vErrors.push(err4); | ||
} | ||
@@ -539,3 +556,3 @@ errors++; | ||
if (!((typeof data4 == "number") && (isFinite(data4)))) { | ||
const err8 = { | ||
const err5 = { | ||
instancePath: instancePath + "/paddingLeft", | ||
@@ -550,6 +567,6 @@ schemaPath: "#/properties/paddingLeft/type", | ||
if (vErrors === null) { | ||
vErrors = [err8]; | ||
vErrors = [err5]; | ||
} | ||
else { | ||
vErrors.push(err8); | ||
vErrors.push(err5); | ||
} | ||
@@ -562,3 +579,3 @@ errors++; | ||
if (!((typeof data5 == "number") && (isFinite(data5)))) { | ||
const err9 = { | ||
const err6 = { | ||
instancePath: instancePath + "/paddingRight", | ||
@@ -573,6 +590,6 @@ schemaPath: "#/properties/paddingRight/type", | ||
if (vErrors === null) { | ||
vErrors = [err9]; | ||
vErrors = [err6]; | ||
} | ||
else { | ||
vErrors.push(err9); | ||
vErrors.push(err6); | ||
} | ||
@@ -584,3 +601,3 @@ errors++; | ||
else { | ||
const err10 = { | ||
const err7 = { | ||
instancePath, | ||
@@ -595,6 +612,6 @@ schemaPath: "#/type", | ||
if (vErrors === null) { | ||
vErrors = [err10]; | ||
vErrors = [err7]; | ||
} | ||
else { | ||
vErrors.push(err10); | ||
vErrors.push(err7); | ||
} | ||
@@ -747,3 +764,3 @@ errors++; | ||
} | ||
function validate68(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) { | ||
function validate70(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) { | ||
let vErrors = null; | ||
@@ -792,3 +809,3 @@ let errors = 0; | ||
} | ||
if (!(((data0 === "left") || (data0 === "right")) || (data0 === "center"))) { | ||
if (!((((data0 === "left") || (data0 === "right")) || (data0 === "center")) || (data0 === "justify"))) { | ||
const err2 = { | ||
@@ -813,65 +830,15 @@ instancePath: instancePath + "/alignment", | ||
if (data.width !== undefined) { | ||
let data1 = data.width; | ||
if ((typeof data1 == "number") && (isFinite(data1))) { | ||
if (data1 < 1 || isNaN(data1)) { | ||
const err3 = { | ||
instancePath: instancePath + "/width", | ||
schemaPath: "#/properties/width/minimum", | ||
keyword: "minimum", | ||
params: { | ||
comparison: ">=", | ||
limit: 1 | ||
}, | ||
message: "must be >= 1" | ||
}; | ||
if (vErrors === null) { | ||
vErrors = [err3]; | ||
} | ||
else { | ||
vErrors.push(err3); | ||
} | ||
errors++; | ||
} | ||
let res0; | ||
if ((1 === 0 || (res0 = data1 / 1, res0 !== parseInt(res0)))) { | ||
const err4 = { | ||
instancePath: instancePath + "/width", | ||
schemaPath: "#/properties/width/multipleOf", | ||
keyword: "multipleOf", | ||
params: { | ||
multipleOf: 1 | ||
}, | ||
message: "must be multiple of 1" | ||
}; | ||
if (vErrors === null) { | ||
vErrors = [err4]; | ||
} | ||
else { | ||
vErrors.push(err4); | ||
} | ||
errors++; | ||
} | ||
if (!(validate65(data.width, { | ||
instancePath: instancePath + "/width", | ||
parentData: data, | ||
parentDataProperty: "width", | ||
rootData | ||
}))) { | ||
vErrors = vErrors === null ? validate65.errors : vErrors.concat(validate65.errors); | ||
errors = vErrors.length; | ||
} | ||
else { | ||
const err5 = { | ||
instancePath: instancePath + "/width", | ||
schemaPath: "#/properties/width/type", | ||
keyword: "type", | ||
params: { | ||
type: "number" | ||
}, | ||
message: "must be number" | ||
}; | ||
if (vErrors === null) { | ||
vErrors = [err5]; | ||
} | ||
else { | ||
vErrors.push(err5); | ||
} | ||
errors++; | ||
} | ||
} | ||
if (data.wrapWord !== undefined) { | ||
if (typeof data.wrapWord !== "boolean") { | ||
const err6 = { | ||
const err3 = { | ||
instancePath: instancePath + "/wrapWord", | ||
@@ -886,6 +853,6 @@ schemaPath: "#/properties/wrapWord/type", | ||
if (vErrors === null) { | ||
vErrors = [err6]; | ||
vErrors = [err3]; | ||
} | ||
else { | ||
vErrors.push(err6); | ||
vErrors.push(err3); | ||
} | ||
@@ -898,3 +865,3 @@ errors++; | ||
if (!((typeof data3 == "number") && (isFinite(data3)))) { | ||
const err7 = { | ||
const err4 = { | ||
instancePath: instancePath + "/truncate", | ||
@@ -909,6 +876,6 @@ schemaPath: "#/properties/truncate/type", | ||
if (vErrors === null) { | ||
vErrors = [err7]; | ||
vErrors = [err4]; | ||
} | ||
else { | ||
vErrors.push(err7); | ||
vErrors.push(err4); | ||
} | ||
@@ -921,3 +888,3 @@ errors++; | ||
if (!((typeof data4 == "number") && (isFinite(data4)))) { | ||
const err8 = { | ||
const err5 = { | ||
instancePath: instancePath + "/paddingLeft", | ||
@@ -932,6 +899,6 @@ schemaPath: "#/properties/paddingLeft/type", | ||
if (vErrors === null) { | ||
vErrors = [err8]; | ||
vErrors = [err5]; | ||
} | ||
else { | ||
vErrors.push(err8); | ||
vErrors.push(err5); | ||
} | ||
@@ -944,3 +911,3 @@ errors++; | ||
if (!((typeof data5 == "number") && (isFinite(data5)))) { | ||
const err9 = { | ||
const err6 = { | ||
instancePath: instancePath + "/paddingRight", | ||
@@ -955,6 +922,6 @@ schemaPath: "#/properties/paddingRight/type", | ||
if (vErrors === null) { | ||
vErrors = [err9]; | ||
vErrors = [err6]; | ||
} | ||
else { | ||
vErrors.push(err9); | ||
vErrors.push(err6); | ||
} | ||
@@ -966,3 +933,3 @@ errors++; | ||
else { | ||
const err10 = { | ||
const err7 = { | ||
instancePath, | ||
@@ -977,10 +944,10 @@ schemaPath: "#/type", | ||
if (vErrors === null) { | ||
vErrors = [err10]; | ||
vErrors = [err7]; | ||
} | ||
else { | ||
vErrors.push(err10); | ||
vErrors.push(err7); | ||
} | ||
errors++; | ||
} | ||
validate68.errors = vErrors; | ||
validate70.errors = vErrors; | ||
return errors === 0; | ||
@@ -1036,3 +1003,3 @@ } | ||
if (data.columnDefault !== undefined) { | ||
if (!(validate68(data.columnDefault, { | ||
if (!(validate70(data.columnDefault, { | ||
instancePath: instancePath + "/columnDefault", | ||
@@ -1043,3 +1010,3 @@ parentData: data, | ||
}))) { | ||
vErrors = vErrors === null ? validate68.errors : vErrors.concat(validate68.errors); | ||
vErrors = vErrors === null ? validate70.errors : vErrors.concat(validate70.errors); | ||
errors = vErrors.length; | ||
@@ -1124,4 +1091,4 @@ } | ||
} | ||
exports["streamConfig.json"] = validate70; | ||
const schema20 = { | ||
exports["streamConfig.json"] = validate73; | ||
const schema21 = { | ||
"$id": "streamConfig.json", | ||
@@ -1141,3 +1108,3 @@ "$schema": "http://json-schema.org/draft-07/schema#", | ||
"columnCount": { | ||
"type": "number" | ||
"$ref": "shared.json#/definitions/naturalNumber" | ||
}, | ||
@@ -1148,5 +1115,6 @@ "drawVerticalLine": { | ||
}, | ||
"required": ["columnDefault", "columnCount"], | ||
"additionalProperties": false | ||
}; | ||
function validate71(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) { | ||
function validate74(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) { | ||
let vErrors = null; | ||
@@ -1359,6 +1327,6 @@ let errors = 0; | ||
} | ||
validate71.errors = vErrors; | ||
validate74.errors = vErrors; | ||
return errors === 0; | ||
} | ||
function validate88(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) { | ||
function validate91(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) { | ||
let vErrors = null; | ||
@@ -1501,6 +1469,6 @@ let errors = 0; | ||
} | ||
validate88.errors = vErrors; | ||
validate91.errors = vErrors; | ||
return errors === 0; | ||
} | ||
function validate92(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) { | ||
function validate95(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) { | ||
let vErrors = null; | ||
@@ -1549,3 +1517,3 @@ let errors = 0; | ||
} | ||
if (!(((data0 === "left") || (data0 === "right")) || (data0 === "center"))) { | ||
if (!((((data0 === "left") || (data0 === "right")) || (data0 === "center")) || (data0 === "justify"))) { | ||
const err2 = { | ||
@@ -1570,65 +1538,15 @@ instancePath: instancePath + "/alignment", | ||
if (data.width !== undefined) { | ||
let data1 = data.width; | ||
if ((typeof data1 == "number") && (isFinite(data1))) { | ||
if (data1 < 1 || isNaN(data1)) { | ||
const err3 = { | ||
instancePath: instancePath + "/width", | ||
schemaPath: "#/properties/width/minimum", | ||
keyword: "minimum", | ||
params: { | ||
comparison: ">=", | ||
limit: 1 | ||
}, | ||
message: "must be >= 1" | ||
}; | ||
if (vErrors === null) { | ||
vErrors = [err3]; | ||
} | ||
else { | ||
vErrors.push(err3); | ||
} | ||
errors++; | ||
} | ||
let res0; | ||
if ((1 === 0 || (res0 = data1 / 1, res0 !== parseInt(res0)))) { | ||
const err4 = { | ||
instancePath: instancePath + "/width", | ||
schemaPath: "#/properties/width/multipleOf", | ||
keyword: "multipleOf", | ||
params: { | ||
multipleOf: 1 | ||
}, | ||
message: "must be multiple of 1" | ||
}; | ||
if (vErrors === null) { | ||
vErrors = [err4]; | ||
} | ||
else { | ||
vErrors.push(err4); | ||
} | ||
errors++; | ||
} | ||
if (!(validate65(data.width, { | ||
instancePath: instancePath + "/width", | ||
parentData: data, | ||
parentDataProperty: "width", | ||
rootData | ||
}))) { | ||
vErrors = vErrors === null ? validate65.errors : vErrors.concat(validate65.errors); | ||
errors = vErrors.length; | ||
} | ||
else { | ||
const err5 = { | ||
instancePath: instancePath + "/width", | ||
schemaPath: "#/properties/width/type", | ||
keyword: "type", | ||
params: { | ||
type: "number" | ||
}, | ||
message: "must be number" | ||
}; | ||
if (vErrors === null) { | ||
vErrors = [err5]; | ||
} | ||
else { | ||
vErrors.push(err5); | ||
} | ||
errors++; | ||
} | ||
} | ||
if (data.wrapWord !== undefined) { | ||
if (typeof data.wrapWord !== "boolean") { | ||
const err6 = { | ||
const err3 = { | ||
instancePath: instancePath + "/wrapWord", | ||
@@ -1643,6 +1561,6 @@ schemaPath: "#/properties/wrapWord/type", | ||
if (vErrors === null) { | ||
vErrors = [err6]; | ||
vErrors = [err3]; | ||
} | ||
else { | ||
vErrors.push(err6); | ||
vErrors.push(err3); | ||
} | ||
@@ -1655,3 +1573,3 @@ errors++; | ||
if (!((typeof data3 == "number") && (isFinite(data3)))) { | ||
const err7 = { | ||
const err4 = { | ||
instancePath: instancePath + "/truncate", | ||
@@ -1666,6 +1584,6 @@ schemaPath: "#/properties/truncate/type", | ||
if (vErrors === null) { | ||
vErrors = [err7]; | ||
vErrors = [err4]; | ||
} | ||
else { | ||
vErrors.push(err7); | ||
vErrors.push(err4); | ||
} | ||
@@ -1678,3 +1596,3 @@ errors++; | ||
if (!((typeof data4 == "number") && (isFinite(data4)))) { | ||
const err8 = { | ||
const err5 = { | ||
instancePath: instancePath + "/paddingLeft", | ||
@@ -1689,6 +1607,6 @@ schemaPath: "#/properties/paddingLeft/type", | ||
if (vErrors === null) { | ||
vErrors = [err8]; | ||
vErrors = [err5]; | ||
} | ||
else { | ||
vErrors.push(err8); | ||
vErrors.push(err5); | ||
} | ||
@@ -1701,3 +1619,3 @@ errors++; | ||
if (!((typeof data5 == "number") && (isFinite(data5)))) { | ||
const err9 = { | ||
const err6 = { | ||
instancePath: instancePath + "/paddingRight", | ||
@@ -1712,6 +1630,6 @@ schemaPath: "#/properties/paddingRight/type", | ||
if (vErrors === null) { | ||
vErrors = [err9]; | ||
vErrors = [err6]; | ||
} | ||
else { | ||
vErrors.push(err9); | ||
vErrors.push(err6); | ||
} | ||
@@ -1723,3 +1641,3 @@ errors++; | ||
else { | ||
const err10 = { | ||
const err7 = { | ||
instancePath, | ||
@@ -1734,13 +1652,77 @@ schemaPath: "#/type", | ||
if (vErrors === null) { | ||
vErrors = [err10]; | ||
vErrors = [err7]; | ||
} | ||
else { | ||
vErrors.push(err10); | ||
vErrors.push(err7); | ||
} | ||
errors++; | ||
} | ||
validate92.errors = vErrors; | ||
validate95.errors = vErrors; | ||
return errors === 0; | ||
} | ||
function validate70(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) { | ||
function validate98(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) { | ||
let vErrors = null; | ||
let errors = 0; | ||
if ((typeof data == "number") && (isFinite(data))) { | ||
if (data < 1 || isNaN(data)) { | ||
const err0 = { | ||
instancePath, | ||
schemaPath: "#/minimum", | ||
keyword: "minimum", | ||
params: { | ||
comparison: ">=", | ||
limit: 1 | ||
}, | ||
message: "must be >= 1" | ||
}; | ||
if (vErrors === null) { | ||
vErrors = [err0]; | ||
} | ||
else { | ||
vErrors.push(err0); | ||
} | ||
errors++; | ||
} | ||
let res0; | ||
if ((1 === 0 || (res0 = data / 1, res0 !== parseInt(res0)))) { | ||
const err1 = { | ||
instancePath, | ||
schemaPath: "#/multipleOf", | ||
keyword: "multipleOf", | ||
params: { | ||
multipleOf: 1 | ||
}, | ||
message: "must be multiple of 1" | ||
}; | ||
if (vErrors === null) { | ||
vErrors = [err1]; | ||
} | ||
else { | ||
vErrors.push(err1); | ||
} | ||
errors++; | ||
} | ||
} | ||
else { | ||
const err2 = { | ||
instancePath, | ||
schemaPath: "#/type", | ||
keyword: "type", | ||
params: { | ||
type: "number" | ||
}, | ||
message: "must be number" | ||
}; | ||
if (vErrors === null) { | ||
vErrors = [err2]; | ||
} | ||
else { | ||
vErrors.push(err2); | ||
} | ||
errors++; | ||
} | ||
validate98.errors = vErrors; | ||
return errors === 0; | ||
} | ||
function validate73(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) { | ||
/*# sourceURL="streamConfig.json" */ ; | ||
@@ -1750,5 +1732,41 @@ let vErrors = null; | ||
if (data && typeof data == "object" && !Array.isArray(data)) { | ||
if (data.columnDefault === undefined) { | ||
const err0 = { | ||
instancePath, | ||
schemaPath: "#/required", | ||
keyword: "required", | ||
params: { | ||
missingProperty: "columnDefault" | ||
}, | ||
message: "must have required property '" + "columnDefault" + "'" | ||
}; | ||
if (vErrors === null) { | ||
vErrors = [err0]; | ||
} | ||
else { | ||
vErrors.push(err0); | ||
} | ||
errors++; | ||
} | ||
if (data.columnCount === undefined) { | ||
const err1 = { | ||
instancePath, | ||
schemaPath: "#/required", | ||
keyword: "required", | ||
params: { | ||
missingProperty: "columnCount" | ||
}, | ||
message: "must have required property '" + "columnCount" + "'" | ||
}; | ||
if (vErrors === null) { | ||
vErrors = [err1]; | ||
} | ||
else { | ||
vErrors.push(err1); | ||
} | ||
errors++; | ||
} | ||
for (const key0 in data) { | ||
if (!(((((key0 === "border") || (key0 === "columns")) || (key0 === "columnDefault")) || (key0 === "columnCount")) || (key0 === "drawVerticalLine"))) { | ||
const err0 = { | ||
const err2 = { | ||
instancePath, | ||
@@ -1763,6 +1781,6 @@ schemaPath: "#/additionalProperties", | ||
if (vErrors === null) { | ||
vErrors = [err0]; | ||
vErrors = [err2]; | ||
} | ||
else { | ||
vErrors.push(err0); | ||
vErrors.push(err2); | ||
} | ||
@@ -1773,3 +1791,3 @@ errors++; | ||
if (data.border !== undefined) { | ||
if (!(validate71(data.border, { | ||
if (!(validate74(data.border, { | ||
instancePath: instancePath + "/border", | ||
@@ -1780,3 +1798,3 @@ parentData: data, | ||
}))) { | ||
vErrors = vErrors === null ? validate71.errors : vErrors.concat(validate71.errors); | ||
vErrors = vErrors === null ? validate74.errors : vErrors.concat(validate74.errors); | ||
errors = vErrors.length; | ||
@@ -1786,3 +1804,3 @@ } | ||
if (data.columns !== undefined) { | ||
if (!(validate88(data.columns, { | ||
if (!(validate91(data.columns, { | ||
instancePath: instancePath + "/columns", | ||
@@ -1793,3 +1811,3 @@ parentData: data, | ||
}))) { | ||
vErrors = vErrors === null ? validate88.errors : vErrors.concat(validate88.errors); | ||
vErrors = vErrors === null ? validate91.errors : vErrors.concat(validate91.errors); | ||
errors = vErrors.length; | ||
@@ -1799,3 +1817,3 @@ } | ||
if (data.columnDefault !== undefined) { | ||
if (!(validate92(data.columnDefault, { | ||
if (!(validate95(data.columnDefault, { | ||
instancePath: instancePath + "/columnDefault", | ||
@@ -1806,3 +1824,3 @@ parentData: data, | ||
}))) { | ||
vErrors = vErrors === null ? validate92.errors : vErrors.concat(validate92.errors); | ||
vErrors = vErrors === null ? validate95.errors : vErrors.concat(validate95.errors); | ||
errors = vErrors.length; | ||
@@ -1812,20 +1830,10 @@ } | ||
if (data.columnCount !== undefined) { | ||
let data3 = data.columnCount; | ||
if (!((typeof data3 == "number") && (isFinite(data3)))) { | ||
const err1 = { | ||
instancePath: instancePath + "/columnCount", | ||
schemaPath: "#/properties/columnCount/type", | ||
keyword: "type", | ||
params: { | ||
type: "number" | ||
}, | ||
message: "must be number" | ||
}; | ||
if (vErrors === null) { | ||
vErrors = [err1]; | ||
} | ||
else { | ||
vErrors.push(err1); | ||
} | ||
errors++; | ||
if (!(validate98(data.columnCount, { | ||
instancePath: instancePath + "/columnCount", | ||
parentData: data, | ||
parentDataProperty: "columnCount", | ||
rootData | ||
}))) { | ||
vErrors = vErrors === null ? validate98.errors : vErrors.concat(validate98.errors); | ||
errors = vErrors.length; | ||
} | ||
@@ -1835,3 +1843,3 @@ } | ||
if (typeof data.drawVerticalLine != "function") { | ||
const err2 = { | ||
const err3 = { | ||
instancePath: instancePath + "/drawVerticalLine", | ||
@@ -1844,6 +1852,6 @@ schemaPath: "#/properties/drawVerticalLine/typeof", | ||
if (vErrors === null) { | ||
vErrors = [err2]; | ||
vErrors = [err3]; | ||
} | ||
else { | ||
vErrors.push(err2); | ||
vErrors.push(err3); | ||
} | ||
@@ -1855,3 +1863,3 @@ errors++; | ||
else { | ||
const err3 = { | ||
const err4 = { | ||
instancePath, | ||
@@ -1866,11 +1874,11 @@ schemaPath: "#/type", | ||
if (vErrors === null) { | ||
vErrors = [err3]; | ||
vErrors = [err4]; | ||
} | ||
else { | ||
vErrors.push(err3); | ||
vErrors.push(err4); | ||
} | ||
errors++; | ||
} | ||
validate70.errors = vErrors; | ||
validate73.errors = vErrors; | ||
return errors === 0; | ||
} |
import type { BorderConfig } from './types/api'; | ||
declare const _default: (name: string) => BorderConfig; | ||
export default _default; | ||
export declare const getBorderCharacters: (name: string) => BorderConfig; |
"use strict"; | ||
/* eslint-disable sort-keys-fix/sort-keys-fix */ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = (name) => { | ||
exports.getBorderCharacters = void 0; | ||
const getBorderCharacters = (name) => { | ||
if (name === 'honeywell') { | ||
@@ -83,1 +84,2 @@ return { | ||
}; | ||
exports.getBorderCharacters = getBorderCharacters; |
@@ -1,5 +0,5 @@ | ||
import createStream from './createStream'; | ||
import getBorderCharacters from './getBorderCharacters'; | ||
import table from './table'; | ||
import { createStream } from './createStream'; | ||
import { getBorderCharacters } from './getBorderCharacters'; | ||
import { table } from './table'; | ||
export { table, createStream, getBorderCharacters, }; | ||
export * from './types/api'; |
@@ -12,13 +12,10 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getBorderCharacters = exports.createStream = exports.table = void 0; | ||
const createStream_1 = __importDefault(require("./createStream")); | ||
exports.createStream = createStream_1.default; | ||
const getBorderCharacters_1 = __importDefault(require("./getBorderCharacters")); | ||
exports.getBorderCharacters = getBorderCharacters_1.default; | ||
const table_1 = __importDefault(require("./table")); | ||
exports.table = table_1.default; | ||
const createStream_1 = require("./createStream"); | ||
Object.defineProperty(exports, "createStream", { enumerable: true, get: function () { return createStream_1.createStream; } }); | ||
const getBorderCharacters_1 = require("./getBorderCharacters"); | ||
Object.defineProperty(exports, "getBorderCharacters", { enumerable: true, get: function () { return getBorderCharacters_1.getBorderCharacters; } }); | ||
const table_1 = require("./table"); | ||
Object.defineProperty(exports, "table", { enumerable: true, get: function () { return table_1.table; } }); | ||
__exportStar(require("./types/api"), exports); |
import type { TableUserConfig } from './types/api'; | ||
import type { Row, TableConfig } from './types/internal'; | ||
declare const _default: (rows: Row[], userConfig?: TableUserConfig) => TableConfig; | ||
/** | ||
@@ -8,2 +7,2 @@ * Makes a new configuration object out of the userConfig object | ||
*/ | ||
export default _default; | ||
export declare const makeConfig: (rows: Row[], userConfig?: TableUserConfig) => TableConfig; |
@@ -6,16 +6,8 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.makeConfig = void 0; | ||
const lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep")); | ||
const calculateMaximumColumnWidthIndex_1 = __importDefault(require("./calculateMaximumColumnWidthIndex")); | ||
const getBorderCharacters_1 = __importDefault(require("./getBorderCharacters")); | ||
const validateConfig_1 = __importDefault(require("./validateConfig")); | ||
const calculateColumnWidths_1 = __importDefault(require("./calculateColumnWidths")); | ||
const utils_1 = require("./utils"); | ||
const validateConfig_1 = require("./validateConfig"); | ||
/** | ||
* Merges user provided border characters with the default border ("honeywell") characters. | ||
*/ | ||
const makeBorder = (border) => { | ||
return { | ||
...getBorderCharacters_1.default('honeywell'), | ||
...border, | ||
}; | ||
}; | ||
/** | ||
* Creates a configuration for every column using default | ||
@@ -25,4 +17,4 @@ * values for the missing configuration properties. | ||
const makeColumns = (rows, columns, columnDefault) => { | ||
const maximumColumnWidthIndex = calculateMaximumColumnWidthIndex_1.default(rows); | ||
return rows[0].map((_cell, index) => { | ||
const columnWidths = calculateColumnWidths_1.default(rows); | ||
return rows[0].map((_, columnIndex) => { | ||
return { | ||
@@ -33,6 +25,6 @@ alignment: 'left', | ||
truncate: Number.POSITIVE_INFINITY, | ||
width: maximumColumnWidthIndex[index], | ||
width: columnWidths[columnIndex], | ||
wrapWord: false, | ||
...columnDefault, | ||
...columns === null || columns === void 0 ? void 0 : columns[index], | ||
...columns === null || columns === void 0 ? void 0 : columns[columnIndex], | ||
}; | ||
@@ -45,9 +37,9 @@ }); | ||
*/ | ||
exports.default = (rows, userConfig = {}) => { | ||
const makeConfig = (rows, userConfig = {}) => { | ||
var _a, _b, _c; | ||
validateConfig_1.default('config.json', userConfig); | ||
validateConfig_1.validateConfig('config.json', userConfig); | ||
const config = lodash_clonedeep_1.default(userConfig); | ||
return { | ||
...config, | ||
border: makeBorder(config.border), | ||
border: utils_1.makeBorder(config.border), | ||
columns: makeColumns(rows, config.columns, config.columnDefault), | ||
@@ -63,1 +55,2 @@ drawHorizontalLine: (_a = config.drawHorizontalLine) !== null && _a !== void 0 ? _a : (() => { | ||
}; | ||
exports.makeConfig = makeConfig; |
import type { StreamUserConfig } from './types/api'; | ||
import type { StreamConfig } from './types/internal'; | ||
declare const _default: (userConfig: StreamUserConfig) => StreamConfig; | ||
/** | ||
@@ -8,2 +7,2 @@ * Makes a new configuration object out of the userConfig object | ||
*/ | ||
export default _default; | ||
export declare const makeStreamConfig: (userConfig: StreamUserConfig) => StreamConfig; |
@@ -6,16 +6,7 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.makeStreamConfig = void 0; | ||
const lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep")); | ||
const getBorderCharacters_1 = __importDefault(require("./getBorderCharacters")); | ||
const validateConfig_1 = __importDefault(require("./validateConfig")); | ||
const utils_1 = require("./utils"); | ||
const validateConfig_1 = require("./validateConfig"); | ||
/** | ||
* Merges user provided border characters with the default border ("honeywell") characters. | ||
* | ||
*/ | ||
const makeBorder = (border) => { | ||
return { | ||
...getBorderCharacters_1.default('honeywell'), | ||
...border, | ||
}; | ||
}; | ||
/** | ||
* Creates a configuration for every column using default | ||
@@ -41,15 +32,12 @@ * values for the missing configuration properties. | ||
*/ | ||
exports.default = (userConfig) => { | ||
const makeStreamConfig = (userConfig) => { | ||
var _a; | ||
validateConfig_1.default('streamConfig.json', userConfig); | ||
validateConfig_1.validateConfig('streamConfig.json', userConfig); | ||
const config = lodash_clonedeep_1.default(userConfig); | ||
if (!config.columnDefault || !config.columnDefault.width) { | ||
if (config.columnDefault.width === undefined) { | ||
throw new Error('Must provide config.columnDefault.width when creating a stream.'); | ||
} | ||
if (!config.columnCount) { | ||
throw new Error('Must provide config.columnCount.'); | ||
} | ||
return { | ||
...config, | ||
border: makeBorder(config.border), | ||
border: utils_1.makeBorder(config.border), | ||
columnCount: config.columnCount, | ||
@@ -62,1 +50,2 @@ columns: makeColumns(config.columnCount, config.columns, config.columnDefault), | ||
}; | ||
exports.makeStreamConfig = makeStreamConfig; |
import type { BaseConfig, Row } from './types/internal'; | ||
declare const _default: (rows: Row[], config: BaseConfig) => Row[]; | ||
export default _default; | ||
export declare const padTableData: (rows: Row[], config: BaseConfig) => Row[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = (rows, config) => { | ||
exports.padTableData = void 0; | ||
const padTableData = (rows, config) => { | ||
return rows.map((cells) => { | ||
return cells.map((value, index1) => { | ||
const column = config.columns[index1]; | ||
return ' '.repeat(column.paddingLeft) + value + ' '.repeat(column.paddingRight); | ||
return cells.map((cell, cellIndex) => { | ||
const column = config.columns[cellIndex]; | ||
return ' '.repeat(column.paddingLeft) + cell + ' '.repeat(column.paddingRight); | ||
}); | ||
}); | ||
}; | ||
exports.padTableData = padTableData; |
import type { Row } from './types/internal'; | ||
declare const _default: (rows: unknown[][]) => Row[]; | ||
export default _default; | ||
export declare const stringifyTableData: (rows: unknown[][]) => Row[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = (rows) => { | ||
exports.stringifyTableData = void 0; | ||
const utils_1 = require("./utils"); | ||
const stringifyTableData = (rows) => { | ||
return rows.map((cells) => { | ||
return cells.map(String); | ||
return cells.map((cell) => { | ||
return utils_1.normalizeString(String(cell)); | ||
}); | ||
}); | ||
}; | ||
exports.stringifyTableData = stringifyTableData; |
import type { TableUserConfig } from './types/api'; | ||
declare const _default: (data: unknown[][], userConfig?: TableUserConfig) => string; | ||
export default _default; | ||
export declare const table: (data: unknown[][], userConfig?: TableUserConfig) => string; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const alignTableData_1 = __importDefault(require("./alignTableData")); | ||
const calculateCellWidthIndex_1 = __importDefault(require("./calculateCellWidthIndex")); | ||
const calculateRowHeightIndex_1 = __importDefault(require("./calculateRowHeightIndex")); | ||
const drawTable_1 = __importDefault(require("./drawTable")); | ||
const makeConfig_1 = __importDefault(require("./makeConfig")); | ||
const mapDataUsingRowHeightIndex_1 = __importDefault(require("./mapDataUsingRowHeightIndex")); | ||
const padTableData_1 = __importDefault(require("./padTableData")); | ||
const stringifyTableData_1 = __importDefault(require("./stringifyTableData")); | ||
const truncateTableData_1 = __importDefault(require("./truncateTableData")); | ||
const validateTableData_1 = __importDefault(require("./validateTableData")); | ||
exports.default = (data, userConfig = {}) => { | ||
validateTableData_1.default(data); | ||
let rows = stringifyTableData_1.default(data); | ||
const config = makeConfig_1.default(rows, userConfig); | ||
rows = truncateTableData_1.default(rows, config); | ||
const rowHeightIndex = calculateRowHeightIndex_1.default(rows, config); | ||
rows = mapDataUsingRowHeightIndex_1.default(rows, rowHeightIndex, config); | ||
rows = alignTableData_1.default(rows, config); | ||
rows = padTableData_1.default(rows, config); | ||
const cellWidthIndex = calculateCellWidthIndex_1.default(rows[0]); | ||
return drawTable_1.default(rows, cellWidthIndex, rowHeightIndex, config); | ||
exports.table = void 0; | ||
const alignTableData_1 = require("./alignTableData"); | ||
const calculateCellWidths_1 = require("./calculateCellWidths"); | ||
const calculateRowHeights_1 = require("./calculateRowHeights"); | ||
const drawTable_1 = require("./drawTable"); | ||
const makeConfig_1 = require("./makeConfig"); | ||
const mapDataUsingRowHeights_1 = require("./mapDataUsingRowHeights"); | ||
const padTableData_1 = require("./padTableData"); | ||
const stringifyTableData_1 = require("./stringifyTableData"); | ||
const truncateTableData_1 = require("./truncateTableData"); | ||
const validateTableData_1 = require("./validateTableData"); | ||
const table = (data, userConfig = {}) => { | ||
validateTableData_1.validateTableData(data); | ||
let rows = stringifyTableData_1.stringifyTableData(data); | ||
const config = makeConfig_1.makeConfig(rows, userConfig); | ||
rows = truncateTableData_1.truncateTableData(rows, config); | ||
const rowHeights = calculateRowHeights_1.calculateRowHeights(rows, config); | ||
rows = mapDataUsingRowHeights_1.mapDataUsingRowHeights(rows, rowHeights, config); | ||
rows = alignTableData_1.alignTableData(rows, config); | ||
rows = padTableData_1.padTableData(rows, config); | ||
const cellWidths = calculateCellWidths_1.calculateCellWidths(rows[0]); | ||
return drawTable_1.drawTable(rows, cellWidths, rowHeights, config); | ||
}; | ||
exports.table = table; |
import type { BaseConfig, Row } from './types/internal'; | ||
declare const _default: (rows: Row[], config: BaseConfig) => Row[]; | ||
/** | ||
* @todo Make it work with ASCII content. | ||
*/ | ||
export default _default; | ||
export declare const truncateTableData: (rows: Row[], config: BaseConfig) => Row[]; |
@@ -6,2 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.truncateTableData = void 0; | ||
const lodash_truncate_1 = __importDefault(require("lodash.truncate")); | ||
@@ -11,7 +12,7 @@ /** | ||
*/ | ||
exports.default = (rows, config) => { | ||
const truncateTableData = (rows, config) => { | ||
return rows.map((cells) => { | ||
return cells.map((content, index) => { | ||
return lodash_truncate_1.default(content, { | ||
length: config.columns[index].truncate, | ||
return cells.map((cell, cellIndex) => { | ||
return lodash_truncate_1.default(cell, { | ||
length: config.columns[cellIndex].truncate, | ||
omission: '…', | ||
@@ -22,1 +23,2 @@ }); | ||
}; | ||
exports.truncateTableData = truncateTableData; |
@@ -22,2 +22,3 @@ export declare type DrawLinePredicate = (index: number, size: number) => boolean; | ||
export declare type BorderConfig = Required<BorderUserConfig>; | ||
export declare type Alignment = 'center' | 'justify' | 'left' | 'right'; | ||
export declare type ColumnUserConfig = { | ||
@@ -27,3 +28,3 @@ /** | ||
*/ | ||
readonly alignment?: 'center' | 'left' | 'right'; | ||
readonly alignment?: Alignment; | ||
/** | ||
@@ -30,0 +31,0 @@ * Column width (default: auto calculation based on the cell content) |
import type { TableUserConfig } from './types/api'; | ||
declare const _default: (schemaId: 'config.json' | 'streamConfig.json', config: TableUserConfig) => void; | ||
export default _default; | ||
export declare const validateConfig: (schemaId: 'config.json' | 'streamConfig.json', config: TableUserConfig) => void; |
@@ -6,4 +6,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.validateConfig = void 0; | ||
const validators_1 = __importDefault(require("./generated/validators")); | ||
exports.default = (schemaId, config) => { | ||
const validateConfig = (schemaId, config) => { | ||
const validate = validators_1.default[schemaId]; | ||
@@ -25,1 +26,2 @@ if (!validate(config) && validate.errors) { | ||
}; | ||
exports.validateConfig = validateConfig; |
@@ -1,2 +0,1 @@ | ||
declare const _default: (rows: unknown[][]) => void; | ||
export default _default; | ||
export declare const validateTableData: (rows: unknown[][]) => void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = (rows) => { | ||
exports.validateTableData = void 0; | ||
const utils_1 = require("./utils"); | ||
const validateTableData = (rows) => { | ||
if (!Array.isArray(rows)) { | ||
@@ -23,3 +25,3 @@ throw new TypeError('Table data must be an array.'); | ||
// eslint-disable-next-line no-control-regex | ||
if (/[\u0001-\u0006\u0008\u0009\u000B-\u001A]/.test(cell)) { | ||
if (/[\u0001-\u0006\u0008\u0009\u000B-\u001A]/.test(utils_1.normalizeString(String(cell)))) { | ||
throw new Error('Table data must not contain control characters.'); | ||
@@ -30,1 +32,2 @@ } | ||
}; | ||
exports.validateTableData = validateTableData; |
@@ -1,2 +0,1 @@ | ||
declare const _default: (cellValue: string, columnWidth: number, useWrapWord: boolean) => string[]; | ||
/** | ||
@@ -9,2 +8,2 @@ * Wrap a single cell value into a list of lines | ||
*/ | ||
export default _default; | ||
export declare const wrapCell: (cellValue: string, cellWidth: number, useWrapWord: boolean) => string[]; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const slice_ansi_1 = __importDefault(require("slice-ansi")); | ||
const strip_ansi_1 = __importDefault(require("strip-ansi")); | ||
const wrapString_1 = __importDefault(require("./wrapString")); | ||
const wrapWord_1 = __importDefault(require("./wrapWord")); | ||
const splitAnsi = (input) => { | ||
const lengths = strip_ansi_1.default(input).split('\n').map(({ length }) => { | ||
return length; | ||
}); | ||
const result = []; | ||
let startIndex = 0; | ||
lengths.forEach((length) => { | ||
result.push(length === 0 ? '' : slice_ansi_1.default(input, startIndex, startIndex + length)); | ||
// Plus 1 for the newline character itself | ||
startIndex += length + 1; | ||
}); | ||
return result; | ||
}; | ||
exports.wrapCell = void 0; | ||
const utils_1 = require("./utils"); | ||
const wrapString_1 = require("./wrapString"); | ||
const wrapWord_1 = require("./wrapWord"); | ||
/** | ||
@@ -30,5 +14,5 @@ * Wrap a single cell value into a list of lines | ||
*/ | ||
exports.default = (cellValue, columnWidth, useWrapWord) => { | ||
const wrapCell = (cellValue, cellWidth, useWrapWord) => { | ||
// First split on literal newlines | ||
const cellLines = splitAnsi(cellValue); | ||
const cellLines = utils_1.splitAnsi(cellValue); | ||
// Then iterate over the list and word-wrap every remaining line if necessary. | ||
@@ -38,6 +22,6 @@ for (let lineNr = 0; lineNr < cellLines.length;) { | ||
if (useWrapWord) { | ||
lineChunks = wrapWord_1.default(cellLines[lineNr], columnWidth); | ||
lineChunks = wrapWord_1.wrapWord(cellLines[lineNr], cellWidth); | ||
} | ||
else { | ||
lineChunks = wrapString_1.default(cellLines[lineNr], columnWidth); | ||
lineChunks = wrapString_1.wrapString(cellLines[lineNr], cellWidth); | ||
} | ||
@@ -50,1 +34,2 @@ // Replace our original array element with whatever the wrapping returned | ||
}; | ||
exports.wrapCell = wrapCell; |
@@ -1,2 +0,1 @@ | ||
declare const _default: (subject: string, size: number) => string[]; | ||
/** | ||
@@ -10,2 +9,2 @@ * Creates an array of strings split into groups the length of size. | ||
*/ | ||
export default _default; | ||
export declare const wrapString: (subject: string, size: number) => string[]; |
@@ -6,2 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.wrapString = void 0; | ||
const slice_ansi_1 = __importDefault(require("slice-ansi")); | ||
@@ -17,3 +18,3 @@ const string_width_1 = __importDefault(require("string-width")); | ||
*/ | ||
exports.default = (subject, size) => { | ||
const wrapString = (subject, size) => { | ||
let subjectSlice = subject; | ||
@@ -27,1 +28,2 @@ const chunks = []; | ||
}; | ||
exports.wrapString = wrapString; |
@@ -1,2 +0,1 @@ | ||
declare const _default: (input: string, size: number) => string[]; | ||
export default _default; | ||
export declare const wrapWord: (input: string, size: number) => string[]; |
@@ -6,2 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.wrapWord = void 0; | ||
const slice_ansi_1 = __importDefault(require("slice-ansi")); | ||
@@ -32,3 +33,3 @@ const strip_ansi_1 = __importDefault(require("strip-ansi")); | ||
}; | ||
exports.default = (input, size) => { | ||
const wrapWord = (input, size) => { | ||
const result = []; | ||
@@ -42,1 +43,2 @@ let startIndex = 0; | ||
}; | ||
exports.wrapWord = wrapWord; |
@@ -94,3 +94,3 @@ { | ||
}, | ||
"version": "6.5.1" | ||
"version": "6.6.0" | ||
} |
@@ -158,3 +158,3 @@ <a name="table"></a> | ||
Valid values are: "left", "right" and "center". | ||
Valid values are: "left", "right", "center" and "justify". | ||
@@ -167,22 +167,17 @@ ```js | ||
data = [ | ||
['0A', '0B', '0C'], | ||
['1A', '1B', '1C'], | ||
['2A', '2B', '2C'] | ||
['0A', '0B', '0C', '0D 0E 0F'], | ||
['1A', '1B', '1C', '1D 1E 1F'], | ||
['2A', '2B', '2C', '2D 2E 2F'], | ||
]; | ||
config = { | ||
columns: { | ||
0: { | ||
alignment: 'left', | ||
width: 10 | ||
}, | ||
1: { | ||
alignment: 'center', | ||
width: 10 | ||
}, | ||
2: { | ||
alignment: 'right', | ||
width: 10 | ||
} | ||
} | ||
columnDefault: { | ||
width: 10, | ||
}, | ||
columns: [ | ||
{alignment: 'left'}, | ||
{alignment: 'center'}, | ||
{alignment: 'right'}, | ||
{alignment: 'justify'}, | ||
], | ||
}; | ||
@@ -196,9 +191,9 @@ | ||
``` | ||
╔════════════╤════════════╤════════════╗ | ||
║ 0A │ 0B │ 0C ║ | ||
╟────────────┼────────────┼────────────╢ | ||
║ 1A │ 1B │ 1C ║ | ||
╟────────────┼────────────┼────────────╢ | ||
║ 2A │ 2B │ 2C ║ | ||
╚════════════╧════════════╧════════════╝ | ||
╔════════════╤════════════╤════════════╤════════════╗ | ||
║ 0A │ 0B │ 0C │ 0D 0E 0F ║ | ||
╟────────────┼────────────┼────────────┼────────────╢ | ||
║ 1A │ 1B │ 1C │ 1D 1E 1F ║ | ||
╟────────────┼────────────┼────────────┼────────────╢ | ||
║ 2A │ 2B │ 2C │ 2D 2E 2F ║ | ||
╚════════════╧════════════╧════════════╧════════════╝ | ||
``` | ||
@@ -205,0 +200,0 @@ |
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
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
127735
61
2972
782