Fix EsLint Brackets (error markup 'const').
This commit is contained in:
+106
@@ -0,0 +1,106 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _lodash = _interopRequireDefault(require("lodash"));
|
||||
|
||||
var _stringWidth = _interopRequireDefault(require("string-width"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
const alignments = ['left', 'right', 'center'];
|
||||
/**
|
||||
* @param {string} subject
|
||||
* @param {number} width
|
||||
* @returns {string}
|
||||
*/
|
||||
|
||||
const alignLeft = (subject, width) => {
|
||||
return subject + ' '.repeat(width);
|
||||
};
|
||||
/**
|
||||
* @param {string} subject
|
||||
* @param {number} width
|
||||
* @returns {string}
|
||||
*/
|
||||
|
||||
|
||||
const alignRight = (subject, width) => {
|
||||
return ' '.repeat(width) + subject;
|
||||
};
|
||||
/**
|
||||
* @param {string} subject
|
||||
* @param {number} width
|
||||
* @returns {string}
|
||||
*/
|
||||
|
||||
|
||||
const alignCenter = (subject, width) => {
|
||||
let halfWidth;
|
||||
halfWidth = width / 2;
|
||||
|
||||
if (halfWidth % 2 === 0) {
|
||||
return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth);
|
||||
} else {
|
||||
halfWidth = Math.floor(halfWidth);
|
||||
return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth + 1);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Pads a string to the left and/or right to position the subject
|
||||
* text in a desired alignment within a container.
|
||||
*
|
||||
* @param {string} subject
|
||||
* @param {number} containerWidth
|
||||
* @param {string} alignment One of the valid options (left, right, center).
|
||||
* @returns {string}
|
||||
*/
|
||||
|
||||
|
||||
const alignString = (subject, containerWidth, alignment) => {
|
||||
if (!_lodash.default.isString(subject)) {
|
||||
throw new TypeError('Subject parameter value must be a string.');
|
||||
}
|
||||
|
||||
if (!_lodash.default.isNumber(containerWidth)) {
|
||||
throw new TypeError('Container width parameter value must be a number.');
|
||||
}
|
||||
|
||||
const subjectWidth = (0, _stringWidth.default)(subject);
|
||||
|
||||
if (subjectWidth > containerWidth) {
|
||||
// console.log('subjectWidth', subjectWidth, 'containerWidth', containerWidth, 'subject', subject);
|
||||
throw new Error('Subject parameter value width cannot be greater than the container width.');
|
||||
}
|
||||
|
||||
if (!_lodash.default.isString(alignment)) {
|
||||
throw new TypeError('Alignment parameter value must be a string.');
|
||||
}
|
||||
|
||||
if (alignments.indexOf(alignment) === -1) {
|
||||
throw new Error('Alignment parameter value must be a known alignment parameter value (left, right, center).');
|
||||
}
|
||||
|
||||
if (subjectWidth === 0) {
|
||||
return ' '.repeat(containerWidth);
|
||||
}
|
||||
|
||||
const availableWidth = containerWidth - subjectWidth;
|
||||
|
||||
if (alignment === 'left') {
|
||||
return alignLeft(subject, availableWidth);
|
||||
}
|
||||
|
||||
if (alignment === 'right') {
|
||||
return alignRight(subject, availableWidth);
|
||||
}
|
||||
|
||||
return alignCenter(subject, availableWidth);
|
||||
};
|
||||
|
||||
var _default = alignString;
|
||||
exports.default = _default;
|
||||
//# sourceMappingURL=alignString.js.map
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
import _ from 'lodash';
|
||||
import stringWidth from 'string-width';
|
||||
|
||||
const alignments = [
|
||||
'left',
|
||||
'right',
|
||||
'center'
|
||||
];
|
||||
|
||||
/**
|
||||
* @param {string} subject
|
||||
* @param {number} width
|
||||
* @returns {string}
|
||||
*/
|
||||
const alignLeft = (subject, width) => {
|
||||
return subject + ' '.repeat(width);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} subject
|
||||
* @param {number} width
|
||||
* @returns {string}
|
||||
*/
|
||||
const alignRight = (subject, width) => {
|
||||
return ' '.repeat(width) + subject;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} subject
|
||||
* @param {number} width
|
||||
* @returns {string}
|
||||
*/
|
||||
const alignCenter = (subject, width) => {
|
||||
let halfWidth;
|
||||
|
||||
halfWidth = width / 2;
|
||||
|
||||
if (halfWidth % 2 === 0) {
|
||||
return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth);
|
||||
} else {
|
||||
halfWidth = Math.floor(halfWidth);
|
||||
|
||||
return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth + 1);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Pads a string to the left and/or right to position the subject
|
||||
* text in a desired alignment within a container.
|
||||
*
|
||||
* @param {string} subject
|
||||
* @param {number} containerWidth
|
||||
* @param {string} alignment One of the valid options (left, right, center).
|
||||
* @returns {string}
|
||||
*/
|
||||
export default (subject, containerWidth, alignment) => {
|
||||
if (!_.isString(subject)) {
|
||||
throw new TypeError('Subject parameter value must be a string.');
|
||||
}
|
||||
|
||||
if (!_.isNumber(containerWidth)) {
|
||||
throw new TypeError('Container width parameter value must be a number.');
|
||||
}
|
||||
|
||||
const subjectWidth = stringWidth(subject);
|
||||
|
||||
if (subjectWidth > containerWidth) {
|
||||
// console.log('subjectWidth', subjectWidth, 'containerWidth', containerWidth, 'subject', subject);
|
||||
|
||||
throw new Error('Subject parameter value width cannot be greater than the container width.');
|
||||
}
|
||||
|
||||
if (!_.isString(alignment)) {
|
||||
throw new TypeError('Alignment parameter value must be a string.');
|
||||
}
|
||||
|
||||
if (alignments.indexOf(alignment) === -1) {
|
||||
throw new Error('Alignment parameter value must be a known alignment parameter value (left, right, center).');
|
||||
}
|
||||
|
||||
if (subjectWidth === 0) {
|
||||
return ' '.repeat(containerWidth);
|
||||
}
|
||||
|
||||
const availableWidth = containerWidth - subjectWidth;
|
||||
|
||||
if (alignment === 'left') {
|
||||
return alignLeft(subject, availableWidth);
|
||||
}
|
||||
|
||||
if (alignment === 'right') {
|
||||
return alignRight(subject, availableWidth);
|
||||
}
|
||||
|
||||
return alignCenter(subject, availableWidth);
|
||||
};
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../src/alignString.js"],"names":["alignments","alignLeft","subject","width","repeat","alignRight","alignCenter","halfWidth","Math","floor","containerWidth","alignment","_","isString","TypeError","isNumber","subjectWidth","Error","indexOf","availableWidth"],"mappings":";;;;;;;AAAA;;AACA;;;;AAEA,MAAMA,UAAU,GAAG,CACjB,MADiB,EAEjB,OAFiB,EAGjB,QAHiB,CAAnB;AAMA;;;;;;AAKA,MAAMC,SAAS,GAAG,CAACC,OAAD,EAAUC,KAAV,KAAoB;AACpC,SAAOD,OAAO,GAAG,IAAIE,MAAJ,CAAWD,KAAX,CAAjB;AACD,CAFD;AAIA;;;;;;;AAKA,MAAME,UAAU,GAAG,CAACH,OAAD,EAAUC,KAAV,KAAoB;AACrC,SAAO,IAAIC,MAAJ,CAAWD,KAAX,IAAoBD,OAA3B;AACD,CAFD;AAIA;;;;;;;AAKA,MAAMI,WAAW,GAAG,CAACJ,OAAD,EAAUC,KAAV,KAAoB;AACtC,MAAII,SAAJ;AAEAA,EAAAA,SAAS,GAAGJ,KAAK,GAAG,CAApB;;AAEA,MAAII,SAAS,GAAG,CAAZ,KAAkB,CAAtB,EAAyB;AACvB,WAAO,IAAIH,MAAJ,CAAWG,SAAX,IAAwBL,OAAxB,GAAkC,IAAIE,MAAJ,CAAWG,SAAX,CAAzC;AACD,GAFD,MAEO;AACLA,IAAAA,SAAS,GAAGC,IAAI,CAACC,KAAL,CAAWF,SAAX,CAAZ;AAEA,WAAO,IAAIH,MAAJ,CAAWG,SAAX,IAAwBL,OAAxB,GAAkC,IAAIE,MAAJ,CAAWG,SAAS,GAAG,CAAvB,CAAzC;AACD;AACF,CAZD;AAcA;;;;;;;;;;;qBASgBL,O,EAASQ,c,EAAgBC,S,KAAc;AACrD,MAAI,CAACC,gBAAEC,QAAF,CAAWX,OAAX,CAAL,EAA0B;AACxB,UAAM,IAAIY,SAAJ,CAAc,2CAAd,CAAN;AACD;;AAED,MAAI,CAACF,gBAAEG,QAAF,CAAWL,cAAX,CAAL,EAAiC;AAC/B,UAAM,IAAII,SAAJ,CAAc,mDAAd,CAAN;AACD;;AAED,QAAME,YAAY,GAAG,0BAAYd,OAAZ,CAArB;;AAEA,MAAIc,YAAY,GAAGN,cAAnB,EAAmC;AACjC;AAEA,UAAM,IAAIO,KAAJ,CAAU,2EAAV,CAAN;AACD;;AAED,MAAI,CAACL,gBAAEC,QAAF,CAAWF,SAAX,CAAL,EAA4B;AAC1B,UAAM,IAAIG,SAAJ,CAAc,6CAAd,CAAN;AACD;;AAED,MAAId,UAAU,CAACkB,OAAX,CAAmBP,SAAnB,MAAkC,CAAC,CAAvC,EAA0C;AACxC,UAAM,IAAIM,KAAJ,CAAU,4FAAV,CAAN;AACD;;AAED,MAAID,YAAY,KAAK,CAArB,EAAwB;AACtB,WAAO,IAAIZ,MAAJ,CAAWM,cAAX,CAAP;AACD;;AAED,QAAMS,cAAc,GAAGT,cAAc,GAAGM,YAAxC;;AAEA,MAAIL,SAAS,KAAK,MAAlB,EAA0B;AACxB,WAAOV,SAAS,CAACC,OAAD,EAAUiB,cAAV,CAAhB;AACD;;AAED,MAAIR,SAAS,KAAK,OAAlB,EAA2B;AACzB,WAAON,UAAU,CAACH,OAAD,EAAUiB,cAAV,CAAjB;AACD;;AAED,SAAOb,WAAW,CAACJ,OAAD,EAAUiB,cAAV,CAAlB;AACD,C","sourcesContent":["import _ from 'lodash';\nimport stringWidth from 'string-width';\n\nconst alignments = [\n 'left',\n 'right',\n 'center'\n];\n\n/**\n * @param {string} subject\n * @param {number} width\n * @returns {string}\n */\nconst alignLeft = (subject, width) => {\n return subject + ' '.repeat(width);\n};\n\n/**\n * @param {string} subject\n * @param {number} width\n * @returns {string}\n */\nconst alignRight = (subject, width) => {\n return ' '.repeat(width) + subject;\n};\n\n/**\n * @param {string} subject\n * @param {number} width\n * @returns {string}\n */\nconst alignCenter = (subject, width) => {\n let halfWidth;\n\n halfWidth = width / 2;\n\n if (halfWidth % 2 === 0) {\n return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth);\n } else {\n halfWidth = Math.floor(halfWidth);\n\n return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth + 1);\n }\n};\n\n/**\n * Pads a string to the left and/or right to position the subject\n * text in a desired alignment within a container.\n *\n * @param {string} subject\n * @param {number} containerWidth\n * @param {string} alignment One of the valid options (left, right, center).\n * @returns {string}\n */\nexport default (subject, containerWidth, alignment) => {\n if (!_.isString(subject)) {\n throw new TypeError('Subject parameter value must be a string.');\n }\n\n if (!_.isNumber(containerWidth)) {\n throw new TypeError('Container width parameter value must be a number.');\n }\n\n const subjectWidth = stringWidth(subject);\n\n if (subjectWidth > containerWidth) {\n // console.log('subjectWidth', subjectWidth, 'containerWidth', containerWidth, 'subject', subject);\n\n throw new Error('Subject parameter value width cannot be greater than the container width.');\n }\n\n if (!_.isString(alignment)) {\n throw new TypeError('Alignment parameter value must be a string.');\n }\n\n if (alignments.indexOf(alignment) === -1) {\n throw new Error('Alignment parameter value must be a known alignment parameter value (left, right, center).');\n }\n\n if (subjectWidth === 0) {\n return ' '.repeat(containerWidth);\n }\n\n const availableWidth = containerWidth - subjectWidth;\n\n if (alignment === 'left') {\n return alignLeft(subject, availableWidth);\n }\n\n if (alignment === 'right') {\n return alignRight(subject, availableWidth);\n }\n\n return alignCenter(subject, availableWidth);\n};\n"],"file":"alignString.js"}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _stringWidth = _interopRequireDefault(require("string-width"));
|
||||
|
||||
var _alignString = _interopRequireDefault(require("./alignString"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @param {table~row[]} rows
|
||||
* @param {Object} config
|
||||
* @returns {table~row[]}
|
||||
*/
|
||||
const alignTableData = (rows, config) => {
|
||||
return rows.map(cells => {
|
||||
return cells.map((value, index1) => {
|
||||
const column = config.columns[index1];
|
||||
|
||||
if ((0, _stringWidth.default)(value) === column.width) {
|
||||
return value;
|
||||
} else {
|
||||
return (0, _alignString.default)(value, column.width, column.alignment);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
var _default = alignTableData;
|
||||
exports.default = _default;
|
||||
//# sourceMappingURL=alignTableData.js.map
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
import stringWidth from 'string-width';
|
||||
import alignString from './alignString';
|
||||
|
||||
/**
|
||||
* @param {table~row[]} rows
|
||||
* @param {Object} config
|
||||
* @returns {table~row[]}
|
||||
*/
|
||||
export default (rows, config) => {
|
||||
return rows.map((cells) => {
|
||||
return cells.map((value, index1) => {
|
||||
const column = config.columns[index1];
|
||||
|
||||
if (stringWidth(value) === column.width) {
|
||||
return value;
|
||||
} else {
|
||||
return alignString(value, column.width, column.alignment);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../src/alignTableData.js"],"names":["rows","config","map","cells","value","index1","column","columns","width","alignment"],"mappings":";;;;;;;AAAA;;AACA;;;;AAEA;;;;;wBAKgBA,I,EAAMC,M,KAAW;AAC/B,SAAOD,IAAI,CAACE,GAAL,CAAUC,KAAD,IAAW;AACzB,WAAOA,KAAK,CAACD,GAAN,CAAU,CAACE,KAAD,EAAQC,MAAR,KAAmB;AAClC,YAAMC,MAAM,GAAGL,MAAM,CAACM,OAAP,CAAeF,MAAf,CAAf;;AAEA,UAAI,0BAAYD,KAAZ,MAAuBE,MAAM,CAACE,KAAlC,EAAyC;AACvC,eAAOJ,KAAP;AACD,OAFD,MAEO;AACL,eAAO,0BAAYA,KAAZ,EAAmBE,MAAM,CAACE,KAA1B,EAAiCF,MAAM,CAACG,SAAxC,CAAP;AACD;AACF,KARM,CAAP;AASD,GAVM,CAAP;AAWD,C","sourcesContent":["import stringWidth from 'string-width';\nimport alignString from './alignString';\n\n/**\n * @param {table~row[]} rows\n * @param {Object} config\n * @returns {table~row[]}\n */\nexport default (rows, config) => {\n return rows.map((cells) => {\n return cells.map((value, index1) => {\n const column = config.columns[index1];\n\n if (stringWidth(value) === column.width) {\n return value;\n } else {\n return alignString(value, column.width, column.alignment);\n }\n });\n });\n};\n"],"file":"alignTableData.js"}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _lodash = _interopRequireDefault(require("lodash"));
|
||||
|
||||
var _stringWidth = _interopRequireDefault(require("string-width"));
|
||||
|
||||
var _wrapWord = _interopRequireDefault(require("./wrapWord"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @param {string} value
|
||||
* @param {number} columnWidth
|
||||
* @param {boolean} useWrapWord
|
||||
* @returns {number}
|
||||
*/
|
||||
const calculateCellHeight = (value, columnWidth, useWrapWord = false) => {
|
||||
if (!_lodash.default.isString(value)) {
|
||||
throw new TypeError('Value must be a string.');
|
||||
}
|
||||
|
||||
if (!Number.isInteger(columnWidth)) {
|
||||
throw new TypeError('Column width must be an integer.');
|
||||
}
|
||||
|
||||
if (columnWidth < 1) {
|
||||
throw new Error('Column width must be greater than 0.');
|
||||
}
|
||||
|
||||
if (useWrapWord) {
|
||||
return (0, _wrapWord.default)(value, columnWidth).length;
|
||||
}
|
||||
|
||||
return Math.ceil((0, _stringWidth.default)(value) / columnWidth);
|
||||
};
|
||||
|
||||
var _default = calculateCellHeight;
|
||||
exports.default = _default;
|
||||
//# sourceMappingURL=calculateCellHeight.js.map
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
import _ from 'lodash';
|
||||
import stringWidth from 'string-width';
|
||||
import wrapWord from './wrapWord';
|
||||
|
||||
/**
|
||||
* @param {string} value
|
||||
* @param {number} columnWidth
|
||||
* @param {boolean} useWrapWord
|
||||
* @returns {number}
|
||||
*/
|
||||
export default (value, columnWidth, useWrapWord = false) => {
|
||||
if (!_.isString(value)) {
|
||||
throw new TypeError('Value must be a string.');
|
||||
}
|
||||
|
||||
if (!Number.isInteger(columnWidth)) {
|
||||
throw new TypeError('Column width must be an integer.');
|
||||
}
|
||||
|
||||
if (columnWidth < 1) {
|
||||
throw new Error('Column width must be greater than 0.');
|
||||
}
|
||||
|
||||
if (useWrapWord) {
|
||||
return wrapWord(value, columnWidth).length;
|
||||
}
|
||||
|
||||
return Math.ceil(stringWidth(value) / columnWidth);
|
||||
};
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../src/calculateCellHeight.js"],"names":["value","columnWidth","useWrapWord","_","isString","TypeError","Number","isInteger","Error","length","Math","ceil"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;AAEA;;;;;;6BAMgBA,K,EAAOC,W,EAAaC,WAAW,GAAG,K,KAAU;AAC1D,MAAI,CAACC,gBAAEC,QAAF,CAAWJ,KAAX,CAAL,EAAwB;AACtB,UAAM,IAAIK,SAAJ,CAAc,yBAAd,CAAN;AACD;;AAED,MAAI,CAACC,MAAM,CAACC,SAAP,CAAiBN,WAAjB,CAAL,EAAoC;AAClC,UAAM,IAAII,SAAJ,CAAc,kCAAd,CAAN;AACD;;AAED,MAAIJ,WAAW,GAAG,CAAlB,EAAqB;AACnB,UAAM,IAAIO,KAAJ,CAAU,sCAAV,CAAN;AACD;;AAED,MAAIN,WAAJ,EAAiB;AACf,WAAO,uBAASF,KAAT,EAAgBC,WAAhB,EAA6BQ,MAApC;AACD;;AAED,SAAOC,IAAI,CAACC,IAAL,CAAU,0BAAYX,KAAZ,IAAqBC,WAA/B,CAAP;AACD,C","sourcesContent":["import _ from 'lodash';\nimport stringWidth from 'string-width';\nimport wrapWord from './wrapWord';\n\n/**\n * @param {string} value\n * @param {number} columnWidth\n * @param {boolean} useWrapWord\n * @returns {number}\n */\nexport default (value, columnWidth, useWrapWord = false) => {\n if (!_.isString(value)) {\n throw new TypeError('Value must be a string.');\n }\n\n if (!Number.isInteger(columnWidth)) {\n throw new TypeError('Column width must be an integer.');\n }\n\n if (columnWidth < 1) {\n throw new Error('Column width must be greater than 0.');\n }\n\n if (useWrapWord) {\n return wrapWord(value, columnWidth).length;\n }\n\n return Math.ceil(stringWidth(value) / columnWidth);\n};\n"],"file":"calculateCellHeight.js"}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _stringWidth = _interopRequireDefault(require("string-width"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* Calculates width of each cell contents.
|
||||
*
|
||||
* @param {string[]} cells
|
||||
* @returns {number[]}
|
||||
*/
|
||||
const calculateCellWidthIndex = cells => {
|
||||
return cells.map(value => {
|
||||
return (0, _stringWidth.default)(value);
|
||||
});
|
||||
};
|
||||
|
||||
var _default = calculateCellWidthIndex;
|
||||
exports.default = _default;
|
||||
//# sourceMappingURL=calculateCellWidthIndex.js.map
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import stringWidth from 'string-width';
|
||||
|
||||
/**
|
||||
* Calculates width of each cell contents.
|
||||
*
|
||||
* @param {string[]} cells
|
||||
* @returns {number[]}
|
||||
*/
|
||||
export default (cells) => {
|
||||
return cells.map((value) => {
|
||||
return stringWidth(value);
|
||||
});
|
||||
};
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../src/calculateCellWidthIndex.js"],"names":["cells","map","value"],"mappings":";;;;;;;AAAA;;;;AAEA;;;;;;gCAMgBA,K,IAAU;AACxB,SAAOA,KAAK,CAACC,GAAN,CAAWC,KAAD,IAAW;AAC1B,WAAO,0BAAYA,KAAZ,CAAP;AACD,GAFM,CAAP;AAGD,C","sourcesContent":["import stringWidth from 'string-width';\n\n/**\n * Calculates width of each cell contents.\n *\n * @param {string[]} cells\n * @returns {number[]}\n */\nexport default (cells) => {\n return cells.map((value) => {\n return stringWidth(value);\n });\n};\n"],"file":"calculateCellWidthIndex.js"}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _calculateCellWidthIndex = _interopRequireDefault(require("./calculateCellWidthIndex"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* Produces an array of values that describe the largest value length (width) in every column.
|
||||
*
|
||||
* @param {Array[]} rows
|
||||
* @returns {number[]}
|
||||
*/
|
||||
const calculateMaximumColumnWidthIndex = rows => {
|
||||
if (!rows[0]) {
|
||||
throw new Error('Dataset must have at least one row.');
|
||||
}
|
||||
|
||||
const columns = new Array(rows[0].length).fill(0);
|
||||
rows.forEach(row => {
|
||||
const columnWidthIndex = (0, _calculateCellWidthIndex.default)(row);
|
||||
columnWidthIndex.forEach((valueWidth, index0) => {
|
||||
if (columns[index0] < valueWidth) {
|
||||
columns[index0] = valueWidth;
|
||||
}
|
||||
});
|
||||
});
|
||||
return columns;
|
||||
};
|
||||
|
||||
var _default = calculateMaximumColumnWidthIndex;
|
||||
exports.default = _default;
|
||||
//# sourceMappingURL=calculateMaximumColumnWidthIndex.js.map
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
import calculateCellWidthIndex from './calculateCellWidthIndex';
|
||||
|
||||
/**
|
||||
* Produces an array of values that describe the largest value length (width) in every column.
|
||||
*
|
||||
* @param {Array[]} rows
|
||||
* @returns {number[]}
|
||||
*/
|
||||
export default (rows) => {
|
||||
if (!rows[0]) {
|
||||
throw new Error('Dataset must have at least one row.');
|
||||
}
|
||||
|
||||
const columns = new Array(rows[0].length).fill(0);
|
||||
|
||||
rows.forEach((row) => {
|
||||
const columnWidthIndex = calculateCellWidthIndex(row);
|
||||
|
||||
columnWidthIndex.forEach((valueWidth, index0) => {
|
||||
if (columns[index0] < valueWidth) {
|
||||
columns[index0] = valueWidth;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return columns;
|
||||
};
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../src/calculateMaximumColumnWidthIndex.js"],"names":["rows","Error","columns","Array","length","fill","forEach","row","columnWidthIndex","valueWidth","index0"],"mappings":";;;;;;;AAAA;;;;AAEA;;;;;;yCAMgBA,I,IAAS;AACvB,MAAI,CAACA,IAAI,CAAC,CAAD,CAAT,EAAc;AACZ,UAAM,IAAIC,KAAJ,CAAU,qCAAV,CAAN;AACD;;AAED,QAAMC,OAAO,GAAG,IAAIC,KAAJ,CAAUH,IAAI,CAAC,CAAD,CAAJ,CAAQI,MAAlB,EAA0BC,IAA1B,CAA+B,CAA/B,CAAhB;AAEAL,EAAAA,IAAI,CAACM,OAAL,CAAcC,GAAD,IAAS;AACpB,UAAMC,gBAAgB,GAAG,sCAAwBD,GAAxB,CAAzB;AAEAC,IAAAA,gBAAgB,CAACF,OAAjB,CAAyB,CAACG,UAAD,EAAaC,MAAb,KAAwB;AAC/C,UAAIR,OAAO,CAACQ,MAAD,CAAP,GAAkBD,UAAtB,EAAkC;AAChCP,QAAAA,OAAO,CAACQ,MAAD,CAAP,GAAkBD,UAAlB;AACD;AACF,KAJD;AAKD,GARD;AAUA,SAAOP,OAAP;AACD,C","sourcesContent":["import calculateCellWidthIndex from './calculateCellWidthIndex';\n\n/**\n * Produces an array of values that describe the largest value length (width) in every column.\n *\n * @param {Array[]} rows\n * @returns {number[]}\n */\nexport default (rows) => {\n if (!rows[0]) {\n throw new Error('Dataset must have at least one row.');\n }\n\n const columns = new Array(rows[0].length).fill(0);\n\n rows.forEach((row) => {\n const columnWidthIndex = calculateCellWidthIndex(row);\n\n columnWidthIndex.forEach((valueWidth, index0) => {\n if (columns[index0] < valueWidth) {\n columns[index0] = valueWidth;\n }\n });\n });\n\n return columns;\n};\n"],"file":"calculateMaximumColumnWidthIndex.js"}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _lodash = _interopRequireDefault(require("lodash"));
|
||||
|
||||
var _calculateCellHeight = _interopRequireDefault(require("./calculateCellHeight"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* Calculates the vertical row span index.
|
||||
*
|
||||
* @param {Array[]} rows
|
||||
* @param {Object} config
|
||||
* @returns {number[]}
|
||||
*/
|
||||
const calculateRowHeightIndex = (rows, config) => {
|
||||
const tableWidth = rows[0].length;
|
||||
const rowSpanIndex = [];
|
||||
rows.forEach(cells => {
|
||||
const cellHeightIndex = new Array(tableWidth).fill(1);
|
||||
cells.forEach((value, index1) => {
|
||||
if (!_lodash.default.isNumber(config.columns[index1].width)) {
|
||||
throw new TypeError('column[index].width must be a number.');
|
||||
}
|
||||
|
||||
if (!_lodash.default.isBoolean(config.columns[index1].wrapWord)) {
|
||||
throw new TypeError('column[index].wrapWord must be a boolean.');
|
||||
}
|
||||
|
||||
cellHeightIndex[index1] = (0, _calculateCellHeight.default)(value, config.columns[index1].width, config.columns[index1].wrapWord);
|
||||
});
|
||||
rowSpanIndex.push(_lodash.default.max(cellHeightIndex));
|
||||
});
|
||||
return rowSpanIndex;
|
||||
};
|
||||
|
||||
var _default = calculateRowHeightIndex;
|
||||
exports.default = _default;
|
||||
//# sourceMappingURL=calculateRowHeightIndex.js.map
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
import _ from 'lodash';
|
||||
import calculateCellHeight from './calculateCellHeight';
|
||||
|
||||
/**
|
||||
* Calculates the vertical row span index.
|
||||
*
|
||||
* @param {Array[]} rows
|
||||
* @param {Object} config
|
||||
* @returns {number[]}
|
||||
*/
|
||||
export default (rows, config) => {
|
||||
const tableWidth = rows[0].length;
|
||||
|
||||
const rowSpanIndex = [];
|
||||
|
||||
rows.forEach((cells) => {
|
||||
const cellHeightIndex = new Array(tableWidth).fill(1);
|
||||
|
||||
cells.forEach((value, index1) => {
|
||||
if (!_.isNumber(config.columns[index1].width)) {
|
||||
throw new TypeError('column[index].width must be a number.');
|
||||
}
|
||||
|
||||
if (!_.isBoolean(config.columns[index1].wrapWord)) {
|
||||
throw new TypeError('column[index].wrapWord must be a boolean.');
|
||||
}
|
||||
|
||||
cellHeightIndex[index1] = calculateCellHeight(value, config.columns[index1].width, config.columns[index1].wrapWord);
|
||||
});
|
||||
|
||||
rowSpanIndex.push(_.max(cellHeightIndex));
|
||||
});
|
||||
|
||||
return rowSpanIndex;
|
||||
};
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../src/calculateRowHeightIndex.js"],"names":["rows","config","tableWidth","length","rowSpanIndex","forEach","cells","cellHeightIndex","Array","fill","value","index1","_","isNumber","columns","width","TypeError","isBoolean","wrapWord","push","max"],"mappings":";;;;;;;AAAA;;AACA;;;;AAEA;;;;;;;iCAOgBA,I,EAAMC,M,KAAW;AAC/B,QAAMC,UAAU,GAAGF,IAAI,CAAC,CAAD,CAAJ,CAAQG,MAA3B;AAEA,QAAMC,YAAY,GAAG,EAArB;AAEAJ,EAAAA,IAAI,CAACK,OAAL,CAAcC,KAAD,IAAW;AACtB,UAAMC,eAAe,GAAG,IAAIC,KAAJ,CAAUN,UAAV,EAAsBO,IAAtB,CAA2B,CAA3B,CAAxB;AAEAH,IAAAA,KAAK,CAACD,OAAN,CAAc,CAACK,KAAD,EAAQC,MAAR,KAAmB;AAC/B,UAAI,CAACC,gBAAEC,QAAF,CAAWZ,MAAM,CAACa,OAAP,CAAeH,MAAf,EAAuBI,KAAlC,CAAL,EAA+C;AAC7C,cAAM,IAAIC,SAAJ,CAAc,uCAAd,CAAN;AACD;;AAED,UAAI,CAACJ,gBAAEK,SAAF,CAAYhB,MAAM,CAACa,OAAP,CAAeH,MAAf,EAAuBO,QAAnC,CAAL,EAAmD;AACjD,cAAM,IAAIF,SAAJ,CAAc,2CAAd,CAAN;AACD;;AAEDT,MAAAA,eAAe,CAACI,MAAD,CAAf,GAA0B,kCAAoBD,KAApB,EAA2BT,MAAM,CAACa,OAAP,CAAeH,MAAf,EAAuBI,KAAlD,EAAyDd,MAAM,CAACa,OAAP,CAAeH,MAAf,EAAuBO,QAAhF,CAA1B;AACD,KAVD;AAYAd,IAAAA,YAAY,CAACe,IAAb,CAAkBP,gBAAEQ,GAAF,CAAMb,eAAN,CAAlB;AACD,GAhBD;AAkBA,SAAOH,YAAP;AACD,C","sourcesContent":["import _ from 'lodash';\nimport calculateCellHeight from './calculateCellHeight';\n\n/**\n * Calculates the vertical row span index.\n *\n * @param {Array[]} rows\n * @param {Object} config\n * @returns {number[]}\n */\nexport default (rows, config) => {\n const tableWidth = rows[0].length;\n\n const rowSpanIndex = [];\n\n rows.forEach((cells) => {\n const cellHeightIndex = new Array(tableWidth).fill(1);\n\n cells.forEach((value, index1) => {\n if (!_.isNumber(config.columns[index1].width)) {\n throw new TypeError('column[index].width must be a number.');\n }\n\n if (!_.isBoolean(config.columns[index1].wrapWord)) {\n throw new TypeError('column[index].wrapWord must be a boolean.');\n }\n\n cellHeightIndex[index1] = calculateCellHeight(value, config.columns[index1].width, config.columns[index1].wrapWord);\n });\n\n rowSpanIndex.push(_.max(cellHeightIndex));\n });\n\n return rowSpanIndex;\n};\n"],"file":"calculateRowHeightIndex.js"}
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _lodash = _interopRequireDefault(require("lodash"));
|
||||
|
||||
var _makeStreamConfig = _interopRequireDefault(require("./makeStreamConfig"));
|
||||
|
||||
var _drawRow = _interopRequireDefault(require("./drawRow"));
|
||||
|
||||
var _drawBorder = require("./drawBorder");
|
||||
|
||||
var _stringifyTableData = _interopRequireDefault(require("./stringifyTableData"));
|
||||
|
||||
var _truncateTableData = _interopRequireDefault(require("./truncateTableData"));
|
||||
|
||||
var _mapDataUsingRowHeightIndex = _interopRequireDefault(require("./mapDataUsingRowHeightIndex"));
|
||||
|
||||
var _alignTableData = _interopRequireDefault(require("./alignTableData"));
|
||||
|
||||
var _padTableData = _interopRequireDefault(require("./padTableData"));
|
||||
|
||||
var _calculateRowHeightIndex = _interopRequireDefault(require("./calculateRowHeightIndex"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @param {Array} data
|
||||
* @param {Object} config
|
||||
* @returns {Array}
|
||||
*/
|
||||
const prepareData = (data, config) => {
|
||||
let rows;
|
||||
rows = (0, _stringifyTableData.default)(data);
|
||||
rows = (0, _truncateTableData.default)(data, config);
|
||||
const rowHeightIndex = (0, _calculateRowHeightIndex.default)(rows, config);
|
||||
rows = (0, _mapDataUsingRowHeightIndex.default)(rows, rowHeightIndex, config);
|
||||
rows = (0, _alignTableData.default)(rows, config);
|
||||
rows = (0, _padTableData.default)(rows, config);
|
||||
return rows;
|
||||
};
|
||||
/**
|
||||
* @param {string[]} row
|
||||
* @param {number[]} columnWidthIndex
|
||||
* @param {Object} config
|
||||
* @returns {undefined}
|
||||
*/
|
||||
|
||||
|
||||
const create = (row, columnWidthIndex, config) => {
|
||||
const rows = prepareData([row], config);
|
||||
const body = rows.map(literalRow => {
|
||||
return (0, _drawRow.default)(literalRow, config.border);
|
||||
}).join('');
|
||||
let output;
|
||||
output = '';
|
||||
output += (0, _drawBorder.drawBorderTop)(columnWidthIndex, config.border);
|
||||
output += body;
|
||||
output += (0, _drawBorder.drawBorderBottom)(columnWidthIndex, config.border);
|
||||
output = _lodash.default.trimEnd(output);
|
||||
process.stdout.write(output);
|
||||
};
|
||||
/**
|
||||
* @param {string[]} row
|
||||
* @param {number[]} columnWidthIndex
|
||||
* @param {Object} config
|
||||
* @returns {undefined}
|
||||
*/
|
||||
|
||||
|
||||
const append = (row, columnWidthIndex, config) => {
|
||||
const rows = prepareData([row], config);
|
||||
const body = rows.map(literalRow => {
|
||||
return (0, _drawRow.default)(literalRow, config.border);
|
||||
}).join('');
|
||||
let output;
|
||||
output = '\r\u001B[K';
|
||||
output += (0, _drawBorder.drawBorderJoin)(columnWidthIndex, config.border);
|
||||
output += body;
|
||||
output += (0, _drawBorder.drawBorderBottom)(columnWidthIndex, config.border);
|
||||
output = _lodash.default.trimEnd(output);
|
||||
process.stdout.write(output);
|
||||
};
|
||||
/**
|
||||
* @param {Object} userConfig
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
|
||||
const createStream = (userConfig = {}) => {
|
||||
const config = (0, _makeStreamConfig.default)(userConfig); // @todo Use 'Object.values' when Node.js v6 support is dropped.
|
||||
|
||||
const columnWidthIndex = _lodash.default.values(_lodash.default.mapValues(config.columns, column => {
|
||||
return column.width + column.paddingLeft + column.paddingRight;
|
||||
}));
|
||||
|
||||
let empty;
|
||||
empty = true;
|
||||
return {
|
||||
/**
|
||||
* @param {string[]} row
|
||||
* @returns {undefined}
|
||||
*/
|
||||
write: row => {
|
||||
if (row.length !== config.columnCount) {
|
||||
throw new Error('Row cell count does not match the config.columnCount.');
|
||||
}
|
||||
|
||||
if (empty) {
|
||||
empty = false;
|
||||
return create(row, columnWidthIndex, config);
|
||||
} else {
|
||||
return append(row, columnWidthIndex, config);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var _default = createStream;
|
||||
exports.default = _default;
|
||||
//# sourceMappingURL=createStream.js.map
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
import _ from 'lodash';
|
||||
import makeStreamConfig from './makeStreamConfig';
|
||||
import drawRow from './drawRow';
|
||||
import {
|
||||
drawBorderBottom,
|
||||
drawBorderJoin,
|
||||
drawBorderTop
|
||||
} from './drawBorder';
|
||||
import stringifyTableData from './stringifyTableData';
|
||||
import truncateTableData from './truncateTableData';
|
||||
import mapDataUsingRowHeightIndex from './mapDataUsingRowHeightIndex';
|
||||
import alignTableData from './alignTableData';
|
||||
import padTableData from './padTableData';
|
||||
import calculateRowHeightIndex from './calculateRowHeightIndex';
|
||||
|
||||
/**
|
||||
* @param {Array} data
|
||||
* @param {Object} config
|
||||
* @returns {Array}
|
||||
*/
|
||||
const prepareData = (data, config) => {
|
||||
let rows;
|
||||
|
||||
rows = stringifyTableData(data);
|
||||
|
||||
rows = truncateTableData(data, config);
|
||||
|
||||
const rowHeightIndex = calculateRowHeightIndex(rows, config);
|
||||
|
||||
rows = mapDataUsingRowHeightIndex(rows, rowHeightIndex, config);
|
||||
rows = alignTableData(rows, config);
|
||||
rows = padTableData(rows, config);
|
||||
|
||||
return rows;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string[]} row
|
||||
* @param {number[]} columnWidthIndex
|
||||
* @param {Object} config
|
||||
* @returns {undefined}
|
||||
*/
|
||||
const create = (row, columnWidthIndex, config) => {
|
||||
const rows = prepareData([row], config);
|
||||
|
||||
const body = rows.map((literalRow) => {
|
||||
return drawRow(literalRow, config.border);
|
||||
}).join('');
|
||||
|
||||
let output;
|
||||
|
||||
output = '';
|
||||
|
||||
output += drawBorderTop(columnWidthIndex, config.border);
|
||||
output += body;
|
||||
output += drawBorderBottom(columnWidthIndex, config.border);
|
||||
|
||||
output = _.trimEnd(output);
|
||||
|
||||
process.stdout.write(output);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string[]} row
|
||||
* @param {number[]} columnWidthIndex
|
||||
* @param {Object} config
|
||||
* @returns {undefined}
|
||||
*/
|
||||
const append = (row, columnWidthIndex, config) => {
|
||||
const rows = prepareData([row], config);
|
||||
|
||||
const body = rows.map((literalRow) => {
|
||||
return drawRow(literalRow, config.border);
|
||||
}).join('');
|
||||
|
||||
let output;
|
||||
|
||||
output = '\r\u001B[K';
|
||||
|
||||
output += drawBorderJoin(columnWidthIndex, config.border);
|
||||
output += body;
|
||||
output += drawBorderBottom(columnWidthIndex, config.border);
|
||||
|
||||
output = _.trimEnd(output);
|
||||
|
||||
process.stdout.write(output);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Object} userConfig
|
||||
* @returns {Object}
|
||||
*/
|
||||
export default (userConfig = {}) => {
|
||||
const config = makeStreamConfig(userConfig);
|
||||
|
||||
// @todo Use 'Object.values' when Node.js v6 support is dropped.
|
||||
const columnWidthIndex = _.values(_.mapValues(config.columns, (column) => {
|
||||
return column.width + column.paddingLeft + column.paddingRight;
|
||||
}));
|
||||
|
||||
let empty;
|
||||
|
||||
empty = true;
|
||||
|
||||
return {
|
||||
/**
|
||||
* @param {string[]} row
|
||||
* @returns {undefined}
|
||||
*/
|
||||
write: (row) => {
|
||||
if (row.length !== config.columnCount) {
|
||||
throw new Error('Row cell count does not match the config.columnCount.');
|
||||
}
|
||||
|
||||
if (empty) {
|
||||
empty = false;
|
||||
|
||||
return create(row, columnWidthIndex, config);
|
||||
} else {
|
||||
return append(row, columnWidthIndex, config);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
+1
File diff suppressed because one or more lines are too long
+104
@@ -0,0 +1,104 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.drawBorderTop = exports.drawBorderJoin = exports.drawBorderBottom = exports.drawBorder = void 0;
|
||||
|
||||
/**
|
||||
* @typedef drawBorder~parts
|
||||
* @property {string} left
|
||||
* @property {string} right
|
||||
* @property {string} body
|
||||
* @property {string} join
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {number[]} columnSizeIndex
|
||||
* @param {drawBorder~parts} parts
|
||||
* @returns {string}
|
||||
*/
|
||||
const drawBorder = (columnSizeIndex, parts) => {
|
||||
const columns = columnSizeIndex.map(size => {
|
||||
return parts.body.repeat(size);
|
||||
}).join(parts.join);
|
||||
return parts.left + columns + parts.right + '\n';
|
||||
};
|
||||
/**
|
||||
* @typedef drawBorderTop~parts
|
||||
* @property {string} topLeft
|
||||
* @property {string} topRight
|
||||
* @property {string} topBody
|
||||
* @property {string} topJoin
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {number[]} columnSizeIndex
|
||||
* @param {drawBorderTop~parts} parts
|
||||
* @returns {string}
|
||||
*/
|
||||
|
||||
|
||||
exports.drawBorder = drawBorder;
|
||||
|
||||
const drawBorderTop = (columnSizeIndex, parts) => {
|
||||
return drawBorder(columnSizeIndex, {
|
||||
body: parts.topBody,
|
||||
join: parts.topJoin,
|
||||
left: parts.topLeft,
|
||||
right: parts.topRight
|
||||
});
|
||||
};
|
||||
/**
|
||||
* @typedef drawBorderJoin~parts
|
||||
* @property {string} joinLeft
|
||||
* @property {string} joinRight
|
||||
* @property {string} joinBody
|
||||
* @property {string} joinJoin
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {number[]} columnSizeIndex
|
||||
* @param {drawBorderJoin~parts} parts
|
||||
* @returns {string}
|
||||
*/
|
||||
|
||||
|
||||
exports.drawBorderTop = drawBorderTop;
|
||||
|
||||
const drawBorderJoin = (columnSizeIndex, parts) => {
|
||||
return drawBorder(columnSizeIndex, {
|
||||
body: parts.joinBody,
|
||||
join: parts.joinJoin,
|
||||
left: parts.joinLeft,
|
||||
right: parts.joinRight
|
||||
});
|
||||
};
|
||||
/**
|
||||
* @typedef drawBorderBottom~parts
|
||||
* @property {string} topLeft
|
||||
* @property {string} topRight
|
||||
* @property {string} topBody
|
||||
* @property {string} topJoin
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {number[]} columnSizeIndex
|
||||
* @param {drawBorderBottom~parts} parts
|
||||
* @returns {string}
|
||||
*/
|
||||
|
||||
|
||||
exports.drawBorderJoin = drawBorderJoin;
|
||||
|
||||
const drawBorderBottom = (columnSizeIndex, parts) => {
|
||||
return drawBorder(columnSizeIndex, {
|
||||
body: parts.bottomBody,
|
||||
join: parts.bottomJoin,
|
||||
left: parts.bottomLeft,
|
||||
right: parts.bottomRight
|
||||
});
|
||||
};
|
||||
|
||||
exports.drawBorderBottom = drawBorderBottom;
|
||||
//# sourceMappingURL=drawBorder.js.map
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* @typedef drawBorder~parts
|
||||
* @property {string} left
|
||||
* @property {string} right
|
||||
* @property {string} body
|
||||
* @property {string} join
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {number[]} columnSizeIndex
|
||||
* @param {drawBorder~parts} parts
|
||||
* @returns {string}
|
||||
*/
|
||||
const drawBorder = (columnSizeIndex, parts) => {
|
||||
const columns = columnSizeIndex
|
||||
.map((size) => {
|
||||
return parts.body.repeat(size);
|
||||
})
|
||||
.join(parts.join);
|
||||
|
||||
return parts.left + columns + parts.right + '\n';
|
||||
};
|
||||
|
||||
/**
|
||||
* @typedef drawBorderTop~parts
|
||||
* @property {string} topLeft
|
||||
* @property {string} topRight
|
||||
* @property {string} topBody
|
||||
* @property {string} topJoin
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {number[]} columnSizeIndex
|
||||
* @param {drawBorderTop~parts} parts
|
||||
* @returns {string}
|
||||
*/
|
||||
const drawBorderTop = (columnSizeIndex, parts) => {
|
||||
return drawBorder(columnSizeIndex, {
|
||||
body: parts.topBody,
|
||||
join: parts.topJoin,
|
||||
left: parts.topLeft,
|
||||
right: parts.topRight
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @typedef drawBorderJoin~parts
|
||||
* @property {string} joinLeft
|
||||
* @property {string} joinRight
|
||||
* @property {string} joinBody
|
||||
* @property {string} joinJoin
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {number[]} columnSizeIndex
|
||||
* @param {drawBorderJoin~parts} parts
|
||||
* @returns {string}
|
||||
*/
|
||||
const drawBorderJoin = (columnSizeIndex, parts) => {
|
||||
return drawBorder(columnSizeIndex, {
|
||||
body: parts.joinBody,
|
||||
join: parts.joinJoin,
|
||||
left: parts.joinLeft,
|
||||
right: parts.joinRight
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @typedef drawBorderBottom~parts
|
||||
* @property {string} topLeft
|
||||
* @property {string} topRight
|
||||
* @property {string} topBody
|
||||
* @property {string} topJoin
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {number[]} columnSizeIndex
|
||||
* @param {drawBorderBottom~parts} parts
|
||||
* @returns {string}
|
||||
*/
|
||||
const drawBorderBottom = (columnSizeIndex, parts) => {
|
||||
return drawBorder(columnSizeIndex, {
|
||||
body: parts.bottomBody,
|
||||
join: parts.bottomJoin,
|
||||
left: parts.bottomLeft,
|
||||
right: parts.bottomRight
|
||||
});
|
||||
};
|
||||
|
||||
export {
|
||||
drawBorder,
|
||||
drawBorderBottom,
|
||||
drawBorderJoin,
|
||||
drawBorderTop
|
||||
};
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../src/drawBorder.js"],"names":["drawBorder","columnSizeIndex","parts","columns","map","size","body","repeat","join","left","right","drawBorderTop","topBody","topJoin","topLeft","topRight","drawBorderJoin","joinBody","joinJoin","joinLeft","joinRight","drawBorderBottom","bottomBody","bottomJoin","bottomLeft","bottomRight"],"mappings":";;;;;;;AAAA;;;;;;;;AAQA;;;;;AAKA,MAAMA,UAAU,GAAG,CAACC,eAAD,EAAkBC,KAAlB,KAA4B;AAC7C,QAAMC,OAAO,GAAGF,eAAe,CAC5BG,GADa,CACRC,IAAD,IAAU;AACb,WAAOH,KAAK,CAACI,IAAN,CAAWC,MAAX,CAAkBF,IAAlB,CAAP;AACD,GAHa,EAIbG,IAJa,CAIRN,KAAK,CAACM,IAJE,CAAhB;AAMA,SAAON,KAAK,CAACO,IAAN,GAAaN,OAAb,GAAuBD,KAAK,CAACQ,KAA7B,GAAqC,IAA5C;AACD,CARD;AAUA;;;;;;;;AAQA;;;;;;;;;AAKA,MAAMC,aAAa,GAAG,CAACV,eAAD,EAAkBC,KAAlB,KAA4B;AAChD,SAAOF,UAAU,CAACC,eAAD,EAAkB;AACjCK,IAAAA,IAAI,EAAEJ,KAAK,CAACU,OADqB;AAEjCJ,IAAAA,IAAI,EAAEN,KAAK,CAACW,OAFqB;AAGjCJ,IAAAA,IAAI,EAAEP,KAAK,CAACY,OAHqB;AAIjCJ,IAAAA,KAAK,EAAER,KAAK,CAACa;AAJoB,GAAlB,CAAjB;AAMD,CAPD;AASA;;;;;;;;AAQA;;;;;;;;;AAKA,MAAMC,cAAc,GAAG,CAACf,eAAD,EAAkBC,KAAlB,KAA4B;AACjD,SAAOF,UAAU,CAACC,eAAD,EAAkB;AACjCK,IAAAA,IAAI,EAAEJ,KAAK,CAACe,QADqB;AAEjCT,IAAAA,IAAI,EAAEN,KAAK,CAACgB,QAFqB;AAGjCT,IAAAA,IAAI,EAAEP,KAAK,CAACiB,QAHqB;AAIjCT,IAAAA,KAAK,EAAER,KAAK,CAACkB;AAJoB,GAAlB,CAAjB;AAMD,CAPD;AASA;;;;;;;;AAQA;;;;;;;;;AAKA,MAAMC,gBAAgB,GAAG,CAACpB,eAAD,EAAkBC,KAAlB,KAA4B;AACnD,SAAOF,UAAU,CAACC,eAAD,EAAkB;AACjCK,IAAAA,IAAI,EAAEJ,KAAK,CAACoB,UADqB;AAEjCd,IAAAA,IAAI,EAAEN,KAAK,CAACqB,UAFqB;AAGjCd,IAAAA,IAAI,EAAEP,KAAK,CAACsB,UAHqB;AAIjCd,IAAAA,KAAK,EAAER,KAAK,CAACuB;AAJoB,GAAlB,CAAjB;AAMD,CAPD","sourcesContent":["/**\n * @typedef drawBorder~parts\n * @property {string} left\n * @property {string} right\n * @property {string} body\n * @property {string} join\n */\n\n/**\n * @param {number[]} columnSizeIndex\n * @param {drawBorder~parts} parts\n * @returns {string}\n */\nconst drawBorder = (columnSizeIndex, parts) => {\n const columns = columnSizeIndex\n .map((size) => {\n return parts.body.repeat(size);\n })\n .join(parts.join);\n\n return parts.left + columns + parts.right + '\\n';\n};\n\n/**\n * @typedef drawBorderTop~parts\n * @property {string} topLeft\n * @property {string} topRight\n * @property {string} topBody\n * @property {string} topJoin\n */\n\n/**\n * @param {number[]} columnSizeIndex\n * @param {drawBorderTop~parts} parts\n * @returns {string}\n */\nconst drawBorderTop = (columnSizeIndex, parts) => {\n return drawBorder(columnSizeIndex, {\n body: parts.topBody,\n join: parts.topJoin,\n left: parts.topLeft,\n right: parts.topRight\n });\n};\n\n/**\n * @typedef drawBorderJoin~parts\n * @property {string} joinLeft\n * @property {string} joinRight\n * @property {string} joinBody\n * @property {string} joinJoin\n */\n\n/**\n * @param {number[]} columnSizeIndex\n * @param {drawBorderJoin~parts} parts\n * @returns {string}\n */\nconst drawBorderJoin = (columnSizeIndex, parts) => {\n return drawBorder(columnSizeIndex, {\n body: parts.joinBody,\n join: parts.joinJoin,\n left: parts.joinLeft,\n right: parts.joinRight\n });\n};\n\n/**\n * @typedef drawBorderBottom~parts\n * @property {string} topLeft\n * @property {string} topRight\n * @property {string} topBody\n * @property {string} topJoin\n */\n\n/**\n * @param {number[]} columnSizeIndex\n * @param {drawBorderBottom~parts} parts\n * @returns {string}\n */\nconst drawBorderBottom = (columnSizeIndex, parts) => {\n return drawBorder(columnSizeIndex, {\n body: parts.bottomBody,\n join: parts.bottomJoin,\n left: parts.bottomLeft,\n right: parts.bottomRight\n });\n};\n\nexport {\n drawBorder,\n drawBorderBottom,\n drawBorderJoin,\n drawBorderTop\n};\n"],"file":"drawBorder.js"}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
/**
|
||||
* @typedef {Object} drawRow~border
|
||||
* @property {string} bodyLeft
|
||||
* @property {string} bodyRight
|
||||
* @property {string} bodyJoin
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {number[]} columns
|
||||
* @param {drawRow~border} border
|
||||
* @returns {string}
|
||||
*/
|
||||
const drawRow = (columns, border) => {
|
||||
return border.bodyLeft + columns.join(border.bodyJoin) + border.bodyRight + '\n';
|
||||
};
|
||||
|
||||
var _default = drawRow;
|
||||
exports.default = _default;
|
||||
//# sourceMappingURL=drawRow.js.map
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* @typedef {Object} drawRow~border
|
||||
* @property {string} bodyLeft
|
||||
* @property {string} bodyRight
|
||||
* @property {string} bodyJoin
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {number[]} columns
|
||||
* @param {drawRow~border} border
|
||||
* @returns {string}
|
||||
*/
|
||||
export default (columns, border) => {
|
||||
return border.bodyLeft + columns.join(border.bodyJoin) + border.bodyRight + '\n';
|
||||
};
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../src/drawRow.js"],"names":["columns","border","bodyLeft","join","bodyJoin","bodyRight"],"mappings":";;;;;;;AAAA;;;;;;;AAOA;;;;;iBAKgBA,O,EAASC,M,KAAW;AAClC,SAAOA,MAAM,CAACC,QAAP,GAAkBF,OAAO,CAACG,IAAR,CAAaF,MAAM,CAACG,QAApB,CAAlB,GAAkDH,MAAM,CAACI,SAAzD,GAAqE,IAA5E;AACD,C","sourcesContent":["/**\n * @typedef {Object} drawRow~border\n * @property {string} bodyLeft\n * @property {string} bodyRight\n * @property {string} bodyJoin\n */\n\n/**\n * @param {number[]} columns\n * @param {drawRow~border} border\n * @returns {string}\n */\nexport default (columns, border) => {\n return border.bodyLeft + columns.join(border.bodyJoin) + border.bodyRight + '\\n';\n};\n"],"file":"drawRow.js"}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _drawBorder = require("./drawBorder");
|
||||
|
||||
var _drawRow = _interopRequireDefault(require("./drawRow"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @param {Array} rows
|
||||
* @param {Object} border
|
||||
* @param {Array} columnSizeIndex
|
||||
* @param {Array} rowSpanIndex
|
||||
* @param {Function} drawHorizontalLine
|
||||
* @returns {string}
|
||||
*/
|
||||
const drawTable = (rows, border, columnSizeIndex, rowSpanIndex, drawHorizontalLine) => {
|
||||
let output;
|
||||
let realRowIndex;
|
||||
let rowHeight;
|
||||
const rowCount = rows.length;
|
||||
realRowIndex = 0;
|
||||
output = '';
|
||||
|
||||
if (drawHorizontalLine(realRowIndex, rowCount)) {
|
||||
output += (0, _drawBorder.drawBorderTop)(columnSizeIndex, border);
|
||||
}
|
||||
|
||||
rows.forEach((row, index0) => {
|
||||
output += (0, _drawRow.default)(row, border);
|
||||
|
||||
if (!rowHeight) {
|
||||
rowHeight = rowSpanIndex[realRowIndex];
|
||||
realRowIndex++;
|
||||
}
|
||||
|
||||
rowHeight--;
|
||||
|
||||
if (rowHeight === 0 && index0 !== rowCount - 1 && drawHorizontalLine(realRowIndex, rowCount)) {
|
||||
output += (0, _drawBorder.drawBorderJoin)(columnSizeIndex, border);
|
||||
}
|
||||
});
|
||||
|
||||
if (drawHorizontalLine(realRowIndex, rowCount)) {
|
||||
output += (0, _drawBorder.drawBorderBottom)(columnSizeIndex, border);
|
||||
}
|
||||
|
||||
return output;
|
||||
};
|
||||
|
||||
var _default = drawTable;
|
||||
exports.default = _default;
|
||||
//# sourceMappingURL=drawTable.js.map
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
import {
|
||||
drawBorderTop,
|
||||
drawBorderJoin,
|
||||
drawBorderBottom
|
||||
} from './drawBorder';
|
||||
import drawRow from './drawRow';
|
||||
|
||||
/**
|
||||
* @param {Array} rows
|
||||
* @param {Object} border
|
||||
* @param {Array} columnSizeIndex
|
||||
* @param {Array} rowSpanIndex
|
||||
* @param {Function} drawHorizontalLine
|
||||
* @returns {string}
|
||||
*/
|
||||
export default (rows, border, columnSizeIndex, rowSpanIndex, drawHorizontalLine) => {
|
||||
let output;
|
||||
let realRowIndex;
|
||||
let rowHeight;
|
||||
|
||||
const rowCount = rows.length;
|
||||
|
||||
realRowIndex = 0;
|
||||
|
||||
output = '';
|
||||
|
||||
if (drawHorizontalLine(realRowIndex, rowCount)) {
|
||||
output += drawBorderTop(columnSizeIndex, border);
|
||||
}
|
||||
|
||||
rows.forEach((row, index0) => {
|
||||
output += drawRow(row, border);
|
||||
|
||||
if (!rowHeight) {
|
||||
rowHeight = rowSpanIndex[realRowIndex];
|
||||
|
||||
realRowIndex++;
|
||||
}
|
||||
|
||||
rowHeight--;
|
||||
|
||||
if (rowHeight === 0 && index0 !== rowCount - 1 && drawHorizontalLine(realRowIndex, rowCount)) {
|
||||
output += drawBorderJoin(columnSizeIndex, border);
|
||||
}
|
||||
});
|
||||
|
||||
if (drawHorizontalLine(realRowIndex, rowCount)) {
|
||||
output += drawBorderBottom(columnSizeIndex, border);
|
||||
}
|
||||
|
||||
return output;
|
||||
};
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../src/drawTable.js"],"names":["rows","border","columnSizeIndex","rowSpanIndex","drawHorizontalLine","output","realRowIndex","rowHeight","rowCount","length","forEach","row","index0"],"mappings":";;;;;;;AAAA;;AAKA;;;;AAEA;;;;;;;;mBAQgBA,I,EAAMC,M,EAAQC,e,EAAiBC,Y,EAAcC,kB,KAAuB;AAClF,MAAIC,MAAJ;AACA,MAAIC,YAAJ;AACA,MAAIC,SAAJ;AAEA,QAAMC,QAAQ,GAAGR,IAAI,CAACS,MAAtB;AAEAH,EAAAA,YAAY,GAAG,CAAf;AAEAD,EAAAA,MAAM,GAAG,EAAT;;AAEA,MAAID,kBAAkB,CAACE,YAAD,EAAeE,QAAf,CAAtB,EAAgD;AAC9CH,IAAAA,MAAM,IAAI,+BAAcH,eAAd,EAA+BD,MAA/B,CAAV;AACD;;AAEDD,EAAAA,IAAI,CAACU,OAAL,CAAa,CAACC,GAAD,EAAMC,MAAN,KAAiB;AAC5BP,IAAAA,MAAM,IAAI,sBAAQM,GAAR,EAAaV,MAAb,CAAV;;AAEA,QAAI,CAACM,SAAL,EAAgB;AACdA,MAAAA,SAAS,GAAGJ,YAAY,CAACG,YAAD,CAAxB;AAEAA,MAAAA,YAAY;AACb;;AAEDC,IAAAA,SAAS;;AAET,QAAIA,SAAS,KAAK,CAAd,IAAmBK,MAAM,KAAKJ,QAAQ,GAAG,CAAzC,IAA8CJ,kBAAkB,CAACE,YAAD,EAAeE,QAAf,CAApE,EAA8F;AAC5FH,MAAAA,MAAM,IAAI,gCAAeH,eAAf,EAAgCD,MAAhC,CAAV;AACD;AACF,GAdD;;AAgBA,MAAIG,kBAAkB,CAACE,YAAD,EAAeE,QAAf,CAAtB,EAAgD;AAC9CH,IAAAA,MAAM,IAAI,kCAAiBH,eAAjB,EAAkCD,MAAlC,CAAV;AACD;;AAED,SAAOI,MAAP;AACD,C","sourcesContent":["import {\n drawBorderTop,\n drawBorderJoin,\n drawBorderBottom\n} from './drawBorder';\nimport drawRow from './drawRow';\n\n/**\n * @param {Array} rows\n * @param {Object} border\n * @param {Array} columnSizeIndex\n * @param {Array} rowSpanIndex\n * @param {Function} drawHorizontalLine\n * @returns {string}\n */\nexport default (rows, border, columnSizeIndex, rowSpanIndex, drawHorizontalLine) => {\n let output;\n let realRowIndex;\n let rowHeight;\n\n const rowCount = rows.length;\n\n realRowIndex = 0;\n\n output = '';\n\n if (drawHorizontalLine(realRowIndex, rowCount)) {\n output += drawBorderTop(columnSizeIndex, border);\n }\n\n rows.forEach((row, index0) => {\n output += drawRow(row, border);\n\n if (!rowHeight) {\n rowHeight = rowSpanIndex[realRowIndex];\n\n realRowIndex++;\n }\n\n rowHeight--;\n\n if (rowHeight === 0 && index0 !== rowCount - 1 && drawHorizontalLine(realRowIndex, rowCount)) {\n output += drawBorderJoin(columnSizeIndex, border);\n }\n });\n\n if (drawHorizontalLine(realRowIndex, rowCount)) {\n output += drawBorderBottom(columnSizeIndex, border);\n }\n\n return output;\n};\n"],"file":"drawTable.js"}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
/* eslint-disable sort-keys */
|
||||
|
||||
/**
|
||||
* @typedef border
|
||||
* @property {string} topBody
|
||||
* @property {string} topJoin
|
||||
* @property {string} topLeft
|
||||
* @property {string} topRight
|
||||
* @property {string} bottomBody
|
||||
* @property {string} bottomJoin
|
||||
* @property {string} bottomLeft
|
||||
* @property {string} bottomRight
|
||||
* @property {string} bodyLeft
|
||||
* @property {string} bodyRight
|
||||
* @property {string} bodyJoin
|
||||
* @property {string} joinBody
|
||||
* @property {string} joinLeft
|
||||
* @property {string} joinRight
|
||||
* @property {string} joinJoin
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {string} name
|
||||
* @returns {border}
|
||||
*/
|
||||
const getBorderCharacters = name => {
|
||||
if (name === 'honeywell') {
|
||||
return {
|
||||
topBody: '═',
|
||||
topJoin: '╤',
|
||||
topLeft: '╔',
|
||||
topRight: '╗',
|
||||
bottomBody: '═',
|
||||
bottomJoin: '╧',
|
||||
bottomLeft: '╚',
|
||||
bottomRight: '╝',
|
||||
bodyLeft: '║',
|
||||
bodyRight: '║',
|
||||
bodyJoin: '│',
|
||||
joinBody: '─',
|
||||
joinLeft: '╟',
|
||||
joinRight: '╢',
|
||||
joinJoin: '┼'
|
||||
};
|
||||
}
|
||||
|
||||
if (name === 'norc') {
|
||||
return {
|
||||
topBody: '─',
|
||||
topJoin: '┬',
|
||||
topLeft: '┌',
|
||||
topRight: '┐',
|
||||
bottomBody: '─',
|
||||
bottomJoin: '┴',
|
||||
bottomLeft: '└',
|
||||
bottomRight: '┘',
|
||||
bodyLeft: '│',
|
||||
bodyRight: '│',
|
||||
bodyJoin: '│',
|
||||
joinBody: '─',
|
||||
joinLeft: '├',
|
||||
joinRight: '┤',
|
||||
joinJoin: '┼'
|
||||
};
|
||||
}
|
||||
|
||||
if (name === 'ramac') {
|
||||
return {
|
||||
topBody: '-',
|
||||
topJoin: '+',
|
||||
topLeft: '+',
|
||||
topRight: '+',
|
||||
bottomBody: '-',
|
||||
bottomJoin: '+',
|
||||
bottomLeft: '+',
|
||||
bottomRight: '+',
|
||||
bodyLeft: '|',
|
||||
bodyRight: '|',
|
||||
bodyJoin: '|',
|
||||
joinBody: '-',
|
||||
joinLeft: '|',
|
||||
joinRight: '|',
|
||||
joinJoin: '|'
|
||||
};
|
||||
}
|
||||
|
||||
if (name === 'void') {
|
||||
return {
|
||||
topBody: '',
|
||||
topJoin: '',
|
||||
topLeft: '',
|
||||
topRight: '',
|
||||
bottomBody: '',
|
||||
bottomJoin: '',
|
||||
bottomLeft: '',
|
||||
bottomRight: '',
|
||||
bodyLeft: '',
|
||||
bodyRight: '',
|
||||
bodyJoin: '',
|
||||
joinBody: '',
|
||||
joinLeft: '',
|
||||
joinRight: '',
|
||||
joinJoin: ''
|
||||
};
|
||||
}
|
||||
|
||||
throw new Error('Unknown border template "' + name + '".');
|
||||
};
|
||||
|
||||
var _default = getBorderCharacters;
|
||||
exports.default = _default;
|
||||
//# sourceMappingURL=getBorderCharacters.js.map
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
/* eslint-disable sort-keys */
|
||||
|
||||
/**
|
||||
* @typedef border
|
||||
* @property {string} topBody
|
||||
* @property {string} topJoin
|
||||
* @property {string} topLeft
|
||||
* @property {string} topRight
|
||||
* @property {string} bottomBody
|
||||
* @property {string} bottomJoin
|
||||
* @property {string} bottomLeft
|
||||
* @property {string} bottomRight
|
||||
* @property {string} bodyLeft
|
||||
* @property {string} bodyRight
|
||||
* @property {string} bodyJoin
|
||||
* @property {string} joinBody
|
||||
* @property {string} joinLeft
|
||||
* @property {string} joinRight
|
||||
* @property {string} joinJoin
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {string} name
|
||||
* @returns {border}
|
||||
*/
|
||||
export default (name) => {
|
||||
if (name === 'honeywell') {
|
||||
return {
|
||||
topBody: '═',
|
||||
topJoin: '╤',
|
||||
topLeft: '╔',
|
||||
topRight: '╗',
|
||||
|
||||
bottomBody: '═',
|
||||
bottomJoin: '╧',
|
||||
bottomLeft: '╚',
|
||||
bottomRight: '╝',
|
||||
|
||||
bodyLeft: '║',
|
||||
bodyRight: '║',
|
||||
bodyJoin: '│',
|
||||
|
||||
joinBody: '─',
|
||||
joinLeft: '╟',
|
||||
joinRight: '╢',
|
||||
joinJoin: '┼'
|
||||
};
|
||||
}
|
||||
|
||||
if (name === 'norc') {
|
||||
return {
|
||||
topBody: '─',
|
||||
topJoin: '┬',
|
||||
topLeft: '┌',
|
||||
topRight: '┐',
|
||||
|
||||
bottomBody: '─',
|
||||
bottomJoin: '┴',
|
||||
bottomLeft: '└',
|
||||
bottomRight: '┘',
|
||||
|
||||
bodyLeft: '│',
|
||||
bodyRight: '│',
|
||||
bodyJoin: '│',
|
||||
|
||||
joinBody: '─',
|
||||
joinLeft: '├',
|
||||
joinRight: '┤',
|
||||
joinJoin: '┼'
|
||||
};
|
||||
}
|
||||
|
||||
if (name === 'ramac') {
|
||||
return {
|
||||
topBody: '-',
|
||||
topJoin: '+',
|
||||
topLeft: '+',
|
||||
topRight: '+',
|
||||
|
||||
bottomBody: '-',
|
||||
bottomJoin: '+',
|
||||
bottomLeft: '+',
|
||||
bottomRight: '+',
|
||||
|
||||
bodyLeft: '|',
|
||||
bodyRight: '|',
|
||||
bodyJoin: '|',
|
||||
|
||||
joinBody: '-',
|
||||
joinLeft: '|',
|
||||
joinRight: '|',
|
||||
joinJoin: '|'
|
||||
};
|
||||
}
|
||||
|
||||
if (name === 'void') {
|
||||
return {
|
||||
topBody: '',
|
||||
topJoin: '',
|
||||
topLeft: '',
|
||||
topRight: '',
|
||||
|
||||
bottomBody: '',
|
||||
bottomJoin: '',
|
||||
bottomLeft: '',
|
||||
bottomRight: '',
|
||||
|
||||
bodyLeft: '',
|
||||
bodyRight: '',
|
||||
bodyJoin: '',
|
||||
|
||||
joinBody: '',
|
||||
joinLeft: '',
|
||||
joinRight: '',
|
||||
joinJoin: ''
|
||||
};
|
||||
}
|
||||
|
||||
throw new Error('Unknown border template "' + name + '".');
|
||||
};
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../src/getBorderCharacters.js"],"names":["name","topBody","topJoin","topLeft","topRight","bottomBody","bottomJoin","bottomLeft","bottomRight","bodyLeft","bodyRight","bodyJoin","joinBody","joinLeft","joinRight","joinJoin","Error"],"mappings":";;;;;;;AAAA;;AAEA;;;;;;;;;;;;;;;;;;;AAmBA;;;;4BAIgBA,I,IAAS;AACvB,MAAIA,IAAI,KAAK,WAAb,EAA0B;AACxB,WAAO;AACLC,MAAAA,OAAO,EAAE,GADJ;AAELC,MAAAA,OAAO,EAAE,GAFJ;AAGLC,MAAAA,OAAO,EAAE,GAHJ;AAILC,MAAAA,QAAQ,EAAE,GAJL;AAMLC,MAAAA,UAAU,EAAE,GANP;AAOLC,MAAAA,UAAU,EAAE,GAPP;AAQLC,MAAAA,UAAU,EAAE,GARP;AASLC,MAAAA,WAAW,EAAE,GATR;AAWLC,MAAAA,QAAQ,EAAE,GAXL;AAYLC,MAAAA,SAAS,EAAE,GAZN;AAaLC,MAAAA,QAAQ,EAAE,GAbL;AAeLC,MAAAA,QAAQ,EAAE,GAfL;AAgBLC,MAAAA,QAAQ,EAAE,GAhBL;AAiBLC,MAAAA,SAAS,EAAE,GAjBN;AAkBLC,MAAAA,QAAQ,EAAE;AAlBL,KAAP;AAoBD;;AAED,MAAIf,IAAI,KAAK,MAAb,EAAqB;AACnB,WAAO;AACLC,MAAAA,OAAO,EAAE,GADJ;AAELC,MAAAA,OAAO,EAAE,GAFJ;AAGLC,MAAAA,OAAO,EAAE,GAHJ;AAILC,MAAAA,QAAQ,EAAE,GAJL;AAMLC,MAAAA,UAAU,EAAE,GANP;AAOLC,MAAAA,UAAU,EAAE,GAPP;AAQLC,MAAAA,UAAU,EAAE,GARP;AASLC,MAAAA,WAAW,EAAE,GATR;AAWLC,MAAAA,QAAQ,EAAE,GAXL;AAYLC,MAAAA,SAAS,EAAE,GAZN;AAaLC,MAAAA,QAAQ,EAAE,GAbL;AAeLC,MAAAA,QAAQ,EAAE,GAfL;AAgBLC,MAAAA,QAAQ,EAAE,GAhBL;AAiBLC,MAAAA,SAAS,EAAE,GAjBN;AAkBLC,MAAAA,QAAQ,EAAE;AAlBL,KAAP;AAoBD;;AAED,MAAIf,IAAI,KAAK,OAAb,EAAsB;AACpB,WAAO;AACLC,MAAAA,OAAO,EAAE,GADJ;AAELC,MAAAA,OAAO,EAAE,GAFJ;AAGLC,MAAAA,OAAO,EAAE,GAHJ;AAILC,MAAAA,QAAQ,EAAE,GAJL;AAMLC,MAAAA,UAAU,EAAE,GANP;AAOLC,MAAAA,UAAU,EAAE,GAPP;AAQLC,MAAAA,UAAU,EAAE,GARP;AASLC,MAAAA,WAAW,EAAE,GATR;AAWLC,MAAAA,QAAQ,EAAE,GAXL;AAYLC,MAAAA,SAAS,EAAE,GAZN;AAaLC,MAAAA,QAAQ,EAAE,GAbL;AAeLC,MAAAA,QAAQ,EAAE,GAfL;AAgBLC,MAAAA,QAAQ,EAAE,GAhBL;AAiBLC,MAAAA,SAAS,EAAE,GAjBN;AAkBLC,MAAAA,QAAQ,EAAE;AAlBL,KAAP;AAoBD;;AAED,MAAIf,IAAI,KAAK,MAAb,EAAqB;AACnB,WAAO;AACLC,MAAAA,OAAO,EAAE,EADJ;AAELC,MAAAA,OAAO,EAAE,EAFJ;AAGLC,MAAAA,OAAO,EAAE,EAHJ;AAILC,MAAAA,QAAQ,EAAE,EAJL;AAMLC,MAAAA,UAAU,EAAE,EANP;AAOLC,MAAAA,UAAU,EAAE,EAPP;AAQLC,MAAAA,UAAU,EAAE,EARP;AASLC,MAAAA,WAAW,EAAE,EATR;AAWLC,MAAAA,QAAQ,EAAE,EAXL;AAYLC,MAAAA,SAAS,EAAE,EAZN;AAaLC,MAAAA,QAAQ,EAAE,EAbL;AAeLC,MAAAA,QAAQ,EAAE,EAfL;AAgBLC,MAAAA,QAAQ,EAAE,EAhBL;AAiBLC,MAAAA,SAAS,EAAE,EAjBN;AAkBLC,MAAAA,QAAQ,EAAE;AAlBL,KAAP;AAoBD;;AAED,QAAM,IAAIC,KAAJ,CAAU,8BAA8BhB,IAA9B,GAAqC,IAA/C,CAAN;AACD,C","sourcesContent":["/* eslint-disable sort-keys */\n\n/**\n * @typedef border\n * @property {string} topBody\n * @property {string} topJoin\n * @property {string} topLeft\n * @property {string} topRight\n * @property {string} bottomBody\n * @property {string} bottomJoin\n * @property {string} bottomLeft\n * @property {string} bottomRight\n * @property {string} bodyLeft\n * @property {string} bodyRight\n * @property {string} bodyJoin\n * @property {string} joinBody\n * @property {string} joinLeft\n * @property {string} joinRight\n * @property {string} joinJoin\n */\n\n/**\n * @param {string} name\n * @returns {border}\n */\nexport default (name) => {\n if (name === 'honeywell') {\n return {\n topBody: '═',\n topJoin: '╤',\n topLeft: '╔',\n topRight: '╗',\n\n bottomBody: '═',\n bottomJoin: '╧',\n bottomLeft: '╚',\n bottomRight: '╝',\n\n bodyLeft: '║',\n bodyRight: '║',\n bodyJoin: '│',\n\n joinBody: '─',\n joinLeft: '╟',\n joinRight: '╢',\n joinJoin: '┼'\n };\n }\n\n if (name === 'norc') {\n return {\n topBody: '─',\n topJoin: '┬',\n topLeft: '┌',\n topRight: '┐',\n\n bottomBody: '─',\n bottomJoin: '┴',\n bottomLeft: '└',\n bottomRight: '┘',\n\n bodyLeft: '│',\n bodyRight: '│',\n bodyJoin: '│',\n\n joinBody: '─',\n joinLeft: '├',\n joinRight: '┤',\n joinJoin: '┼'\n };\n }\n\n if (name === 'ramac') {\n return {\n topBody: '-',\n topJoin: '+',\n topLeft: '+',\n topRight: '+',\n\n bottomBody: '-',\n bottomJoin: '+',\n bottomLeft: '+',\n bottomRight: '+',\n\n bodyLeft: '|',\n bodyRight: '|',\n bodyJoin: '|',\n\n joinBody: '-',\n joinLeft: '|',\n joinRight: '|',\n joinJoin: '|'\n };\n }\n\n if (name === 'void') {\n return {\n topBody: '',\n topJoin: '',\n topLeft: '',\n topRight: '',\n\n bottomBody: '',\n bottomJoin: '',\n bottomLeft: '',\n bottomRight: '',\n\n bodyLeft: '',\n bodyRight: '',\n bodyJoin: '',\n\n joinBody: '',\n joinLeft: '',\n joinRight: '',\n joinJoin: ''\n };\n }\n\n throw new Error('Unknown border template \"' + name + '\".');\n};\n"],"file":"getBorderCharacters.js"}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "table", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _table.default;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "createStream", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _createStream.default;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "getBorderCharacters", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _getBorderCharacters.default;
|
||||
}
|
||||
});
|
||||
|
||||
var _table = _interopRequireDefault(require("./table"));
|
||||
|
||||
var _createStream = _interopRequireDefault(require("./createStream"));
|
||||
|
||||
var _getBorderCharacters = _interopRequireDefault(require("./getBorderCharacters"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
//# sourceMappingURL=index.js.map
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import table from './table';
|
||||
import createStream from './createStream';
|
||||
import getBorderCharacters from './getBorderCharacters';
|
||||
|
||||
export {
|
||||
table,
|
||||
createStream,
|
||||
getBorderCharacters
|
||||
};
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../src/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA","sourcesContent":["import table from './table';\nimport createStream from './createStream';\nimport getBorderCharacters from './getBorderCharacters';\n\nexport {\n table,\n createStream,\n getBorderCharacters\n};\n"],"file":"index.js"}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _lodash = _interopRequireDefault(require("lodash"));
|
||||
|
||||
var _getBorderCharacters = _interopRequireDefault(require("./getBorderCharacters"));
|
||||
|
||||
var _validateConfig = _interopRequireDefault(require("./validateConfig"));
|
||||
|
||||
var _calculateMaximumColumnWidthIndex = _interopRequireDefault(require("./calculateMaximumColumnWidthIndex"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* Merges user provided border characters with the default border ("honeywell") characters.
|
||||
*
|
||||
* @param {Object} border
|
||||
* @returns {Object}
|
||||
*/
|
||||
const makeBorder = (border = {}) => {
|
||||
return Object.assign({}, (0, _getBorderCharacters.default)('honeywell'), border);
|
||||
};
|
||||
/**
|
||||
* Creates a configuration for every column using default
|
||||
* values for the missing configuration properties.
|
||||
*
|
||||
* @param {Array[]} rows
|
||||
* @param {Object} columns
|
||||
* @param {Object} columnDefault
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
|
||||
const makeColumns = (rows, columns = {}, columnDefault = {}) => {
|
||||
const maximumColumnWidthIndex = (0, _calculateMaximumColumnWidthIndex.default)(rows);
|
||||
|
||||
_lodash.default.times(rows[0].length, index => {
|
||||
if (_lodash.default.isUndefined(columns[index])) {
|
||||
columns[index] = {};
|
||||
}
|
||||
|
||||
columns[index] = Object.assign({
|
||||
alignment: 'left',
|
||||
paddingLeft: 1,
|
||||
paddingRight: 1,
|
||||
truncate: Infinity,
|
||||
width: maximumColumnWidthIndex[index],
|
||||
wrapWord: false
|
||||
}, columnDefault, columns[index]);
|
||||
});
|
||||
|
||||
return columns;
|
||||
};
|
||||
/**
|
||||
* Makes a new configuration object out of the userConfig object
|
||||
* using default values for the missing configuration properties.
|
||||
*
|
||||
* @param {Array[]} rows
|
||||
* @param {Object} userConfig
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
|
||||
const makeConfig = (rows, userConfig = {}) => {
|
||||
(0, _validateConfig.default)('config.json', userConfig);
|
||||
|
||||
const config = _lodash.default.cloneDeep(userConfig);
|
||||
|
||||
config.border = makeBorder(config.border);
|
||||
config.columns = makeColumns(rows, config.columns, config.columnDefault);
|
||||
|
||||
if (!config.drawHorizontalLine) {
|
||||
/**
|
||||
* @returns {boolean}
|
||||
*/
|
||||
config.drawHorizontalLine = () => {
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
return config;
|
||||
};
|
||||
|
||||
var _default = makeConfig;
|
||||
exports.default = _default;
|
||||
//# sourceMappingURL=makeConfig.js.map
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
import _ from 'lodash';
|
||||
import getBorderCharacters from './getBorderCharacters';
|
||||
import validateConfig from './validateConfig';
|
||||
import calculateMaximumColumnWidthIndex from './calculateMaximumColumnWidthIndex';
|
||||
|
||||
/**
|
||||
* Merges user provided border characters with the default border ("honeywell") characters.
|
||||
*
|
||||
* @param {Object} border
|
||||
* @returns {Object}
|
||||
*/
|
||||
const makeBorder = (border = {}) => {
|
||||
return Object.assign({}, getBorderCharacters('honeywell'), border);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a configuration for every column using default
|
||||
* values for the missing configuration properties.
|
||||
*
|
||||
* @param {Array[]} rows
|
||||
* @param {Object} columns
|
||||
* @param {Object} columnDefault
|
||||
* @returns {Object}
|
||||
*/
|
||||
const makeColumns = (rows, columns = {}, columnDefault = {}) => {
|
||||
const maximumColumnWidthIndex = calculateMaximumColumnWidthIndex(rows);
|
||||
|
||||
_.times(rows[0].length, (index) => {
|
||||
if (_.isUndefined(columns[index])) {
|
||||
columns[index] = {};
|
||||
}
|
||||
|
||||
columns[index] = Object.assign({
|
||||
alignment: 'left',
|
||||
paddingLeft: 1,
|
||||
paddingRight: 1,
|
||||
truncate: Infinity,
|
||||
width: maximumColumnWidthIndex[index],
|
||||
wrapWord: false
|
||||
}, columnDefault, columns[index]);
|
||||
});
|
||||
|
||||
return columns;
|
||||
};
|
||||
|
||||
/**
|
||||
* Makes a new configuration object out of the userConfig object
|
||||
* using default values for the missing configuration properties.
|
||||
*
|
||||
* @param {Array[]} rows
|
||||
* @param {Object} userConfig
|
||||
* @returns {Object}
|
||||
*/
|
||||
export default (rows, userConfig = {}) => {
|
||||
validateConfig('config.json', userConfig);
|
||||
|
||||
const config = _.cloneDeep(userConfig);
|
||||
|
||||
config.border = makeBorder(config.border);
|
||||
config.columns = makeColumns(rows, config.columns, config.columnDefault);
|
||||
|
||||
if (!config.drawHorizontalLine) {
|
||||
/**
|
||||
* @returns {boolean}
|
||||
*/
|
||||
config.drawHorizontalLine = () => {
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
return config;
|
||||
};
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../src/makeConfig.js"],"names":["makeBorder","border","Object","assign","makeColumns","rows","columns","columnDefault","maximumColumnWidthIndex","_","times","length","index","isUndefined","alignment","paddingLeft","paddingRight","truncate","Infinity","width","wrapWord","userConfig","config","cloneDeep","drawHorizontalLine"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;;;AAEA;;;;;;AAMA,MAAMA,UAAU,GAAG,CAACC,MAAM,GAAG,EAAV,KAAiB;AAClC,SAAOC,MAAM,CAACC,MAAP,CAAc,EAAd,EAAkB,kCAAoB,WAApB,CAAlB,EAAoDF,MAApD,CAAP;AACD,CAFD;AAIA;;;;;;;;;;;AASA,MAAMG,WAAW,GAAG,CAACC,IAAD,EAAOC,OAAO,GAAG,EAAjB,EAAqBC,aAAa,GAAG,EAArC,KAA4C;AAC9D,QAAMC,uBAAuB,GAAG,+CAAiCH,IAAjC,CAAhC;;AAEAI,kBAAEC,KAAF,CAAQL,IAAI,CAAC,CAAD,CAAJ,CAAQM,MAAhB,EAAyBC,KAAD,IAAW;AACjC,QAAIH,gBAAEI,WAAF,CAAcP,OAAO,CAACM,KAAD,CAArB,CAAJ,EAAmC;AACjCN,MAAAA,OAAO,CAACM,KAAD,CAAP,GAAiB,EAAjB;AACD;;AAEDN,IAAAA,OAAO,CAACM,KAAD,CAAP,GAAiBV,MAAM,CAACC,MAAP,CAAc;AAC7BW,MAAAA,SAAS,EAAE,MADkB;AAE7BC,MAAAA,WAAW,EAAE,CAFgB;AAG7BC,MAAAA,YAAY,EAAE,CAHe;AAI7BC,MAAAA,QAAQ,EAAEC,QAJmB;AAK7BC,MAAAA,KAAK,EAAEX,uBAAuB,CAACI,KAAD,CALD;AAM7BQ,MAAAA,QAAQ,EAAE;AANmB,KAAd,EAOdb,aAPc,EAOCD,OAAO,CAACM,KAAD,CAPR,CAAjB;AAQD,GAbD;;AAeA,SAAON,OAAP;AACD,CAnBD;AAqBA;;;;;;;;;;oBAQgBD,I,EAAMgB,UAAU,GAAG,E,KAAO;AACxC,+BAAe,aAAf,EAA8BA,UAA9B;;AAEA,QAAMC,MAAM,GAAGb,gBAAEc,SAAF,CAAYF,UAAZ,CAAf;;AAEAC,EAAAA,MAAM,CAACrB,MAAP,GAAgBD,UAAU,CAACsB,MAAM,CAACrB,MAAR,CAA1B;AACAqB,EAAAA,MAAM,CAAChB,OAAP,GAAiBF,WAAW,CAACC,IAAD,EAAOiB,MAAM,CAAChB,OAAd,EAAuBgB,MAAM,CAACf,aAA9B,CAA5B;;AAEA,MAAI,CAACe,MAAM,CAACE,kBAAZ,EAAgC;AAC9B;;;AAGAF,IAAAA,MAAM,CAACE,kBAAP,GAA4B,MAAM;AAChC,aAAO,IAAP;AACD,KAFD;AAGD;;AAED,SAAOF,MAAP;AACD,C","sourcesContent":["import _ from 'lodash';\nimport getBorderCharacters from './getBorderCharacters';\nimport validateConfig from './validateConfig';\nimport calculateMaximumColumnWidthIndex from './calculateMaximumColumnWidthIndex';\n\n/**\n * Merges user provided border characters with the default border (\"honeywell\") characters.\n *\n * @param {Object} border\n * @returns {Object}\n */\nconst makeBorder = (border = {}) => {\n return Object.assign({}, getBorderCharacters('honeywell'), border);\n};\n\n/**\n * Creates a configuration for every column using default\n * values for the missing configuration properties.\n *\n * @param {Array[]} rows\n * @param {Object} columns\n * @param {Object} columnDefault\n * @returns {Object}\n */\nconst makeColumns = (rows, columns = {}, columnDefault = {}) => {\n const maximumColumnWidthIndex = calculateMaximumColumnWidthIndex(rows);\n\n _.times(rows[0].length, (index) => {\n if (_.isUndefined(columns[index])) {\n columns[index] = {};\n }\n\n columns[index] = Object.assign({\n alignment: 'left',\n paddingLeft: 1,\n paddingRight: 1,\n truncate: Infinity,\n width: maximumColumnWidthIndex[index],\n wrapWord: false\n }, columnDefault, columns[index]);\n });\n\n return columns;\n};\n\n/**\n * Makes a new configuration object out of the userConfig object\n * using default values for the missing configuration properties.\n *\n * @param {Array[]} rows\n * @param {Object} userConfig\n * @returns {Object}\n */\nexport default (rows, userConfig = {}) => {\n validateConfig('config.json', userConfig);\n\n const config = _.cloneDeep(userConfig);\n\n config.border = makeBorder(config.border);\n config.columns = makeColumns(rows, config.columns, config.columnDefault);\n\n if (!config.drawHorizontalLine) {\n /**\n * @returns {boolean}\n */\n config.drawHorizontalLine = () => {\n return true;\n };\n }\n\n return config;\n};\n"],"file":"makeConfig.js"}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _lodash = _interopRequireDefault(require("lodash"));
|
||||
|
||||
var _getBorderCharacters = _interopRequireDefault(require("./getBorderCharacters"));
|
||||
|
||||
var _validateConfig = _interopRequireDefault(require("./validateConfig"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* Merges user provided border characters with the default border ("honeywell") characters.
|
||||
*
|
||||
* @param {Object} border
|
||||
* @returns {Object}
|
||||
*/
|
||||
const makeBorder = (border = {}) => {
|
||||
return Object.assign({}, (0, _getBorderCharacters.default)('honeywell'), border);
|
||||
};
|
||||
/**
|
||||
* Creates a configuration for every column using default
|
||||
* values for the missing configuration properties.
|
||||
*
|
||||
* @param {number} columnCount
|
||||
* @param {Object} columns
|
||||
* @param {Object} columnDefault
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
|
||||
const makeColumns = (columnCount, columns = {}, columnDefault = {}) => {
|
||||
_lodash.default.times(columnCount, index => {
|
||||
if (_lodash.default.isUndefined(columns[index])) {
|
||||
columns[index] = {};
|
||||
}
|
||||
|
||||
columns[index] = Object.assign({
|
||||
alignment: 'left',
|
||||
paddingLeft: 1,
|
||||
paddingRight: 1,
|
||||
truncate: Infinity,
|
||||
wrapWord: false
|
||||
}, columnDefault, columns[index]);
|
||||
});
|
||||
|
||||
return columns;
|
||||
};
|
||||
/**
|
||||
* @typedef {Object} columnConfig
|
||||
* @property {string} alignment
|
||||
* @property {number} width
|
||||
* @property {number} truncate
|
||||
* @property {number} paddingLeft
|
||||
* @property {number} paddingRight
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} streamConfig
|
||||
* @property {columnConfig} columnDefault
|
||||
* @property {Object} border
|
||||
* @property {columnConfig[]}
|
||||
* @property {number} columnCount Number of columns in the table (required).
|
||||
*/
|
||||
|
||||
/**
|
||||
* Makes a new configuration object out of the userConfig object
|
||||
* using default values for the missing configuration properties.
|
||||
*
|
||||
* @param {streamConfig} userConfig
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
|
||||
const makeStreamConfig = (userConfig = {}) => {
|
||||
(0, _validateConfig.default)('streamConfig.json', userConfig);
|
||||
|
||||
const config = _lodash.default.cloneDeep(userConfig);
|
||||
|
||||
if (!config.columnDefault || !config.columnDefault.width) {
|
||||
throw new Error('Must provide config.columnDefault.width when creating a stream.');
|
||||
}
|
||||
|
||||
if (!config.columnCount) {
|
||||
throw new Error('Must provide config.columnCount.');
|
||||
}
|
||||
|
||||
config.border = makeBorder(config.border);
|
||||
config.columns = makeColumns(config.columnCount, config.columns, config.columnDefault);
|
||||
return config;
|
||||
};
|
||||
|
||||
var _default = makeStreamConfig;
|
||||
exports.default = _default;
|
||||
//# sourceMappingURL=makeStreamConfig.js.map
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
import _ from 'lodash';
|
||||
import getBorderCharacters from './getBorderCharacters';
|
||||
import validateConfig from './validateConfig';
|
||||
|
||||
/**
|
||||
* Merges user provided border characters with the default border ("honeywell") characters.
|
||||
*
|
||||
* @param {Object} border
|
||||
* @returns {Object}
|
||||
*/
|
||||
const makeBorder = (border = {}) => {
|
||||
return Object.assign({}, getBorderCharacters('honeywell'), border);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a configuration for every column using default
|
||||
* values for the missing configuration properties.
|
||||
*
|
||||
* @param {number} columnCount
|
||||
* @param {Object} columns
|
||||
* @param {Object} columnDefault
|
||||
* @returns {Object}
|
||||
*/
|
||||
const makeColumns = (columnCount, columns = {}, columnDefault = {}) => {
|
||||
_.times(columnCount, (index) => {
|
||||
if (_.isUndefined(columns[index])) {
|
||||
columns[index] = {};
|
||||
}
|
||||
|
||||
columns[index] = Object.assign({
|
||||
alignment: 'left',
|
||||
paddingLeft: 1,
|
||||
paddingRight: 1,
|
||||
truncate: Infinity,
|
||||
wrapWord: false
|
||||
}, columnDefault, columns[index]);
|
||||
});
|
||||
|
||||
return columns;
|
||||
};
|
||||
|
||||
/**
|
||||
* @typedef {Object} columnConfig
|
||||
* @property {string} alignment
|
||||
* @property {number} width
|
||||
* @property {number} truncate
|
||||
* @property {number} paddingLeft
|
||||
* @property {number} paddingRight
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} streamConfig
|
||||
* @property {columnConfig} columnDefault
|
||||
* @property {Object} border
|
||||
* @property {columnConfig[]}
|
||||
* @property {number} columnCount Number of columns in the table (required).
|
||||
*/
|
||||
|
||||
/**
|
||||
* Makes a new configuration object out of the userConfig object
|
||||
* using default values for the missing configuration properties.
|
||||
*
|
||||
* @param {streamConfig} userConfig
|
||||
* @returns {Object}
|
||||
*/
|
||||
export default (userConfig = {}) => {
|
||||
validateConfig('streamConfig.json', userConfig);
|
||||
|
||||
const config = _.cloneDeep(userConfig);
|
||||
|
||||
if (!config.columnDefault || !config.columnDefault.width) {
|
||||
throw new Error('Must provide config.columnDefault.width when creating a stream.');
|
||||
}
|
||||
|
||||
if (!config.columnCount) {
|
||||
throw new Error('Must provide config.columnCount.');
|
||||
}
|
||||
|
||||
config.border = makeBorder(config.border);
|
||||
config.columns = makeColumns(config.columnCount, config.columns, config.columnDefault);
|
||||
|
||||
return config;
|
||||
};
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../src/makeStreamConfig.js"],"names":["makeBorder","border","Object","assign","makeColumns","columnCount","columns","columnDefault","_","times","index","isUndefined","alignment","paddingLeft","paddingRight","truncate","Infinity","wrapWord","userConfig","config","cloneDeep","width","Error"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;AAEA;;;;;;AAMA,MAAMA,UAAU,GAAG,CAACC,MAAM,GAAG,EAAV,KAAiB;AAClC,SAAOC,MAAM,CAACC,MAAP,CAAc,EAAd,EAAkB,kCAAoB,WAApB,CAAlB,EAAoDF,MAApD,CAAP;AACD,CAFD;AAIA;;;;;;;;;;;AASA,MAAMG,WAAW,GAAG,CAACC,WAAD,EAAcC,OAAO,GAAG,EAAxB,EAA4BC,aAAa,GAAG,EAA5C,KAAmD;AACrEC,kBAAEC,KAAF,CAAQJ,WAAR,EAAsBK,KAAD,IAAW;AAC9B,QAAIF,gBAAEG,WAAF,CAAcL,OAAO,CAACI,KAAD,CAArB,CAAJ,EAAmC;AACjCJ,MAAAA,OAAO,CAACI,KAAD,CAAP,GAAiB,EAAjB;AACD;;AAEDJ,IAAAA,OAAO,CAACI,KAAD,CAAP,GAAiBR,MAAM,CAACC,MAAP,CAAc;AAC7BS,MAAAA,SAAS,EAAE,MADkB;AAE7BC,MAAAA,WAAW,EAAE,CAFgB;AAG7BC,MAAAA,YAAY,EAAE,CAHe;AAI7BC,MAAAA,QAAQ,EAAEC,QAJmB;AAK7BC,MAAAA,QAAQ,EAAE;AALmB,KAAd,EAMdV,aANc,EAMCD,OAAO,CAACI,KAAD,CANR,CAAjB;AAOD,GAZD;;AAcA,SAAOJ,OAAP;AACD,CAhBD;AAkBA;;;;;;;;;AASA;;;;;;;;AAQA;;;;;;;;;0BAOgBY,UAAU,GAAG,E,KAAO;AAClC,+BAAe,mBAAf,EAAoCA,UAApC;;AAEA,QAAMC,MAAM,GAAGX,gBAAEY,SAAF,CAAYF,UAAZ,CAAf;;AAEA,MAAI,CAACC,MAAM,CAACZ,aAAR,IAAyB,CAACY,MAAM,CAACZ,aAAP,CAAqBc,KAAnD,EAA0D;AACxD,UAAM,IAAIC,KAAJ,CAAU,iEAAV,CAAN;AACD;;AAED,MAAI,CAACH,MAAM,CAACd,WAAZ,EAAyB;AACvB,UAAM,IAAIiB,KAAJ,CAAU,kCAAV,CAAN;AACD;;AAEDH,EAAAA,MAAM,CAAClB,MAAP,GAAgBD,UAAU,CAACmB,MAAM,CAAClB,MAAR,CAA1B;AACAkB,EAAAA,MAAM,CAACb,OAAP,GAAiBF,WAAW,CAACe,MAAM,CAACd,WAAR,EAAqBc,MAAM,CAACb,OAA5B,EAAqCa,MAAM,CAACZ,aAA5C,CAA5B;AAEA,SAAOY,MAAP;AACD,C","sourcesContent":["import _ from 'lodash';\nimport getBorderCharacters from './getBorderCharacters';\nimport validateConfig from './validateConfig';\n\n/**\n * Merges user provided border characters with the default border (\"honeywell\") characters.\n *\n * @param {Object} border\n * @returns {Object}\n */\nconst makeBorder = (border = {}) => {\n return Object.assign({}, getBorderCharacters('honeywell'), border);\n};\n\n/**\n * Creates a configuration for every column using default\n * values for the missing configuration properties.\n *\n * @param {number} columnCount\n * @param {Object} columns\n * @param {Object} columnDefault\n * @returns {Object}\n */\nconst makeColumns = (columnCount, columns = {}, columnDefault = {}) => {\n _.times(columnCount, (index) => {\n if (_.isUndefined(columns[index])) {\n columns[index] = {};\n }\n\n columns[index] = Object.assign({\n alignment: 'left',\n paddingLeft: 1,\n paddingRight: 1,\n truncate: Infinity,\n wrapWord: false\n }, columnDefault, columns[index]);\n });\n\n return columns;\n};\n\n/**\n * @typedef {Object} columnConfig\n * @property {string} alignment\n * @property {number} width\n * @property {number} truncate\n * @property {number} paddingLeft\n * @property {number} paddingRight\n */\n\n/**\n * @typedef {Object} streamConfig\n * @property {columnConfig} columnDefault\n * @property {Object} border\n * @property {columnConfig[]}\n * @property {number} columnCount Number of columns in the table (required).\n */\n\n/**\n * Makes a new configuration object out of the userConfig object\n * using default values for the missing configuration properties.\n *\n * @param {streamConfig} userConfig\n * @returns {Object}\n */\nexport default (userConfig = {}) => {\n validateConfig('streamConfig.json', userConfig);\n\n const config = _.cloneDeep(userConfig);\n\n if (!config.columnDefault || !config.columnDefault.width) {\n throw new Error('Must provide config.columnDefault.width when creating a stream.');\n }\n\n if (!config.columnCount) {\n throw new Error('Must provide config.columnCount.');\n }\n\n config.border = makeBorder(config.border);\n config.columns = makeColumns(config.columnCount, config.columns, config.columnDefault);\n\n return config;\n};\n"],"file":"makeStreamConfig.js"}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _lodash = _interopRequireDefault(require("lodash"));
|
||||
|
||||
var _wrapString = _interopRequireDefault(require("./wrapString"));
|
||||
|
||||
var _wrapWord = _interopRequireDefault(require("./wrapWord"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @param {Array} unmappedRows
|
||||
* @param {number[]} rowHeightIndex
|
||||
* @param {Object} config
|
||||
* @returns {Array}
|
||||
*/
|
||||
const mapDataUsingRowHeightIndex = (unmappedRows, rowHeightIndex, config) => {
|
||||
const tableWidth = unmappedRows[0].length;
|
||||
const mappedRows = unmappedRows.map((cells, index0) => {
|
||||
const rowHeight = _lodash.default.times(rowHeightIndex[index0], () => {
|
||||
return new Array(tableWidth).fill('');
|
||||
}); // rowHeight
|
||||
// [{row index within rowSaw; index2}]
|
||||
// [{cell index within a virtual row; index1}]
|
||||
|
||||
|
||||
cells.forEach((value, index1) => {
|
||||
let chunkedValue;
|
||||
|
||||
if (config.columns[index1].wrapWord) {
|
||||
chunkedValue = (0, _wrapWord.default)(value, config.columns[index1].width);
|
||||
} else {
|
||||
chunkedValue = (0, _wrapString.default)(value, config.columns[index1].width);
|
||||
}
|
||||
|
||||
chunkedValue.forEach((part, index2) => {
|
||||
rowHeight[index2][index1] = part;
|
||||
});
|
||||
});
|
||||
return rowHeight;
|
||||
});
|
||||
return _lodash.default.flatten(mappedRows);
|
||||
};
|
||||
|
||||
var _default = mapDataUsingRowHeightIndex;
|
||||
exports.default = _default;
|
||||
//# sourceMappingURL=mapDataUsingRowHeightIndex.js.map
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
import _ from 'lodash';
|
||||
import wrapString from './wrapString';
|
||||
import wrapWord from './wrapWord';
|
||||
|
||||
/**
|
||||
* @param {Array} unmappedRows
|
||||
* @param {number[]} rowHeightIndex
|
||||
* @param {Object} config
|
||||
* @returns {Array}
|
||||
*/
|
||||
export default (unmappedRows, rowHeightIndex, config) => {
|
||||
const tableWidth = unmappedRows[0].length;
|
||||
|
||||
const mappedRows = unmappedRows.map((cells, index0) => {
|
||||
const rowHeight = _.times(rowHeightIndex[index0], () => {
|
||||
return new Array(tableWidth).fill('');
|
||||
});
|
||||
|
||||
// rowHeight
|
||||
// [{row index within rowSaw; index2}]
|
||||
// [{cell index within a virtual row; index1}]
|
||||
|
||||
cells.forEach((value, index1) => {
|
||||
let chunkedValue;
|
||||
|
||||
if (config.columns[index1].wrapWord) {
|
||||
chunkedValue = wrapWord(value, config.columns[index1].width);
|
||||
} else {
|
||||
chunkedValue = wrapString(value, config.columns[index1].width);
|
||||
}
|
||||
|
||||
chunkedValue.forEach((part, index2) => {
|
||||
rowHeight[index2][index1] = part;
|
||||
});
|
||||
});
|
||||
|
||||
return rowHeight;
|
||||
});
|
||||
|
||||
return _.flatten(mappedRows);
|
||||
};
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../src/mapDataUsingRowHeightIndex.js"],"names":["unmappedRows","rowHeightIndex","config","tableWidth","length","mappedRows","map","cells","index0","rowHeight","_","times","Array","fill","forEach","value","index1","chunkedValue","columns","wrapWord","width","part","index2","flatten"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;AAEA;;;;;;oCAMgBA,Y,EAAcC,c,EAAgBC,M,KAAW;AACvD,QAAMC,UAAU,GAAGH,YAAY,CAAC,CAAD,CAAZ,CAAgBI,MAAnC;AAEA,QAAMC,UAAU,GAAGL,YAAY,CAACM,GAAb,CAAiB,CAACC,KAAD,EAAQC,MAAR,KAAmB;AACrD,UAAMC,SAAS,GAAGC,gBAAEC,KAAF,CAAQV,cAAc,CAACO,MAAD,CAAtB,EAAgC,MAAM;AACtD,aAAO,IAAII,KAAJ,CAAUT,UAAV,EAAsBU,IAAtB,CAA2B,EAA3B,CAAP;AACD,KAFiB,CAAlB,CADqD,CAKrD;AACA;AACA;;;AAEAN,IAAAA,KAAK,CAACO,OAAN,CAAc,CAACC,KAAD,EAAQC,MAAR,KAAmB;AAC/B,UAAIC,YAAJ;;AAEA,UAAIf,MAAM,CAACgB,OAAP,CAAeF,MAAf,EAAuBG,QAA3B,EAAqC;AACnCF,QAAAA,YAAY,GAAG,uBAASF,KAAT,EAAgBb,MAAM,CAACgB,OAAP,CAAeF,MAAf,EAAuBI,KAAvC,CAAf;AACD,OAFD,MAEO;AACLH,QAAAA,YAAY,GAAG,yBAAWF,KAAX,EAAkBb,MAAM,CAACgB,OAAP,CAAeF,MAAf,EAAuBI,KAAzC,CAAf;AACD;;AAEDH,MAAAA,YAAY,CAACH,OAAb,CAAqB,CAACO,IAAD,EAAOC,MAAP,KAAkB;AACrCb,QAAAA,SAAS,CAACa,MAAD,CAAT,CAAkBN,MAAlB,IAA4BK,IAA5B;AACD,OAFD;AAGD,KAZD;AAcA,WAAOZ,SAAP;AACD,GAxBkB,CAAnB;AA0BA,SAAOC,gBAAEa,OAAF,CAAUlB,UAAV,CAAP;AACD,C","sourcesContent":["import _ from 'lodash';\nimport wrapString from './wrapString';\nimport wrapWord from './wrapWord';\n\n/**\n * @param {Array} unmappedRows\n * @param {number[]} rowHeightIndex\n * @param {Object} config\n * @returns {Array}\n */\nexport default (unmappedRows, rowHeightIndex, config) => {\n const tableWidth = unmappedRows[0].length;\n\n const mappedRows = unmappedRows.map((cells, index0) => {\n const rowHeight = _.times(rowHeightIndex[index0], () => {\n return new Array(tableWidth).fill('');\n });\n\n // rowHeight\n // [{row index within rowSaw; index2}]\n // [{cell index within a virtual row; index1}]\n\n cells.forEach((value, index1) => {\n let chunkedValue;\n\n if (config.columns[index1].wrapWord) {\n chunkedValue = wrapWord(value, config.columns[index1].width);\n } else {\n chunkedValue = wrapString(value, config.columns[index1].width);\n }\n\n chunkedValue.forEach((part, index2) => {\n rowHeight[index2][index1] = part;\n });\n });\n\n return rowHeight;\n });\n\n return _.flatten(mappedRows);\n};\n"],"file":"mapDataUsingRowHeightIndex.js"}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
/**
|
||||
* @param {table~row[]} rows
|
||||
* @param {Object} config
|
||||
* @returns {table~row[]}
|
||||
*/
|
||||
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);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
var _default = padTableData;
|
||||
exports.default = _default;
|
||||
//# sourceMappingURL=padTableData.js.map
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* @param {table~row[]} rows
|
||||
* @param {Object} config
|
||||
* @returns {table~row[]}
|
||||
*/
|
||||
export default (rows, config) => {
|
||||
return rows.map((cells) => {
|
||||
return cells.map((value, index1) => {
|
||||
const column = config.columns[index1];
|
||||
|
||||
return ' '.repeat(column.paddingLeft) + value + ' '.repeat(column.paddingRight);
|
||||
});
|
||||
});
|
||||
};
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../src/padTableData.js"],"names":["rows","config","map","cells","value","index1","column","columns","repeat","paddingLeft","paddingRight"],"mappings":";;;;;;;AAAA;;;;;sBAKgBA,I,EAAMC,M,KAAW;AAC/B,SAAOD,IAAI,CAACE,GAAL,CAAUC,KAAD,IAAW;AACzB,WAAOA,KAAK,CAACD,GAAN,CAAU,CAACE,KAAD,EAAQC,MAAR,KAAmB;AAClC,YAAMC,MAAM,GAAGL,MAAM,CAACM,OAAP,CAAeF,MAAf,CAAf;AAEA,aAAO,IAAIG,MAAJ,CAAWF,MAAM,CAACG,WAAlB,IAAiCL,KAAjC,GAAyC,IAAII,MAAJ,CAAWF,MAAM,CAACI,YAAlB,CAAhD;AACD,KAJM,CAAP;AAKD,GANM,CAAP;AAOD,C","sourcesContent":["/**\n * @param {table~row[]} rows\n * @param {Object} config\n * @returns {table~row[]}\n */\nexport default (rows, config) => {\n return rows.map((cells) => {\n return cells.map((value, index1) => {\n const column = config.columns[index1];\n\n return ' '.repeat(column.paddingLeft) + value + ' '.repeat(column.paddingRight);\n });\n });\n};\n"],"file":"padTableData.js"}
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
{
|
||||
"$id": "config.json",
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"border": {
|
||||
"$ref": "#/definitions/borders"
|
||||
},
|
||||
"columns": {
|
||||
"$ref": "#/definitions/columns"
|
||||
},
|
||||
"columnDefault": {
|
||||
"$ref": "#/definitions/column"
|
||||
},
|
||||
"drawHorizontalLine": {
|
||||
"typeof": "function"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"definitions": {
|
||||
"columns": {
|
||||
"type": "object",
|
||||
"patternProperties": {
|
||||
"^[0-9]+$": {
|
||||
"$ref": "#/definitions/column"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"column": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"alignment": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"left",
|
||||
"right",
|
||||
"center"
|
||||
]
|
||||
},
|
||||
"width": {
|
||||
"type": "number"
|
||||
},
|
||||
"wrapWord": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"truncate": {
|
||||
"type": "number"
|
||||
},
|
||||
"paddingLeft": {
|
||||
"type": "number"
|
||||
},
|
||||
"paddingRight": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"borders": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"topBody": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"topJoin": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"topLeft": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"topRight": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bottomBody": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bottomJoin": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bottomLeft": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bottomRight": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bodyLeft": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bodyRight": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bodyJoin": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"joinBody": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"joinLeft": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"joinRight": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"joinJoin": {
|
||||
"$ref": "#/definitions/border"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"border": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
{
|
||||
"$id": "streamConfig.json",
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"border": {
|
||||
"$ref": "#/definitions/borders"
|
||||
},
|
||||
"columns": {
|
||||
"$ref": "#/definitions/columns"
|
||||
},
|
||||
"columnDefault": {
|
||||
"$ref": "#/definitions/column"
|
||||
},
|
||||
"columnCount": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"definitions": {
|
||||
"columns": {
|
||||
"type": "object",
|
||||
"patternProperties": {
|
||||
"^[0-9]+$": {
|
||||
"$ref": "#/definitions/column"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"column": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"alignment": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"left",
|
||||
"right",
|
||||
"center"
|
||||
]
|
||||
},
|
||||
"width": {
|
||||
"type": "number"
|
||||
},
|
||||
"wrapWord": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"truncate": {
|
||||
"type": "number"
|
||||
},
|
||||
"paddingLeft": {
|
||||
"type": "number"
|
||||
},
|
||||
"paddingRight": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"borders": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"topBody": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"topJoin": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"topLeft": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"topRight": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bottomBody": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bottomJoin": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bottomLeft": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bottomRight": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bodyLeft": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bodyRight": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bodyJoin": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"joinBody": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"joinLeft": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"joinRight": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"joinJoin": {
|
||||
"$ref": "#/definitions/border"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"border": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
/**
|
||||
* Casts all cell values to a string.
|
||||
*
|
||||
* @param {table~row[]} rows
|
||||
* @returns {table~row[]}
|
||||
*/
|
||||
const stringifyTableData = rows => {
|
||||
return rows.map(cells => {
|
||||
return cells.map(String);
|
||||
});
|
||||
};
|
||||
|
||||
var _default = stringifyTableData;
|
||||
exports.default = _default;
|
||||
//# sourceMappingURL=stringifyTableData.js.map
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Casts all cell values to a string.
|
||||
*
|
||||
* @param {table~row[]} rows
|
||||
* @returns {table~row[]}
|
||||
*/
|
||||
export default (rows) => {
|
||||
return rows.map((cells) => {
|
||||
return cells.map(String);
|
||||
});
|
||||
};
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../src/stringifyTableData.js"],"names":["rows","map","cells","String"],"mappings":";;;;;;;AAAA;;;;;;2BAMgBA,I,IAAS;AACvB,SAAOA,IAAI,CAACC,GAAL,CAAUC,KAAD,IAAW;AACzB,WAAOA,KAAK,CAACD,GAAN,CAAUE,MAAV,CAAP;AACD,GAFM,CAAP;AAGD,C","sourcesContent":["/**\n * Casts all cell values to a string.\n *\n * @param {table~row[]} rows\n * @returns {table~row[]}\n */\nexport default (rows) => {\n return rows.map((cells) => {\n return cells.map(String);\n });\n};\n"],"file":"stringifyTableData.js"}
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _drawTable = _interopRequireDefault(require("./drawTable"));
|
||||
|
||||
var _calculateCellWidthIndex = _interopRequireDefault(require("./calculateCellWidthIndex"));
|
||||
|
||||
var _makeConfig = _interopRequireDefault(require("./makeConfig"));
|
||||
|
||||
var _calculateRowHeightIndex = _interopRequireDefault(require("./calculateRowHeightIndex"));
|
||||
|
||||
var _mapDataUsingRowHeightIndex = _interopRequireDefault(require("./mapDataUsingRowHeightIndex"));
|
||||
|
||||
var _alignTableData = _interopRequireDefault(require("./alignTableData"));
|
||||
|
||||
var _padTableData = _interopRequireDefault(require("./padTableData"));
|
||||
|
||||
var _validateTableData = _interopRequireDefault(require("./validateTableData"));
|
||||
|
||||
var _stringifyTableData = _interopRequireDefault(require("./stringifyTableData"));
|
||||
|
||||
var _truncateTableData = _interopRequireDefault(require("./truncateTableData"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @typedef {string} table~cell
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {table~cell[]} table~row
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} table~columns
|
||||
* @property {string} alignment Cell content alignment (enum: left, center, right) (default: left).
|
||||
* @property {number} width Column width (default: auto).
|
||||
* @property {number} truncate Number of characters are which the content will be truncated (default: Infinity).
|
||||
* @property {boolean} wrapWord When true the text is broken at the nearest space or one of the special characters
|
||||
* @property {number} paddingLeft Cell content padding width left (default: 1).
|
||||
* @property {number} paddingRight Cell content padding width right (default: 1).
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} table~border
|
||||
* @property {string} topBody
|
||||
* @property {string} topJoin
|
||||
* @property {string} topLeft
|
||||
* @property {string} topRight
|
||||
* @property {string} bottomBody
|
||||
* @property {string} bottomJoin
|
||||
* @property {string} bottomLeft
|
||||
* @property {string} bottomRight
|
||||
* @property {string} bodyLeft
|
||||
* @property {string} bodyRight
|
||||
* @property {string} bodyJoin
|
||||
* @property {string} joinBody
|
||||
* @property {string} joinLeft
|
||||
* @property {string} joinRight
|
||||
* @property {string} joinJoin
|
||||
*/
|
||||
|
||||
/**
|
||||
* Used to tell whether to draw a horizontal line.
|
||||
* This callback is called for each non-content line of the table.
|
||||
* The default behavior is to always return true.
|
||||
*
|
||||
* @typedef {Function} drawHorizontalLine
|
||||
* @param {number} index
|
||||
* @param {number} size
|
||||
* @returns {boolean}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} table~config
|
||||
* @property {table~border} border
|
||||
* @property {table~columns[]} columns Column specific configuration.
|
||||
* @property {table~columns} columnDefault Default values for all columns. Column specific settings overwrite the default values.
|
||||
* @property {table~drawHorizontalLine} drawHorizontalLine
|
||||
*/
|
||||
|
||||
/**
|
||||
* Generates a text table.
|
||||
*
|
||||
* @param {table~row[]} data
|
||||
* @param {table~config} userConfig
|
||||
* @returns {string}
|
||||
*/
|
||||
const table = (data, userConfig = {}) => {
|
||||
let rows;
|
||||
(0, _validateTableData.default)(data);
|
||||
rows = (0, _stringifyTableData.default)(data);
|
||||
const config = (0, _makeConfig.default)(rows, userConfig);
|
||||
rows = (0, _truncateTableData.default)(data, config);
|
||||
const rowHeightIndex = (0, _calculateRowHeightIndex.default)(rows, config);
|
||||
rows = (0, _mapDataUsingRowHeightIndex.default)(rows, rowHeightIndex, config);
|
||||
rows = (0, _alignTableData.default)(rows, config);
|
||||
rows = (0, _padTableData.default)(rows, config);
|
||||
const cellWidthIndex = (0, _calculateCellWidthIndex.default)(rows[0]);
|
||||
return (0, _drawTable.default)(rows, config.border, cellWidthIndex, rowHeightIndex, config.drawHorizontalLine);
|
||||
};
|
||||
|
||||
var _default = table;
|
||||
exports.default = _default;
|
||||
//# sourceMappingURL=table.js.map
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
import drawTable from './drawTable';
|
||||
import calculateCellWidthIndex from './calculateCellWidthIndex';
|
||||
import makeConfig from './makeConfig';
|
||||
import calculateRowHeightIndex from './calculateRowHeightIndex';
|
||||
import mapDataUsingRowHeightIndex from './mapDataUsingRowHeightIndex';
|
||||
import alignTableData from './alignTableData';
|
||||
import padTableData from './padTableData';
|
||||
import validateTableData from './validateTableData';
|
||||
import stringifyTableData from './stringifyTableData';
|
||||
import truncateTableData from './truncateTableData';
|
||||
|
||||
/**
|
||||
* @typedef {string} table~cell
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {table~cell[]} table~row
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} table~columns
|
||||
* @property {string} alignment Cell content alignment (enum: left, center, right) (default: left).
|
||||
* @property {number} width Column width (default: auto).
|
||||
* @property {number} truncate Number of characters are which the content will be truncated (default: Infinity).
|
||||
* @property {boolean} wrapWord When true the text is broken at the nearest space or one of the special characters
|
||||
* @property {number} paddingLeft Cell content padding width left (default: 1).
|
||||
* @property {number} paddingRight Cell content padding width right (default: 1).
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} table~border
|
||||
* @property {string} topBody
|
||||
* @property {string} topJoin
|
||||
* @property {string} topLeft
|
||||
* @property {string} topRight
|
||||
* @property {string} bottomBody
|
||||
* @property {string} bottomJoin
|
||||
* @property {string} bottomLeft
|
||||
* @property {string} bottomRight
|
||||
* @property {string} bodyLeft
|
||||
* @property {string} bodyRight
|
||||
* @property {string} bodyJoin
|
||||
* @property {string} joinBody
|
||||
* @property {string} joinLeft
|
||||
* @property {string} joinRight
|
||||
* @property {string} joinJoin
|
||||
*/
|
||||
|
||||
/**
|
||||
* Used to tell whether to draw a horizontal line.
|
||||
* This callback is called for each non-content line of the table.
|
||||
* The default behavior is to always return true.
|
||||
*
|
||||
* @typedef {Function} drawHorizontalLine
|
||||
* @param {number} index
|
||||
* @param {number} size
|
||||
* @returns {boolean}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} table~config
|
||||
* @property {table~border} border
|
||||
* @property {table~columns[]} columns Column specific configuration.
|
||||
* @property {table~columns} columnDefault Default values for all columns. Column specific settings overwrite the default values.
|
||||
* @property {table~drawHorizontalLine} drawHorizontalLine
|
||||
*/
|
||||
|
||||
/**
|
||||
* Generates a text table.
|
||||
*
|
||||
* @param {table~row[]} data
|
||||
* @param {table~config} userConfig
|
||||
* @returns {string}
|
||||
*/
|
||||
export default (data, userConfig = {}) => {
|
||||
let rows;
|
||||
|
||||
validateTableData(data);
|
||||
|
||||
rows = stringifyTableData(data);
|
||||
|
||||
const config = makeConfig(rows, userConfig);
|
||||
|
||||
rows = truncateTableData(data, config);
|
||||
|
||||
const rowHeightIndex = calculateRowHeightIndex(rows, config);
|
||||
|
||||
rows = mapDataUsingRowHeightIndex(rows, rowHeightIndex, config);
|
||||
rows = alignTableData(rows, config);
|
||||
rows = padTableData(rows, config);
|
||||
|
||||
const cellWidthIndex = calculateCellWidthIndex(rows[0]);
|
||||
|
||||
return drawTable(rows, config.border, cellWidthIndex, rowHeightIndex, config.drawHorizontalLine);
|
||||
};
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../src/table.js"],"names":["data","userConfig","rows","config","rowHeightIndex","cellWidthIndex","border","drawHorizontalLine"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;AAEA;;;;AAIA;;;;AAIA;;;;;;;;;;AAUA;;;;;;;;;;;;;;;;;;;AAmBA;;;;;;;;;;;AAWA;;;;;;;;AAQA;;;;;;;eAOgBA,I,EAAMC,UAAU,GAAG,E,KAAO;AACxC,MAAIC,IAAJ;AAEA,kCAAkBF,IAAlB;AAEAE,EAAAA,IAAI,GAAG,iCAAmBF,IAAnB,CAAP;AAEA,QAAMG,MAAM,GAAG,yBAAWD,IAAX,EAAiBD,UAAjB,CAAf;AAEAC,EAAAA,IAAI,GAAG,gCAAkBF,IAAlB,EAAwBG,MAAxB,CAAP;AAEA,QAAMC,cAAc,GAAG,sCAAwBF,IAAxB,EAA8BC,MAA9B,CAAvB;AAEAD,EAAAA,IAAI,GAAG,yCAA2BA,IAA3B,EAAiCE,cAAjC,EAAiDD,MAAjD,CAAP;AACAD,EAAAA,IAAI,GAAG,6BAAeA,IAAf,EAAqBC,MAArB,CAAP;AACAD,EAAAA,IAAI,GAAG,2BAAaA,IAAb,EAAmBC,MAAnB,CAAP;AAEA,QAAME,cAAc,GAAG,sCAAwBH,IAAI,CAAC,CAAD,CAA5B,CAAvB;AAEA,SAAO,wBAAUA,IAAV,EAAgBC,MAAM,CAACG,MAAvB,EAA+BD,cAA/B,EAA+CD,cAA/C,EAA+DD,MAAM,CAACI,kBAAtE,CAAP;AACD,C","sourcesContent":["import drawTable from './drawTable';\nimport calculateCellWidthIndex from './calculateCellWidthIndex';\nimport makeConfig from './makeConfig';\nimport calculateRowHeightIndex from './calculateRowHeightIndex';\nimport mapDataUsingRowHeightIndex from './mapDataUsingRowHeightIndex';\nimport alignTableData from './alignTableData';\nimport padTableData from './padTableData';\nimport validateTableData from './validateTableData';\nimport stringifyTableData from './stringifyTableData';\nimport truncateTableData from './truncateTableData';\n\n/**\n * @typedef {string} table~cell\n */\n\n/**\n * @typedef {table~cell[]} table~row\n */\n\n/**\n * @typedef {Object} table~columns\n * @property {string} alignment Cell content alignment (enum: left, center, right) (default: left).\n * @property {number} width Column width (default: auto).\n * @property {number} truncate Number of characters are which the content will be truncated (default: Infinity).\n * @property {boolean} wrapWord When true the text is broken at the nearest space or one of the special characters\n * @property {number} paddingLeft Cell content padding width left (default: 1).\n * @property {number} paddingRight Cell content padding width right (default: 1).\n */\n\n/**\n * @typedef {Object} table~border\n * @property {string} topBody\n * @property {string} topJoin\n * @property {string} topLeft\n * @property {string} topRight\n * @property {string} bottomBody\n * @property {string} bottomJoin\n * @property {string} bottomLeft\n * @property {string} bottomRight\n * @property {string} bodyLeft\n * @property {string} bodyRight\n * @property {string} bodyJoin\n * @property {string} joinBody\n * @property {string} joinLeft\n * @property {string} joinRight\n * @property {string} joinJoin\n */\n\n/**\n * Used to tell whether to draw a horizontal line.\n * This callback is called for each non-content line of the table.\n * The default behavior is to always return true.\n *\n * @typedef {Function} drawHorizontalLine\n * @param {number} index\n * @param {number} size\n * @returns {boolean}\n */\n\n/**\n * @typedef {Object} table~config\n * @property {table~border} border\n * @property {table~columns[]} columns Column specific configuration.\n * @property {table~columns} columnDefault Default values for all columns. Column specific settings overwrite the default values.\n * @property {table~drawHorizontalLine} drawHorizontalLine\n */\n\n/**\n * Generates a text table.\n *\n * @param {table~row[]} data\n * @param {table~config} userConfig\n * @returns {string}\n */\nexport default (data, userConfig = {}) => {\n let rows;\n\n validateTableData(data);\n\n rows = stringifyTableData(data);\n\n const config = makeConfig(rows, userConfig);\n\n rows = truncateTableData(data, config);\n\n const rowHeightIndex = calculateRowHeightIndex(rows, config);\n\n rows = mapDataUsingRowHeightIndex(rows, rowHeightIndex, config);\n rows = alignTableData(rows, config);\n rows = padTableData(rows, config);\n\n const cellWidthIndex = calculateCellWidthIndex(rows[0]);\n\n return drawTable(rows, config.border, cellWidthIndex, rowHeightIndex, config.drawHorizontalLine);\n};\n"],"file":"table.js"}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _lodash = _interopRequireDefault(require("lodash"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @todo Make it work with ASCII content.
|
||||
* @param {table~row[]} rows
|
||||
* @param {Object} config
|
||||
* @returns {table~row[]}
|
||||
*/
|
||||
const truncateTableData = (rows, config) => {
|
||||
return rows.map(cells => {
|
||||
return cells.map((content, index) => {
|
||||
return _lodash.default.truncate(content, {
|
||||
length: config.columns[index].truncate
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
var _default = truncateTableData;
|
||||
exports.default = _default;
|
||||
//# sourceMappingURL=truncateTableData.js.map
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
import _ from 'lodash';
|
||||
|
||||
/**
|
||||
* @todo Make it work with ASCII content.
|
||||
* @param {table~row[]} rows
|
||||
* @param {Object} config
|
||||
* @returns {table~row[]}
|
||||
*/
|
||||
export default (rows, config) => {
|
||||
return rows.map((cells) => {
|
||||
return cells.map((content, index) => {
|
||||
return _.truncate(content, {
|
||||
length: config.columns[index].truncate
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../src/truncateTableData.js"],"names":["rows","config","map","cells","content","index","_","truncate","length","columns"],"mappings":";;;;;;;AAAA;;;;AAEA;;;;;;2BAMgBA,I,EAAMC,M,KAAW;AAC/B,SAAOD,IAAI,CAACE,GAAL,CAAUC,KAAD,IAAW;AACzB,WAAOA,KAAK,CAACD,GAAN,CAAU,CAACE,OAAD,EAAUC,KAAV,KAAoB;AACnC,aAAOC,gBAAEC,QAAF,CAAWH,OAAX,EAAoB;AACzBI,QAAAA,MAAM,EAAEP,MAAM,CAACQ,OAAP,CAAeJ,KAAf,EAAsBE;AADL,OAApB,CAAP;AAGD,KAJM,CAAP;AAKD,GANM,CAAP;AAOD,C","sourcesContent":["import _ from 'lodash';\n\n/**\n * @todo Make it work with ASCII content.\n * @param {table~row[]} rows\n * @param {Object} config\n * @returns {table~row[]}\n */\nexport default (rows, config) => {\n return rows.map((cells) => {\n return cells.map((content, index) => {\n return _.truncate(content, {\n length: config.columns[index].truncate\n });\n });\n });\n};\n"],"file":"truncateTableData.js"}
|
||||
+752
@@ -0,0 +1,752 @@
|
||||
'use strict';
|
||||
var equal = require('ajv/lib/compile/equal');
|
||||
var validate = (function() {
|
||||
var pattern0 = new RegExp('^[0-9]+$');
|
||||
var refVal = [];
|
||||
var refVal1 = (function() {
|
||||
var pattern0 = new RegExp('^[0-9]+$');
|
||||
return function validate(data, dataPath, parentData, parentDataProperty, rootData) {
|
||||
'use strict';
|
||||
var vErrors = null;
|
||||
var errors = 0;
|
||||
if (rootData === undefined) rootData = data;
|
||||
if ((data && typeof data === "object" && !Array.isArray(data))) {
|
||||
var errs__0 = errors;
|
||||
var valid1 = true;
|
||||
for (var key0 in data) {
|
||||
var isAdditional0 = !(false || validate.schema.properties.hasOwnProperty(key0));
|
||||
if (isAdditional0) {
|
||||
valid1 = false;
|
||||
var err = {
|
||||
keyword: 'additionalProperties',
|
||||
dataPath: (dataPath || '') + "",
|
||||
schemaPath: '#/additionalProperties',
|
||||
params: {
|
||||
additionalProperty: '' + key0 + ''
|
||||
},
|
||||
message: 'should NOT have additional properties'
|
||||
};
|
||||
if (vErrors === null) vErrors = [err];
|
||||
else vErrors.push(err);
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (data.topBody !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal2(data.topBody, (dataPath || '') + '.topBody', data, 'topBody', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal2.errors;
|
||||
else vErrors = vErrors.concat(refVal2.errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.topJoin !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal[2](data.topJoin, (dataPath || '') + '.topJoin', data, 'topJoin', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal[2].errors;
|
||||
else vErrors = vErrors.concat(refVal[2].errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.topLeft !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal[2](data.topLeft, (dataPath || '') + '.topLeft', data, 'topLeft', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal[2].errors;
|
||||
else vErrors = vErrors.concat(refVal[2].errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.topRight !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal[2](data.topRight, (dataPath || '') + '.topRight', data, 'topRight', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal[2].errors;
|
||||
else vErrors = vErrors.concat(refVal[2].errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.bottomBody !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal[2](data.bottomBody, (dataPath || '') + '.bottomBody', data, 'bottomBody', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal[2].errors;
|
||||
else vErrors = vErrors.concat(refVal[2].errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.bottomJoin !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal[2](data.bottomJoin, (dataPath || '') + '.bottomJoin', data, 'bottomJoin', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal[2].errors;
|
||||
else vErrors = vErrors.concat(refVal[2].errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.bottomLeft !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal[2](data.bottomLeft, (dataPath || '') + '.bottomLeft', data, 'bottomLeft', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal[2].errors;
|
||||
else vErrors = vErrors.concat(refVal[2].errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.bottomRight !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal[2](data.bottomRight, (dataPath || '') + '.bottomRight', data, 'bottomRight', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal[2].errors;
|
||||
else vErrors = vErrors.concat(refVal[2].errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.bodyLeft !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal[2](data.bodyLeft, (dataPath || '') + '.bodyLeft', data, 'bodyLeft', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal[2].errors;
|
||||
else vErrors = vErrors.concat(refVal[2].errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.bodyRight !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal[2](data.bodyRight, (dataPath || '') + '.bodyRight', data, 'bodyRight', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal[2].errors;
|
||||
else vErrors = vErrors.concat(refVal[2].errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.bodyJoin !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal[2](data.bodyJoin, (dataPath || '') + '.bodyJoin', data, 'bodyJoin', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal[2].errors;
|
||||
else vErrors = vErrors.concat(refVal[2].errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.joinBody !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal[2](data.joinBody, (dataPath || '') + '.joinBody', data, 'joinBody', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal[2].errors;
|
||||
else vErrors = vErrors.concat(refVal[2].errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.joinLeft !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal[2](data.joinLeft, (dataPath || '') + '.joinLeft', data, 'joinLeft', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal[2].errors;
|
||||
else vErrors = vErrors.concat(refVal[2].errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.joinRight !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal[2](data.joinRight, (dataPath || '') + '.joinRight', data, 'joinRight', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal[2].errors;
|
||||
else vErrors = vErrors.concat(refVal[2].errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.joinJoin !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal[2](data.joinJoin, (dataPath || '') + '.joinJoin', data, 'joinJoin', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal[2].errors;
|
||||
else vErrors = vErrors.concat(refVal[2].errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
} else {
|
||||
var err = {
|
||||
keyword: 'type',
|
||||
dataPath: (dataPath || '') + "",
|
||||
schemaPath: '#/type',
|
||||
params: {
|
||||
type: 'object'
|
||||
},
|
||||
message: 'should be object'
|
||||
};
|
||||
if (vErrors === null) vErrors = [err];
|
||||
else vErrors.push(err);
|
||||
errors++;
|
||||
}
|
||||
validate.errors = vErrors;
|
||||
return errors === 0;
|
||||
};
|
||||
})();
|
||||
refVal1.schema = {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"topBody": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"topJoin": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"topLeft": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"topRight": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bottomBody": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bottomJoin": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bottomLeft": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bottomRight": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bodyLeft": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bodyRight": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bodyJoin": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"joinBody": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"joinLeft": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"joinRight": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"joinJoin": {
|
||||
"$ref": "#/definitions/border"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
};
|
||||
refVal1.errors = null;
|
||||
refVal[1] = refVal1;
|
||||
var refVal2 = (function() {
|
||||
var pattern0 = new RegExp('^[0-9]+$');
|
||||
return function validate(data, dataPath, parentData, parentDataProperty, rootData) {
|
||||
'use strict';
|
||||
var vErrors = null;
|
||||
var errors = 0;
|
||||
if (typeof data !== "string") {
|
||||
var err = {
|
||||
keyword: 'type',
|
||||
dataPath: (dataPath || '') + "",
|
||||
schemaPath: '#/type',
|
||||
params: {
|
||||
type: 'string'
|
||||
},
|
||||
message: 'should be string'
|
||||
};
|
||||
if (vErrors === null) vErrors = [err];
|
||||
else vErrors.push(err);
|
||||
errors++;
|
||||
}
|
||||
validate.errors = vErrors;
|
||||
return errors === 0;
|
||||
};
|
||||
})();
|
||||
refVal2.schema = {
|
||||
"type": "string"
|
||||
};
|
||||
refVal2.errors = null;
|
||||
refVal[2] = refVal2;
|
||||
var refVal3 = (function() {
|
||||
var pattern0 = new RegExp('^[0-9]+$');
|
||||
return function validate(data, dataPath, parentData, parentDataProperty, rootData) {
|
||||
'use strict';
|
||||
var vErrors = null;
|
||||
var errors = 0;
|
||||
if (rootData === undefined) rootData = data;
|
||||
if ((data && typeof data === "object" && !Array.isArray(data))) {
|
||||
var errs__0 = errors;
|
||||
var valid1 = true;
|
||||
for (var key0 in data) {
|
||||
var isAdditional0 = !(false || pattern0.test(key0));
|
||||
if (isAdditional0) {
|
||||
valid1 = false;
|
||||
var err = {
|
||||
keyword: 'additionalProperties',
|
||||
dataPath: (dataPath || '') + "",
|
||||
schemaPath: '#/additionalProperties',
|
||||
params: {
|
||||
additionalProperty: '' + key0 + ''
|
||||
},
|
||||
message: 'should NOT have additional properties'
|
||||
};
|
||||
if (vErrors === null) vErrors = [err];
|
||||
else vErrors.push(err);
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
for (var key0 in data) {
|
||||
if (pattern0.test(key0)) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal4(data[key0], (dataPath || '') + '[\'' + key0 + '\']', data, key0, rootData)) {
|
||||
if (vErrors === null) vErrors = refVal4.errors;
|
||||
else vErrors = vErrors.concat(refVal4.errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var err = {
|
||||
keyword: 'type',
|
||||
dataPath: (dataPath || '') + "",
|
||||
schemaPath: '#/type',
|
||||
params: {
|
||||
type: 'object'
|
||||
},
|
||||
message: 'should be object'
|
||||
};
|
||||
if (vErrors === null) vErrors = [err];
|
||||
else vErrors.push(err);
|
||||
errors++;
|
||||
}
|
||||
validate.errors = vErrors;
|
||||
return errors === 0;
|
||||
};
|
||||
})();
|
||||
refVal3.schema = {
|
||||
"type": "object",
|
||||
"patternProperties": {
|
||||
"^[0-9]+$": {
|
||||
"$ref": "#/definitions/column"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
};
|
||||
refVal3.errors = null;
|
||||
refVal[3] = refVal3;
|
||||
var refVal4 = (function() {
|
||||
var pattern0 = new RegExp('^[0-9]+$');
|
||||
return function validate(data, dataPath, parentData, parentDataProperty, rootData) {
|
||||
'use strict';
|
||||
var vErrors = null;
|
||||
var errors = 0;
|
||||
if ((data && typeof data === "object" && !Array.isArray(data))) {
|
||||
var errs__0 = errors;
|
||||
var valid1 = true;
|
||||
for (var key0 in data) {
|
||||
var isAdditional0 = !(false || key0 == 'alignment' || key0 == 'width' || key0 == 'wrapWord' || key0 == 'truncate' || key0 == 'paddingLeft' || key0 == 'paddingRight');
|
||||
if (isAdditional0) {
|
||||
valid1 = false;
|
||||
var err = {
|
||||
keyword: 'additionalProperties',
|
||||
dataPath: (dataPath || '') + "",
|
||||
schemaPath: '#/additionalProperties',
|
||||
params: {
|
||||
additionalProperty: '' + key0 + ''
|
||||
},
|
||||
message: 'should NOT have additional properties'
|
||||
};
|
||||
if (vErrors === null) vErrors = [err];
|
||||
else vErrors.push(err);
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
var data1 = data.alignment;
|
||||
if (data1 !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (typeof data1 !== "string") {
|
||||
var err = {
|
||||
keyword: 'type',
|
||||
dataPath: (dataPath || '') + '.alignment',
|
||||
schemaPath: '#/properties/alignment/type',
|
||||
params: {
|
||||
type: 'string'
|
||||
},
|
||||
message: 'should be string'
|
||||
};
|
||||
if (vErrors === null) vErrors = [err];
|
||||
else vErrors.push(err);
|
||||
errors++;
|
||||
}
|
||||
var schema1 = validate.schema.properties.alignment.enum;
|
||||
var valid1;
|
||||
valid1 = false;
|
||||
for (var i1 = 0; i1 < schema1.length; i1++)
|
||||
if (equal(data1, schema1[i1])) {
|
||||
valid1 = true;
|
||||
break;
|
||||
} if (!valid1) {
|
||||
var err = {
|
||||
keyword: 'enum',
|
||||
dataPath: (dataPath || '') + '.alignment',
|
||||
schemaPath: '#/properties/alignment/enum',
|
||||
params: {
|
||||
allowedValues: schema1
|
||||
},
|
||||
message: 'should be equal to one of the allowed values'
|
||||
};
|
||||
if (vErrors === null) vErrors = [err];
|
||||
else vErrors.push(err);
|
||||
errors++;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.width !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (typeof data.width !== "number") {
|
||||
var err = {
|
||||
keyword: 'type',
|
||||
dataPath: (dataPath || '') + '.width',
|
||||
schemaPath: '#/properties/width/type',
|
||||
params: {
|
||||
type: 'number'
|
||||
},
|
||||
message: 'should be number'
|
||||
};
|
||||
if (vErrors === null) vErrors = [err];
|
||||
else vErrors.push(err);
|
||||
errors++;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.wrapWord !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (typeof data.wrapWord !== "boolean") {
|
||||
var err = {
|
||||
keyword: 'type',
|
||||
dataPath: (dataPath || '') + '.wrapWord',
|
||||
schemaPath: '#/properties/wrapWord/type',
|
||||
params: {
|
||||
type: 'boolean'
|
||||
},
|
||||
message: 'should be boolean'
|
||||
};
|
||||
if (vErrors === null) vErrors = [err];
|
||||
else vErrors.push(err);
|
||||
errors++;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.truncate !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (typeof data.truncate !== "number") {
|
||||
var err = {
|
||||
keyword: 'type',
|
||||
dataPath: (dataPath || '') + '.truncate',
|
||||
schemaPath: '#/properties/truncate/type',
|
||||
params: {
|
||||
type: 'number'
|
||||
},
|
||||
message: 'should be number'
|
||||
};
|
||||
if (vErrors === null) vErrors = [err];
|
||||
else vErrors.push(err);
|
||||
errors++;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.paddingLeft !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (typeof data.paddingLeft !== "number") {
|
||||
var err = {
|
||||
keyword: 'type',
|
||||
dataPath: (dataPath || '') + '.paddingLeft',
|
||||
schemaPath: '#/properties/paddingLeft/type',
|
||||
params: {
|
||||
type: 'number'
|
||||
},
|
||||
message: 'should be number'
|
||||
};
|
||||
if (vErrors === null) vErrors = [err];
|
||||
else vErrors.push(err);
|
||||
errors++;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.paddingRight !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (typeof data.paddingRight !== "number") {
|
||||
var err = {
|
||||
keyword: 'type',
|
||||
dataPath: (dataPath || '') + '.paddingRight',
|
||||
schemaPath: '#/properties/paddingRight/type',
|
||||
params: {
|
||||
type: 'number'
|
||||
},
|
||||
message: 'should be number'
|
||||
};
|
||||
if (vErrors === null) vErrors = [err];
|
||||
else vErrors.push(err);
|
||||
errors++;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
} else {
|
||||
var err = {
|
||||
keyword: 'type',
|
||||
dataPath: (dataPath || '') + "",
|
||||
schemaPath: '#/type',
|
||||
params: {
|
||||
type: 'object'
|
||||
},
|
||||
message: 'should be object'
|
||||
};
|
||||
if (vErrors === null) vErrors = [err];
|
||||
else vErrors.push(err);
|
||||
errors++;
|
||||
}
|
||||
validate.errors = vErrors;
|
||||
return errors === 0;
|
||||
};
|
||||
})();
|
||||
refVal4.schema = {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"alignment": {
|
||||
"type": "string",
|
||||
"enum": ["left", "right", "center"]
|
||||
},
|
||||
"width": {
|
||||
"type": "number"
|
||||
},
|
||||
"wrapWord": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"truncate": {
|
||||
"type": "number"
|
||||
},
|
||||
"paddingLeft": {
|
||||
"type": "number"
|
||||
},
|
||||
"paddingRight": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
};
|
||||
refVal4.errors = null;
|
||||
refVal[4] = refVal4;
|
||||
return function validate(data, dataPath, parentData, parentDataProperty, rootData) {
|
||||
'use strict'; /*# sourceURL=config.json */
|
||||
var vErrors = null;
|
||||
var errors = 0;
|
||||
if (rootData === undefined) rootData = data;
|
||||
if ((data && typeof data === "object" && !Array.isArray(data))) {
|
||||
var errs__0 = errors;
|
||||
var valid1 = true;
|
||||
for (var key0 in data) {
|
||||
var isAdditional0 = !(false || key0 == 'border' || key0 == 'columns' || key0 == 'columnDefault' || key0 == 'drawHorizontalLine');
|
||||
if (isAdditional0) {
|
||||
valid1 = false;
|
||||
var err = {
|
||||
keyword: 'additionalProperties',
|
||||
dataPath: (dataPath || '') + "",
|
||||
schemaPath: '#/additionalProperties',
|
||||
params: {
|
||||
additionalProperty: '' + key0 + ''
|
||||
},
|
||||
message: 'should NOT have additional properties'
|
||||
};
|
||||
if (vErrors === null) vErrors = [err];
|
||||
else vErrors.push(err);
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (data.border !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal1(data.border, (dataPath || '') + '.border', data, 'border', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal1.errors;
|
||||
else vErrors = vErrors.concat(refVal1.errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.columns !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal3(data.columns, (dataPath || '') + '.columns', data, 'columns', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal3.errors;
|
||||
else vErrors = vErrors.concat(refVal3.errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.columnDefault !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal[4](data.columnDefault, (dataPath || '') + '.columnDefault', data, 'columnDefault', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal[4].errors;
|
||||
else vErrors = vErrors.concat(refVal[4].errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.drawHorizontalLine !== undefined) {
|
||||
var errs_1 = errors;
|
||||
var errs__1 = errors;
|
||||
var valid1;
|
||||
valid1 = typeof data.drawHorizontalLine == "function";
|
||||
if (!valid1) {
|
||||
if (errs__1 == errors) {
|
||||
var err = {
|
||||
keyword: 'typeof',
|
||||
dataPath: (dataPath || '') + '.drawHorizontalLine',
|
||||
schemaPath: '#/properties/drawHorizontalLine/typeof',
|
||||
params: {
|
||||
keyword: 'typeof'
|
||||
},
|
||||
message: 'should pass "typeof" keyword validation'
|
||||
};
|
||||
if (vErrors === null) vErrors = [err];
|
||||
else vErrors.push(err);
|
||||
errors++;
|
||||
} else {
|
||||
for (var i1 = errs__1; i1 < errors; i1++) {
|
||||
var ruleErr1 = vErrors[i1];
|
||||
if (ruleErr1.dataPath === undefined) ruleErr1.dataPath = (dataPath || '') + '.drawHorizontalLine';
|
||||
if (ruleErr1.schemaPath === undefined) {
|
||||
ruleErr1.schemaPath = "#/properties/drawHorizontalLine/typeof";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
} else {
|
||||
var err = {
|
||||
keyword: 'type',
|
||||
dataPath: (dataPath || '') + "",
|
||||
schemaPath: '#/type',
|
||||
params: {
|
||||
type: 'object'
|
||||
},
|
||||
message: 'should be object'
|
||||
};
|
||||
if (vErrors === null) vErrors = [err];
|
||||
else vErrors.push(err);
|
||||
errors++;
|
||||
}
|
||||
validate.errors = vErrors;
|
||||
return errors === 0;
|
||||
};
|
||||
})();
|
||||
validate.schema = {
|
||||
"$id": "config.json",
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"border": {
|
||||
"$ref": "#/definitions/borders"
|
||||
},
|
||||
"columns": {
|
||||
"$ref": "#/definitions/columns"
|
||||
},
|
||||
"columnDefault": {
|
||||
"$ref": "#/definitions/column"
|
||||
},
|
||||
"drawHorizontalLine": {
|
||||
"typeof": "function"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"definitions": {
|
||||
"columns": {
|
||||
"type": "object",
|
||||
"patternProperties": {
|
||||
"^[0-9]+$": {
|
||||
"$ref": "#/definitions/column"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"column": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"alignment": {
|
||||
"type": "string",
|
||||
"enum": ["left", "right", "center"]
|
||||
},
|
||||
"width": {
|
||||
"type": "number"
|
||||
},
|
||||
"wrapWord": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"truncate": {
|
||||
"type": "number"
|
||||
},
|
||||
"paddingLeft": {
|
||||
"type": "number"
|
||||
},
|
||||
"paddingRight": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"borders": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"topBody": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"topJoin": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"topLeft": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"topRight": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bottomBody": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bottomJoin": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bottomLeft": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bottomRight": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bodyLeft": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bodyRight": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bodyJoin": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"joinBody": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"joinLeft": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"joinRight": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"joinJoin": {
|
||||
"$ref": "#/definitions/border"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"border": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
};
|
||||
validate.errors = null;
|
||||
module.exports = validate;
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
// eslint-disable-next-line import/default
|
||||
import validateConfig from '../dist/validateConfig';
|
||||
// eslint-disable-next-line import/default
|
||||
import validateStreamConfig from '../dist/validateStreamConfig';
|
||||
|
||||
const validate = {
|
||||
'config.json': validateConfig,
|
||||
'streamConfig.json': validateStreamConfig
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} schemaId
|
||||
* @param {formatData~config} config
|
||||
* @returns {undefined}
|
||||
*/
|
||||
export default (schemaId, config = {}) => {
|
||||
if (!validate[schemaId](config)) {
|
||||
const errors = validate[schemaId].errors.map((error) => {
|
||||
return {
|
||||
dataPath: error.dataPath,
|
||||
message: error.message,
|
||||
params: error.params,
|
||||
schemaPath: error.schemaPath
|
||||
};
|
||||
});
|
||||
|
||||
/* eslint-disable no-console */
|
||||
console.log('config', config);
|
||||
console.log('errors', errors);
|
||||
/* eslint-enable no-console */
|
||||
|
||||
throw new Error('Invalid config.');
|
||||
}
|
||||
};
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../src/validateConfig.js"],"names":["validate","validateConfig","validateStreamConfig","schemaId","config","errors","map","error","dataPath","message","params","schemaPath","console","log","Error"],"mappings":";;;;;;;AACA;;AAEA;;;;AAHA;AAEA;AAGA,MAAMA,QAAQ,GAAG;AACf,iBAAeC,uBADA;AAEf,uBAAqBC;AAFN,CAAjB;AAKA;;;;;;yBAKgBC,Q,EAAUC,MAAM,GAAG,E,KAAO;AACxC,MAAI,CAACJ,QAAQ,CAACG,QAAD,CAAR,CAAmBC,MAAnB,CAAL,EAAiC;AAC/B,UAAMC,MAAM,GAAGL,QAAQ,CAACG,QAAD,CAAR,CAAmBE,MAAnB,CAA0BC,GAA1B,CAA+BC,KAAD,IAAW;AACtD,aAAO;AACLC,QAAAA,QAAQ,EAAED,KAAK,CAACC,QADX;AAELC,QAAAA,OAAO,EAAEF,KAAK,CAACE,OAFV;AAGLC,QAAAA,MAAM,EAAEH,KAAK,CAACG,MAHT;AAILC,QAAAA,UAAU,EAAEJ,KAAK,CAACI;AAJb,OAAP;AAMD,KAPc,CAAf;AASA;;AACAC,IAAAA,OAAO,CAACC,GAAR,CAAY,QAAZ,EAAsBT,MAAtB;AACAQ,IAAAA,OAAO,CAACC,GAAR,CAAY,QAAZ,EAAsBR,MAAtB;AACA;;AAEA,UAAM,IAAIS,KAAJ,CAAU,iBAAV,CAAN;AACD;AACF,C","sourcesContent":["// eslint-disable-next-line import/default\nimport validateConfig from '../dist/validateConfig';\n// eslint-disable-next-line import/default\nimport validateStreamConfig from '../dist/validateStreamConfig';\n\nconst validate = {\n 'config.json': validateConfig,\n 'streamConfig.json': validateStreamConfig\n};\n\n/**\n * @param {string} schemaId\n * @param {formatData~config} config\n * @returns {undefined}\n */\nexport default (schemaId, config = {}) => {\n if (!validate[schemaId](config)) {\n const errors = validate[schemaId].errors.map((error) => {\n return {\n dataPath: error.dataPath,\n message: error.message,\n params: error.params,\n schemaPath: error.schemaPath\n };\n });\n\n /* eslint-disable no-console */\n console.log('config', config);\n console.log('errors', errors);\n /* eslint-enable no-console */\n\n throw new Error('Invalid config.');\n }\n};\n"],"file":"validateConfig.js"}
|
||||
+739
@@ -0,0 +1,739 @@
|
||||
'use strict';
|
||||
var equal = require('ajv/lib/compile/equal');
|
||||
var validate = (function() {
|
||||
var pattern0 = new RegExp('^[0-9]+$');
|
||||
var refVal = [];
|
||||
var refVal1 = (function() {
|
||||
var pattern0 = new RegExp('^[0-9]+$');
|
||||
return function validate(data, dataPath, parentData, parentDataProperty, rootData) {
|
||||
'use strict';
|
||||
var vErrors = null;
|
||||
var errors = 0;
|
||||
if (rootData === undefined) rootData = data;
|
||||
if ((data && typeof data === "object" && !Array.isArray(data))) {
|
||||
var errs__0 = errors;
|
||||
var valid1 = true;
|
||||
for (var key0 in data) {
|
||||
var isAdditional0 = !(false || validate.schema.properties.hasOwnProperty(key0));
|
||||
if (isAdditional0) {
|
||||
valid1 = false;
|
||||
var err = {
|
||||
keyword: 'additionalProperties',
|
||||
dataPath: (dataPath || '') + "",
|
||||
schemaPath: '#/additionalProperties',
|
||||
params: {
|
||||
additionalProperty: '' + key0 + ''
|
||||
},
|
||||
message: 'should NOT have additional properties'
|
||||
};
|
||||
if (vErrors === null) vErrors = [err];
|
||||
else vErrors.push(err);
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (data.topBody !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal2(data.topBody, (dataPath || '') + '.topBody', data, 'topBody', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal2.errors;
|
||||
else vErrors = vErrors.concat(refVal2.errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.topJoin !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal[2](data.topJoin, (dataPath || '') + '.topJoin', data, 'topJoin', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal[2].errors;
|
||||
else vErrors = vErrors.concat(refVal[2].errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.topLeft !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal[2](data.topLeft, (dataPath || '') + '.topLeft', data, 'topLeft', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal[2].errors;
|
||||
else vErrors = vErrors.concat(refVal[2].errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.topRight !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal[2](data.topRight, (dataPath || '') + '.topRight', data, 'topRight', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal[2].errors;
|
||||
else vErrors = vErrors.concat(refVal[2].errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.bottomBody !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal[2](data.bottomBody, (dataPath || '') + '.bottomBody', data, 'bottomBody', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal[2].errors;
|
||||
else vErrors = vErrors.concat(refVal[2].errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.bottomJoin !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal[2](data.bottomJoin, (dataPath || '') + '.bottomJoin', data, 'bottomJoin', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal[2].errors;
|
||||
else vErrors = vErrors.concat(refVal[2].errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.bottomLeft !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal[2](data.bottomLeft, (dataPath || '') + '.bottomLeft', data, 'bottomLeft', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal[2].errors;
|
||||
else vErrors = vErrors.concat(refVal[2].errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.bottomRight !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal[2](data.bottomRight, (dataPath || '') + '.bottomRight', data, 'bottomRight', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal[2].errors;
|
||||
else vErrors = vErrors.concat(refVal[2].errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.bodyLeft !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal[2](data.bodyLeft, (dataPath || '') + '.bodyLeft', data, 'bodyLeft', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal[2].errors;
|
||||
else vErrors = vErrors.concat(refVal[2].errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.bodyRight !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal[2](data.bodyRight, (dataPath || '') + '.bodyRight', data, 'bodyRight', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal[2].errors;
|
||||
else vErrors = vErrors.concat(refVal[2].errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.bodyJoin !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal[2](data.bodyJoin, (dataPath || '') + '.bodyJoin', data, 'bodyJoin', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal[2].errors;
|
||||
else vErrors = vErrors.concat(refVal[2].errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.joinBody !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal[2](data.joinBody, (dataPath || '') + '.joinBody', data, 'joinBody', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal[2].errors;
|
||||
else vErrors = vErrors.concat(refVal[2].errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.joinLeft !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal[2](data.joinLeft, (dataPath || '') + '.joinLeft', data, 'joinLeft', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal[2].errors;
|
||||
else vErrors = vErrors.concat(refVal[2].errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.joinRight !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal[2](data.joinRight, (dataPath || '') + '.joinRight', data, 'joinRight', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal[2].errors;
|
||||
else vErrors = vErrors.concat(refVal[2].errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.joinJoin !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal[2](data.joinJoin, (dataPath || '') + '.joinJoin', data, 'joinJoin', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal[2].errors;
|
||||
else vErrors = vErrors.concat(refVal[2].errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
} else {
|
||||
var err = {
|
||||
keyword: 'type',
|
||||
dataPath: (dataPath || '') + "",
|
||||
schemaPath: '#/type',
|
||||
params: {
|
||||
type: 'object'
|
||||
},
|
||||
message: 'should be object'
|
||||
};
|
||||
if (vErrors === null) vErrors = [err];
|
||||
else vErrors.push(err);
|
||||
errors++;
|
||||
}
|
||||
validate.errors = vErrors;
|
||||
return errors === 0;
|
||||
};
|
||||
})();
|
||||
refVal1.schema = {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"topBody": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"topJoin": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"topLeft": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"topRight": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bottomBody": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bottomJoin": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bottomLeft": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bottomRight": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bodyLeft": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bodyRight": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bodyJoin": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"joinBody": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"joinLeft": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"joinRight": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"joinJoin": {
|
||||
"$ref": "#/definitions/border"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
};
|
||||
refVal1.errors = null;
|
||||
refVal[1] = refVal1;
|
||||
var refVal2 = (function() {
|
||||
var pattern0 = new RegExp('^[0-9]+$');
|
||||
return function validate(data, dataPath, parentData, parentDataProperty, rootData) {
|
||||
'use strict';
|
||||
var vErrors = null;
|
||||
var errors = 0;
|
||||
if (typeof data !== "string") {
|
||||
var err = {
|
||||
keyword: 'type',
|
||||
dataPath: (dataPath || '') + "",
|
||||
schemaPath: '#/type',
|
||||
params: {
|
||||
type: 'string'
|
||||
},
|
||||
message: 'should be string'
|
||||
};
|
||||
if (vErrors === null) vErrors = [err];
|
||||
else vErrors.push(err);
|
||||
errors++;
|
||||
}
|
||||
validate.errors = vErrors;
|
||||
return errors === 0;
|
||||
};
|
||||
})();
|
||||
refVal2.schema = {
|
||||
"type": "string"
|
||||
};
|
||||
refVal2.errors = null;
|
||||
refVal[2] = refVal2;
|
||||
var refVal3 = (function() {
|
||||
var pattern0 = new RegExp('^[0-9]+$');
|
||||
return function validate(data, dataPath, parentData, parentDataProperty, rootData) {
|
||||
'use strict';
|
||||
var vErrors = null;
|
||||
var errors = 0;
|
||||
if (rootData === undefined) rootData = data;
|
||||
if ((data && typeof data === "object" && !Array.isArray(data))) {
|
||||
var errs__0 = errors;
|
||||
var valid1 = true;
|
||||
for (var key0 in data) {
|
||||
var isAdditional0 = !(false || pattern0.test(key0));
|
||||
if (isAdditional0) {
|
||||
valid1 = false;
|
||||
var err = {
|
||||
keyword: 'additionalProperties',
|
||||
dataPath: (dataPath || '') + "",
|
||||
schemaPath: '#/additionalProperties',
|
||||
params: {
|
||||
additionalProperty: '' + key0 + ''
|
||||
},
|
||||
message: 'should NOT have additional properties'
|
||||
};
|
||||
if (vErrors === null) vErrors = [err];
|
||||
else vErrors.push(err);
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
for (var key0 in data) {
|
||||
if (pattern0.test(key0)) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal4(data[key0], (dataPath || '') + '[\'' + key0 + '\']', data, key0, rootData)) {
|
||||
if (vErrors === null) vErrors = refVal4.errors;
|
||||
else vErrors = vErrors.concat(refVal4.errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var err = {
|
||||
keyword: 'type',
|
||||
dataPath: (dataPath || '') + "",
|
||||
schemaPath: '#/type',
|
||||
params: {
|
||||
type: 'object'
|
||||
},
|
||||
message: 'should be object'
|
||||
};
|
||||
if (vErrors === null) vErrors = [err];
|
||||
else vErrors.push(err);
|
||||
errors++;
|
||||
}
|
||||
validate.errors = vErrors;
|
||||
return errors === 0;
|
||||
};
|
||||
})();
|
||||
refVal3.schema = {
|
||||
"type": "object",
|
||||
"patternProperties": {
|
||||
"^[0-9]+$": {
|
||||
"$ref": "#/definitions/column"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
};
|
||||
refVal3.errors = null;
|
||||
refVal[3] = refVal3;
|
||||
var refVal4 = (function() {
|
||||
var pattern0 = new RegExp('^[0-9]+$');
|
||||
return function validate(data, dataPath, parentData, parentDataProperty, rootData) {
|
||||
'use strict';
|
||||
var vErrors = null;
|
||||
var errors = 0;
|
||||
if ((data && typeof data === "object" && !Array.isArray(data))) {
|
||||
var errs__0 = errors;
|
||||
var valid1 = true;
|
||||
for (var key0 in data) {
|
||||
var isAdditional0 = !(false || key0 == 'alignment' || key0 == 'width' || key0 == 'wrapWord' || key0 == 'truncate' || key0 == 'paddingLeft' || key0 == 'paddingRight');
|
||||
if (isAdditional0) {
|
||||
valid1 = false;
|
||||
var err = {
|
||||
keyword: 'additionalProperties',
|
||||
dataPath: (dataPath || '') + "",
|
||||
schemaPath: '#/additionalProperties',
|
||||
params: {
|
||||
additionalProperty: '' + key0 + ''
|
||||
},
|
||||
message: 'should NOT have additional properties'
|
||||
};
|
||||
if (vErrors === null) vErrors = [err];
|
||||
else vErrors.push(err);
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
var data1 = data.alignment;
|
||||
if (data1 !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (typeof data1 !== "string") {
|
||||
var err = {
|
||||
keyword: 'type',
|
||||
dataPath: (dataPath || '') + '.alignment',
|
||||
schemaPath: '#/properties/alignment/type',
|
||||
params: {
|
||||
type: 'string'
|
||||
},
|
||||
message: 'should be string'
|
||||
};
|
||||
if (vErrors === null) vErrors = [err];
|
||||
else vErrors.push(err);
|
||||
errors++;
|
||||
}
|
||||
var schema1 = validate.schema.properties.alignment.enum;
|
||||
var valid1;
|
||||
valid1 = false;
|
||||
for (var i1 = 0; i1 < schema1.length; i1++)
|
||||
if (equal(data1, schema1[i1])) {
|
||||
valid1 = true;
|
||||
break;
|
||||
} if (!valid1) {
|
||||
var err = {
|
||||
keyword: 'enum',
|
||||
dataPath: (dataPath || '') + '.alignment',
|
||||
schemaPath: '#/properties/alignment/enum',
|
||||
params: {
|
||||
allowedValues: schema1
|
||||
},
|
||||
message: 'should be equal to one of the allowed values'
|
||||
};
|
||||
if (vErrors === null) vErrors = [err];
|
||||
else vErrors.push(err);
|
||||
errors++;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.width !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (typeof data.width !== "number") {
|
||||
var err = {
|
||||
keyword: 'type',
|
||||
dataPath: (dataPath || '') + '.width',
|
||||
schemaPath: '#/properties/width/type',
|
||||
params: {
|
||||
type: 'number'
|
||||
},
|
||||
message: 'should be number'
|
||||
};
|
||||
if (vErrors === null) vErrors = [err];
|
||||
else vErrors.push(err);
|
||||
errors++;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.wrapWord !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (typeof data.wrapWord !== "boolean") {
|
||||
var err = {
|
||||
keyword: 'type',
|
||||
dataPath: (dataPath || '') + '.wrapWord',
|
||||
schemaPath: '#/properties/wrapWord/type',
|
||||
params: {
|
||||
type: 'boolean'
|
||||
},
|
||||
message: 'should be boolean'
|
||||
};
|
||||
if (vErrors === null) vErrors = [err];
|
||||
else vErrors.push(err);
|
||||
errors++;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.truncate !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (typeof data.truncate !== "number") {
|
||||
var err = {
|
||||
keyword: 'type',
|
||||
dataPath: (dataPath || '') + '.truncate',
|
||||
schemaPath: '#/properties/truncate/type',
|
||||
params: {
|
||||
type: 'number'
|
||||
},
|
||||
message: 'should be number'
|
||||
};
|
||||
if (vErrors === null) vErrors = [err];
|
||||
else vErrors.push(err);
|
||||
errors++;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.paddingLeft !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (typeof data.paddingLeft !== "number") {
|
||||
var err = {
|
||||
keyword: 'type',
|
||||
dataPath: (dataPath || '') + '.paddingLeft',
|
||||
schemaPath: '#/properties/paddingLeft/type',
|
||||
params: {
|
||||
type: 'number'
|
||||
},
|
||||
message: 'should be number'
|
||||
};
|
||||
if (vErrors === null) vErrors = [err];
|
||||
else vErrors.push(err);
|
||||
errors++;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.paddingRight !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (typeof data.paddingRight !== "number") {
|
||||
var err = {
|
||||
keyword: 'type',
|
||||
dataPath: (dataPath || '') + '.paddingRight',
|
||||
schemaPath: '#/properties/paddingRight/type',
|
||||
params: {
|
||||
type: 'number'
|
||||
},
|
||||
message: 'should be number'
|
||||
};
|
||||
if (vErrors === null) vErrors = [err];
|
||||
else vErrors.push(err);
|
||||
errors++;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
} else {
|
||||
var err = {
|
||||
keyword: 'type',
|
||||
dataPath: (dataPath || '') + "",
|
||||
schemaPath: '#/type',
|
||||
params: {
|
||||
type: 'object'
|
||||
},
|
||||
message: 'should be object'
|
||||
};
|
||||
if (vErrors === null) vErrors = [err];
|
||||
else vErrors.push(err);
|
||||
errors++;
|
||||
}
|
||||
validate.errors = vErrors;
|
||||
return errors === 0;
|
||||
};
|
||||
})();
|
||||
refVal4.schema = {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"alignment": {
|
||||
"type": "string",
|
||||
"enum": ["left", "right", "center"]
|
||||
},
|
||||
"width": {
|
||||
"type": "number"
|
||||
},
|
||||
"wrapWord": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"truncate": {
|
||||
"type": "number"
|
||||
},
|
||||
"paddingLeft": {
|
||||
"type": "number"
|
||||
},
|
||||
"paddingRight": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
};
|
||||
refVal4.errors = null;
|
||||
refVal[4] = refVal4;
|
||||
return function validate(data, dataPath, parentData, parentDataProperty, rootData) {
|
||||
'use strict'; /*# sourceURL=streamConfig.json */
|
||||
var vErrors = null;
|
||||
var errors = 0;
|
||||
if (rootData === undefined) rootData = data;
|
||||
if ((data && typeof data === "object" && !Array.isArray(data))) {
|
||||
var errs__0 = errors;
|
||||
var valid1 = true;
|
||||
for (var key0 in data) {
|
||||
var isAdditional0 = !(false || key0 == 'border' || key0 == 'columns' || key0 == 'columnDefault' || key0 == 'columnCount');
|
||||
if (isAdditional0) {
|
||||
valid1 = false;
|
||||
var err = {
|
||||
keyword: 'additionalProperties',
|
||||
dataPath: (dataPath || '') + "",
|
||||
schemaPath: '#/additionalProperties',
|
||||
params: {
|
||||
additionalProperty: '' + key0 + ''
|
||||
},
|
||||
message: 'should NOT have additional properties'
|
||||
};
|
||||
if (vErrors === null) vErrors = [err];
|
||||
else vErrors.push(err);
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (data.border !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal1(data.border, (dataPath || '') + '.border', data, 'border', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal1.errors;
|
||||
else vErrors = vErrors.concat(refVal1.errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.columns !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal3(data.columns, (dataPath || '') + '.columns', data, 'columns', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal3.errors;
|
||||
else vErrors = vErrors.concat(refVal3.errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.columnDefault !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (!refVal[4](data.columnDefault, (dataPath || '') + '.columnDefault', data, 'columnDefault', rootData)) {
|
||||
if (vErrors === null) vErrors = refVal[4].errors;
|
||||
else vErrors = vErrors.concat(refVal[4].errors);
|
||||
errors = vErrors.length;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
if (data.columnCount !== undefined) {
|
||||
var errs_1 = errors;
|
||||
if (typeof data.columnCount !== "number") {
|
||||
var err = {
|
||||
keyword: 'type',
|
||||
dataPath: (dataPath || '') + '.columnCount',
|
||||
schemaPath: '#/properties/columnCount/type',
|
||||
params: {
|
||||
type: 'number'
|
||||
},
|
||||
message: 'should be number'
|
||||
};
|
||||
if (vErrors === null) vErrors = [err];
|
||||
else vErrors.push(err);
|
||||
errors++;
|
||||
}
|
||||
var valid1 = errors === errs_1;
|
||||
}
|
||||
} else {
|
||||
var err = {
|
||||
keyword: 'type',
|
||||
dataPath: (dataPath || '') + "",
|
||||
schemaPath: '#/type',
|
||||
params: {
|
||||
type: 'object'
|
||||
},
|
||||
message: 'should be object'
|
||||
};
|
||||
if (vErrors === null) vErrors = [err];
|
||||
else vErrors.push(err);
|
||||
errors++;
|
||||
}
|
||||
validate.errors = vErrors;
|
||||
return errors === 0;
|
||||
};
|
||||
})();
|
||||
validate.schema = {
|
||||
"$id": "streamConfig.json",
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"border": {
|
||||
"$ref": "#/definitions/borders"
|
||||
},
|
||||
"columns": {
|
||||
"$ref": "#/definitions/columns"
|
||||
},
|
||||
"columnDefault": {
|
||||
"$ref": "#/definitions/column"
|
||||
},
|
||||
"columnCount": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"definitions": {
|
||||
"columns": {
|
||||
"type": "object",
|
||||
"patternProperties": {
|
||||
"^[0-9]+$": {
|
||||
"$ref": "#/definitions/column"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"column": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"alignment": {
|
||||
"type": "string",
|
||||
"enum": ["left", "right", "center"]
|
||||
},
|
||||
"width": {
|
||||
"type": "number"
|
||||
},
|
||||
"wrapWord": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"truncate": {
|
||||
"type": "number"
|
||||
},
|
||||
"paddingLeft": {
|
||||
"type": "number"
|
||||
},
|
||||
"paddingRight": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"borders": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"topBody": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"topJoin": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"topLeft": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"topRight": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bottomBody": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bottomJoin": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bottomLeft": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bottomRight": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bodyLeft": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bodyRight": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"bodyJoin": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"joinBody": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"joinLeft": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"joinRight": {
|
||||
"$ref": "#/definitions/border"
|
||||
},
|
||||
"joinJoin": {
|
||||
"$ref": "#/definitions/border"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"border": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
};
|
||||
validate.errors = null;
|
||||
module.exports = validate;
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
/**
|
||||
* @typedef {string} cell
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {cell[]} validateData~column
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {column[]} rows
|
||||
* @returns {undefined}
|
||||
*/
|
||||
const validateTableData = rows => {
|
||||
if (!Array.isArray(rows)) {
|
||||
throw new TypeError('Table data must be an array.');
|
||||
}
|
||||
|
||||
if (rows.length === 0) {
|
||||
throw new Error('Table must define at least one row.');
|
||||
}
|
||||
|
||||
if (rows[0].length === 0) {
|
||||
throw new Error('Table must define at least one column.');
|
||||
}
|
||||
|
||||
const columnNumber = rows[0].length;
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator = rows[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
const cells = _step.value;
|
||||
|
||||
if (!Array.isArray(cells)) {
|
||||
throw new TypeError('Table row data must be an array.');
|
||||
}
|
||||
|
||||
if (cells.length !== columnNumber) {
|
||||
throw new Error('Table must have a consistent number of cells.');
|
||||
} // @todo Make an exception for newline characters.
|
||||
// @see https://github.com/gajus/table/issues/9
|
||||
|
||||
|
||||
var _iteratorNormalCompletion2 = true;
|
||||
var _didIteratorError2 = false;
|
||||
var _iteratorError2 = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator2 = cells[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
||||
const cell = _step2.value;
|
||||
|
||||
// eslint-disable-next-line no-control-regex
|
||||
if (/[\u0001-\u001A]/.test(cell)) {
|
||||
throw new Error('Table data must not contain control characters.');
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError2 = true;
|
||||
_iteratorError2 = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
|
||||
_iterator2.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError2) {
|
||||
throw _iteratorError2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
||||
_iterator.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var _default = validateTableData;
|
||||
exports.default = _default;
|
||||
//# sourceMappingURL=validateTableData.js.map
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* @typedef {string} cell
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {cell[]} validateData~column
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {column[]} rows
|
||||
* @returns {undefined}
|
||||
*/
|
||||
export default (rows) => {
|
||||
if (!Array.isArray(rows)) {
|
||||
throw new TypeError('Table data must be an array.');
|
||||
}
|
||||
|
||||
if (rows.length === 0) {
|
||||
throw new Error('Table must define at least one row.');
|
||||
}
|
||||
|
||||
if (rows[0].length === 0) {
|
||||
throw new Error('Table must define at least one column.');
|
||||
}
|
||||
|
||||
const columnNumber = rows[0].length;
|
||||
|
||||
for (const cells of rows) {
|
||||
if (!Array.isArray(cells)) {
|
||||
throw new TypeError('Table row data must be an array.');
|
||||
}
|
||||
|
||||
if (cells.length !== columnNumber) {
|
||||
throw new Error('Table must have a consistent number of cells.');
|
||||
}
|
||||
|
||||
// @todo Make an exception for newline characters.
|
||||
// @see https://github.com/gajus/table/issues/9
|
||||
for (const cell of cells) {
|
||||
// eslint-disable-next-line no-control-regex
|
||||
if (/[\u0001-\u001A]/.test(cell)) {
|
||||
throw new Error('Table data must not contain control characters.');
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../src/validateTableData.js"],"names":["rows","Array","isArray","TypeError","length","Error","columnNumber","cells","cell","test"],"mappings":";;;;;;;AAAA;;;;AAIA;;;;AAIA;;;;0BAIgBA,I,IAAS;AACvB,MAAI,CAACC,KAAK,CAACC,OAAN,CAAcF,IAAd,CAAL,EAA0B;AACxB,UAAM,IAAIG,SAAJ,CAAc,8BAAd,CAAN;AACD;;AAED,MAAIH,IAAI,CAACI,MAAL,KAAgB,CAApB,EAAuB;AACrB,UAAM,IAAIC,KAAJ,CAAU,qCAAV,CAAN;AACD;;AAED,MAAIL,IAAI,CAAC,CAAD,CAAJ,CAAQI,MAAR,KAAmB,CAAvB,EAA0B;AACxB,UAAM,IAAIC,KAAJ,CAAU,wCAAV,CAAN;AACD;;AAED,QAAMC,YAAY,GAAGN,IAAI,CAAC,CAAD,CAAJ,CAAQI,MAA7B;AAbuB;AAAA;AAAA;;AAAA;AAevB,yBAAoBJ,IAApB,8HAA0B;AAAA,YAAfO,KAAe;;AACxB,UAAI,CAACN,KAAK,CAACC,OAAN,CAAcK,KAAd,CAAL,EAA2B;AACzB,cAAM,IAAIJ,SAAJ,CAAc,kCAAd,CAAN;AACD;;AAED,UAAII,KAAK,CAACH,MAAN,KAAiBE,YAArB,EAAmC;AACjC,cAAM,IAAID,KAAJ,CAAU,+CAAV,CAAN;AACD,OAPuB,CASxB;AACA;;;AAVwB;AAAA;AAAA;;AAAA;AAWxB,8BAAmBE,KAAnB,mIAA0B;AAAA,gBAAfC,IAAe;;AACxB;AACA,cAAI,kBAAkBC,IAAlB,CAAuBD,IAAvB,CAAJ,EAAkC;AAChC,kBAAM,IAAIH,KAAJ,CAAU,iDAAV,CAAN;AACD;AACF;AAhBuB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBzB;AAhCsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiCxB,C","sourcesContent":["/**\n * @typedef {string} cell\n */\n\n/**\n * @typedef {cell[]} validateData~column\n */\n\n/**\n * @param {column[]} rows\n * @returns {undefined}\n */\nexport default (rows) => {\n if (!Array.isArray(rows)) {\n throw new TypeError('Table data must be an array.');\n }\n\n if (rows.length === 0) {\n throw new Error('Table must define at least one row.');\n }\n\n if (rows[0].length === 0) {\n throw new Error('Table must define at least one column.');\n }\n\n const columnNumber = rows[0].length;\n\n for (const cells of rows) {\n if (!Array.isArray(cells)) {\n throw new TypeError('Table row data must be an array.');\n }\n\n if (cells.length !== columnNumber) {\n throw new Error('Table must have a consistent number of cells.');\n }\n\n // @todo Make an exception for newline characters.\n // @see https://github.com/gajus/table/issues/9\n for (const cell of cells) {\n // eslint-disable-next-line no-control-regex\n if (/[\\u0001-\\u001A]/.test(cell)) {\n throw new Error('Table data must not contain control characters.');\n }\n }\n }\n};\n"],"file":"validateTableData.js"}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _sliceAnsi = _interopRequireDefault(require("slice-ansi"));
|
||||
|
||||
var _stringWidth = _interopRequireDefault(require("string-width"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* Creates an array of strings split into groups the length of size.
|
||||
* This function works with strings that contain ASCII characters.
|
||||
*
|
||||
* wrapText is different from would-be "chunk" implementation
|
||||
* in that whitespace characters that occur on a chunk size limit are trimmed.
|
||||
*
|
||||
* @param {string} subject
|
||||
* @param {number} size
|
||||
* @returns {Array}
|
||||
*/
|
||||
const wrapString = (subject, size) => {
|
||||
let subjectSlice;
|
||||
subjectSlice = subject;
|
||||
const chunks = [];
|
||||
|
||||
do {
|
||||
chunks.push((0, _sliceAnsi.default)(subjectSlice, 0, size));
|
||||
subjectSlice = (0, _sliceAnsi.default)(subjectSlice, size).trim();
|
||||
} while ((0, _stringWidth.default)(subjectSlice));
|
||||
|
||||
return chunks;
|
||||
};
|
||||
|
||||
var _default = wrapString;
|
||||
exports.default = _default;
|
||||
//# sourceMappingURL=wrapString.js.map
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
import slice from 'slice-ansi';
|
||||
import stringWidth from 'string-width';
|
||||
|
||||
/**
|
||||
* Creates an array of strings split into groups the length of size.
|
||||
* This function works with strings that contain ASCII characters.
|
||||
*
|
||||
* wrapText is different from would-be "chunk" implementation
|
||||
* in that whitespace characters that occur on a chunk size limit are trimmed.
|
||||
*
|
||||
* @param {string} subject
|
||||
* @param {number} size
|
||||
* @returns {Array}
|
||||
*/
|
||||
export default (subject, size) => {
|
||||
let subjectSlice;
|
||||
|
||||
subjectSlice = subject;
|
||||
|
||||
const chunks = [];
|
||||
|
||||
do {
|
||||
chunks.push(slice(subjectSlice, 0, size));
|
||||
|
||||
subjectSlice = slice(subjectSlice, size).trim();
|
||||
} while (stringWidth(subjectSlice));
|
||||
|
||||
return chunks;
|
||||
};
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../src/wrapString.js"],"names":["subject","size","subjectSlice","chunks","push","trim"],"mappings":";;;;;;;AAAA;;AACA;;;;AAEA;;;;;;;;;;;oBAWgBA,O,EAASC,I,KAAS;AAChC,MAAIC,YAAJ;AAEAA,EAAAA,YAAY,GAAGF,OAAf;AAEA,QAAMG,MAAM,GAAG,EAAf;;AAEA,KAAG;AACDA,IAAAA,MAAM,CAACC,IAAP,CAAY,wBAAMF,YAAN,EAAoB,CAApB,EAAuBD,IAAvB,CAAZ;AAEAC,IAAAA,YAAY,GAAG,wBAAMA,YAAN,EAAoBD,IAApB,EAA0BI,IAA1B,EAAf;AACD,GAJD,QAIS,0BAAYH,YAAZ,CAJT;;AAMA,SAAOC,MAAP;AACD,C","sourcesContent":["import slice from 'slice-ansi';\nimport stringWidth from 'string-width';\n\n/**\n * Creates an array of strings split into groups the length of size.\n * This function works with strings that contain ASCII characters.\n *\n * wrapText is different from would-be \"chunk\" implementation\n * in that whitespace characters that occur on a chunk size limit are trimmed.\n *\n * @param {string} subject\n * @param {number} size\n * @returns {Array}\n */\nexport default (subject, size) => {\n let subjectSlice;\n\n subjectSlice = subject;\n\n const chunks = [];\n\n do {\n chunks.push(slice(subjectSlice, 0, size));\n\n subjectSlice = slice(subjectSlice, size).trim();\n } while (stringWidth(subjectSlice));\n\n return chunks;\n};\n"],"file":"wrapString.js"}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _sliceAnsi = _interopRequireDefault(require("slice-ansi"));
|
||||
|
||||
var _stringWidth = _interopRequireDefault(require("string-width"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {number} size
|
||||
* @returns {Array}
|
||||
*/
|
||||
const wrapWord = (input, size) => {
|
||||
let subject;
|
||||
subject = input;
|
||||
const chunks = []; // https://regex101.com/r/gY5kZ1/1
|
||||
|
||||
const re = new RegExp('(^.{1,' + size + '}(\\s+|$))|(^.{1,' + (size - 1) + '}(\\\\|/|_|\\.|,|;|-))');
|
||||
|
||||
do {
|
||||
let chunk;
|
||||
chunk = subject.match(re);
|
||||
|
||||
if (chunk) {
|
||||
chunk = chunk[0];
|
||||
subject = (0, _sliceAnsi.default)(subject, (0, _stringWidth.default)(chunk));
|
||||
chunk = chunk.trim();
|
||||
} else {
|
||||
chunk = (0, _sliceAnsi.default)(subject, 0, size);
|
||||
subject = (0, _sliceAnsi.default)(subject, size);
|
||||
}
|
||||
|
||||
chunks.push(chunk);
|
||||
} while ((0, _stringWidth.default)(subject));
|
||||
|
||||
return chunks;
|
||||
};
|
||||
|
||||
var _default = wrapWord;
|
||||
exports.default = _default;
|
||||
//# sourceMappingURL=wrapWord.js.map
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
import slice from 'slice-ansi';
|
||||
import stringWidth from 'string-width';
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {number} size
|
||||
* @returns {Array}
|
||||
*/
|
||||
export default (input, size) => {
|
||||
let subject;
|
||||
|
||||
subject = input;
|
||||
|
||||
const chunks = [];
|
||||
|
||||
// https://regex101.com/r/gY5kZ1/1
|
||||
const re = new RegExp('(^.{1,' + size + '}(\\s+|$))|(^.{1,' + (size - 1) + '}(\\\\|/|_|\\.|,|;|-))');
|
||||
|
||||
do {
|
||||
let chunk;
|
||||
|
||||
chunk = subject.match(re);
|
||||
|
||||
if (chunk) {
|
||||
chunk = chunk[0];
|
||||
|
||||
subject = slice(subject, stringWidth(chunk));
|
||||
|
||||
chunk = chunk.trim();
|
||||
} else {
|
||||
chunk = slice(subject, 0, size);
|
||||
subject = slice(subject, size);
|
||||
}
|
||||
|
||||
chunks.push(chunk);
|
||||
} while (stringWidth(subject));
|
||||
|
||||
return chunks;
|
||||
};
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../src/wrapWord.js"],"names":["input","size","subject","chunks","re","RegExp","chunk","match","trim","push"],"mappings":";;;;;;;AAAA;;AACA;;;;AAEA;;;;;kBAKgBA,K,EAAOC,I,KAAS;AAC9B,MAAIC,OAAJ;AAEAA,EAAAA,OAAO,GAAGF,KAAV;AAEA,QAAMG,MAAM,GAAG,EAAf,CAL8B,CAO9B;;AACA,QAAMC,EAAE,GAAG,IAAIC,MAAJ,CAAW,WAAWJ,IAAX,GAAkB,mBAAlB,IAAyCA,IAAI,GAAG,CAAhD,IAAqD,wBAAhE,CAAX;;AAEA,KAAG;AACD,QAAIK,KAAJ;AAEAA,IAAAA,KAAK,GAAGJ,OAAO,CAACK,KAAR,CAAcH,EAAd,CAAR;;AAEA,QAAIE,KAAJ,EAAW;AACTA,MAAAA,KAAK,GAAGA,KAAK,CAAC,CAAD,CAAb;AAEAJ,MAAAA,OAAO,GAAG,wBAAMA,OAAN,EAAe,0BAAYI,KAAZ,CAAf,CAAV;AAEAA,MAAAA,KAAK,GAAGA,KAAK,CAACE,IAAN,EAAR;AACD,KAND,MAMO;AACLF,MAAAA,KAAK,GAAG,wBAAMJ,OAAN,EAAe,CAAf,EAAkBD,IAAlB,CAAR;AACAC,MAAAA,OAAO,GAAG,wBAAMA,OAAN,EAAeD,IAAf,CAAV;AACD;;AAEDE,IAAAA,MAAM,CAACM,IAAP,CAAYH,KAAZ;AACD,GAjBD,QAiBS,0BAAYJ,OAAZ,CAjBT;;AAmBA,SAAOC,MAAP;AACD,C","sourcesContent":["import slice from 'slice-ansi';\nimport stringWidth from 'string-width';\n\n/**\n * @param {string} input\n * @param {number} size\n * @returns {Array}\n */\nexport default (input, size) => {\n let subject;\n\n subject = input;\n\n const chunks = [];\n\n // https://regex101.com/r/gY5kZ1/1\n const re = new RegExp('(^.{1,' + size + '}(\\\\s+|$))|(^.{1,' + (size - 1) + '}(\\\\\\\\|/|_|\\\\.|,|;|-))');\n\n do {\n let chunk;\n\n chunk = subject.match(re);\n\n if (chunk) {\n chunk = chunk[0];\n\n subject = slice(subject, stringWidth(chunk));\n\n chunk = chunk.trim();\n } else {\n chunk = slice(subject, 0, size);\n subject = slice(subject, size);\n }\n\n chunks.push(chunk);\n } while (stringWidth(subject));\n\n return chunks;\n};\n"],"file":"wrapWord.js"}
|
||||
Reference in New Issue
Block a user