+6
| { | ||
| "stage": 0, | ||
| "plugins": [ | ||
| "lodash" | ||
| ] | ||
| } |
Sorry, the diff of this file is not supported yet
| language: node_js | ||
| node_js: | ||
| - '0.12' | ||
| - '0.11' | ||
| - '0.10' | ||
| install: | ||
| - npm install | ||
| notifications: | ||
| email: false |
| 'use strict'; | ||
| var _lodashLangIsString2 = require('lodash/lang/isString'); | ||
| var _lodashLangIsString3 = _interopRequireDefault(_lodashLangIsString2); | ||
| var _lodashLangIsNumber2 = require('lodash/lang/isNumber'); | ||
| var _lodashLangIsNumber3 = _interopRequireDefault(_lodashLangIsNumber2); | ||
| var _lodashStringRepeat2 = require('lodash/string/repeat'); | ||
| var _lodashStringRepeat3 = _interopRequireDefault(_lodashStringRepeat2); | ||
| var _lodashMathFloor2 = require('lodash/math/floor'); | ||
| var _lodashMathFloor3 = _interopRequireDefault(_lodashMathFloor2); | ||
| Object.defineProperty(exports, '__esModule', { | ||
| value: true | ||
| }); | ||
| var _stringWidth = require('string-width'); | ||
| var _stringWidth2 = _interopRequireDefault(_stringWidth); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
| var alignments = undefined; | ||
| alignments = ['left', 'right', 'center']; | ||
| /** | ||
| * @param {String} subject | ||
| * @param {Number} containerWidth | ||
| * @param {String} alignment (left, right, center) | ||
| * @return {String} | ||
| */ | ||
| exports['default'] = function (subject, containerWidth, alignment) { | ||
| var availableWidth = undefined, | ||
| halfAvailableWidth = undefined, | ||
| subjectWidth = undefined; | ||
| if (!(0, _lodashLangIsString3['default'])(subject)) { | ||
| throw new Error('Subject parameter value must be a string.'); | ||
| } | ||
| if (!(0, _lodashLangIsNumber3['default'])(containerWidth)) { | ||
| throw new Error('Container width parameter value must be a number.'); | ||
| } | ||
| subjectWidth = (0, _stringWidth2['default'])(subject); | ||
| if (subjectWidth > containerWidth) { | ||
| throw new Error('Subject parameter value width cannot be greater than the container width.'); | ||
| } | ||
| if (!(0, _lodashLangIsString3['default'])(alignment)) { | ||
| throw new Error('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).'); | ||
| } | ||
| availableWidth = containerWidth - subjectWidth; | ||
| if (alignment === 'left') { | ||
| return subject + (0, _lodashStringRepeat3['default'])(' ', availableWidth); | ||
| } | ||
| if (alignment === 'right') { | ||
| return (0, _lodashStringRepeat3['default'])(' ', availableWidth) + subject; | ||
| } | ||
| halfAvailableWidth = availableWidth / 2; | ||
| if (halfAvailableWidth % 2 === 0) { | ||
| return (0, _lodashStringRepeat3['default'])(' ', halfAvailableWidth) + subject + (0, _lodashStringRepeat3['default'])(' ', halfAvailableWidth); | ||
| } else { | ||
| halfAvailableWidth = (0, _lodashMathFloor3['default'])(halfAvailableWidth); | ||
| return (0, _lodashStringRepeat3['default'])(' ', halfAvailableWidth) + subject + (0, _lodashStringRepeat3['default'])(' ', halfAvailableWidth + 1); | ||
| } | ||
| }; | ||
| module.exports = exports['default']; | ||
| //# sourceMappingURL=align.js.map |
| {"version":3,"sources":["align.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;2BACwB,cAAc;;;;;;AAEtC,IAAI,UAAU,YAAA,CAAC;;AAEf,UAAU,GAAG,2BAIZ,CAAC;;;;;;;;;qBAQa,UAAC,OAAO,EAAE,cAAc,EAAE,SAAS,EAAK;AACnD,QAAI,cAAc,YAAA;QACd,kBAAkB,YAAA;QAClB,YAAY,YAAA,CAAC;;AAEjB,QAAI,CAAC,qCAAW,OAAO,CAAC,EAAE;AACtB,cAAM,IAAI,KAAK,6CAA6C,CAAC;KAChE;;AAED,QAAI,CAAC,qCAAW,cAAc,CAAC,EAAE;AAC7B,cAAM,IAAI,KAAK,qDAAqD,CAAC;KACxE;;AAED,gBAAY,GAAG,8BAAY,OAAO,CAAC,CAAC;;AAEpC,QAAI,YAAY,GAAG,cAAc,EAAE;AAC/B,cAAM,IAAI,KAAK,6EAA6E,CAAC;KAChG;;AAED,QAAI,CAAC,qCAAW,SAAS,CAAC,EAAE;AACxB,cAAM,IAAI,KAAK,+CAA+C,CAAC;KAClE;;AAED,QAAI,UAAU,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE;AACtC,cAAM,IAAI,KAAK,8FAA8F,CAAC;KACjH;;AAED,kBAAc,GAAG,cAAc,GAAG,YAAY,CAAC;;AAE/C,QAAI,SAAS,WAAW,EAAE;AACtB,eAAO,OAAO,GAAG,0CAAc,cAAc,CAAC,CAAC;KAClD;;AAED,QAAI,SAAS,YAAY,EAAE;AACvB,eAAO,0CAAc,cAAc,CAAC,GAAG,OAAO,CAAC;KAClD;;AAED,sBAAkB,GAAG,cAAc,GAAG,CAAC,CAAC;;AAExC,QAAI,kBAAkB,GAAG,CAAC,KAAK,CAAC,EAAE;AAC9B,eAAO,0CAAc,kBAAkB,CAAC,GAAG,OAAO,GAAG,0CAAc,kBAAkB,CAAC,CAAC;KAC1F,MAAM;AACH,0BAAkB,GAAG,kCAAQ,kBAAkB,CAAC,CAAC;;AAEjD,eAAO,0CAAc,kBAAkB,CAAC,GAAG,OAAO,GAAG,0CAAc,kBAAkB,GAAG,CAAC,CAAC,CAAC;KAC9F;CACJ","file":"align.js","sourcesContent":["import _ from 'lodash';\nimport stringWidth from 'string-width';\n\nlet alignments;\n\nalignments = [\n `left`,\n `right`,\n `center`\n];\n\n/**\n * @param {String} subject\n * @param {Number} containerWidth\n * @param {String} alignment (left, right, center)\n * @return {String}\n */\nexport default (subject, containerWidth, alignment) => {\n let availableWidth,\n halfAvailableWidth,\n subjectWidth;\n\n if (!_.isString(subject)) {\n throw new Error(`Subject parameter value must be a string.`);\n }\n\n if (!_.isNumber(containerWidth)) {\n throw new Error(`Container width parameter value must be a number.`);\n }\n\n subjectWidth = stringWidth(subject);\n\n if (subjectWidth > containerWidth) {\n throw new Error(`Subject parameter value width cannot be greater than the container width.`);\n }\n\n if (!_.isString(alignment)) {\n throw new Error(`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 availableWidth = containerWidth - subjectWidth;\n\n if (alignment === `left`) {\n return subject + _.repeat(` `, availableWidth);\n }\n\n if (alignment === `right`) {\n return _.repeat(` `, availableWidth) + subject;\n }\n\n halfAvailableWidth = availableWidth / 2;\n\n if (halfAvailableWidth % 2 === 0) {\n return _.repeat(` `, halfAvailableWidth) + subject + _.repeat(` `, halfAvailableWidth);\n } else {\n halfAvailableWidth = _.floor(halfAvailableWidth);\n\n return _.repeat(` `, halfAvailableWidth) + subject + _.repeat(` `, halfAvailableWidth + 1);\n }\n};\n"],"sourceRoot":"/source/"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| exports["default"] = { | ||
| topBody: "═", | ||
| topJoin: "╤", | ||
| topLeft: "╔", | ||
| topRight: "╗", | ||
| bottomBody: "═", | ||
| bottomJoin: "╧", | ||
| bottomLeft: "╚", | ||
| bottomRight: "╝", | ||
| bodyLeft: "║", | ||
| bodyRight: "║", | ||
| bodyJoin: "│", | ||
| joinBody: "─", | ||
| joinLeft: "╟", | ||
| joinRight: "╢", | ||
| joinJoin: "┼" | ||
| }; | ||
| module.exports = exports["default"]; | ||
| //# sourceMappingURL=border.js.map |
| {"version":3,"sources":["border.js"],"names":[],"mappings":";;;;;qBAAe;AACX,WAAO,KAAK;AACZ,WAAO,KAAK;AACZ,WAAO,KAAK;AACZ,YAAQ,KAAK;;AAEb,cAAU,KAAK;AACf,cAAU,KAAK;AACf,cAAU,KAAK;AACf,eAAW,KAAK;;AAEhB,YAAQ,KAAK;AACb,aAAS,KAAK;AACd,YAAQ,KAAK;;AAEb,YAAQ,KAAK;AACb,YAAQ,KAAK;AACb,aAAS,KAAK;AACd,YAAQ,KAAK;CAChB","file":"border.js","sourcesContent":["export default {\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"],"sourceRoot":"/source/"} |
| 'use strict'; | ||
| var _lodashArrayFill2 = require('lodash/array/fill'); | ||
| var _lodashArrayFill3 = _interopRequireDefault(_lodashArrayFill2); | ||
| var _lodashCollectionForEach2 = require('lodash/collection/forEach'); | ||
| var _lodashCollectionForEach3 = _interopRequireDefault(_lodashCollectionForEach2); | ||
| var _lodashLangIsUndefined2 = require('lodash/lang/isUndefined'); | ||
| var _lodashLangIsUndefined3 = _interopRequireDefault(_lodashLangIsUndefined2); | ||
| Object.defineProperty(exports, '__esModule', { | ||
| value: true | ||
| }); | ||
| var _stringWidth = require('string-width'); | ||
| var _stringWidth2 = _interopRequireDefault(_stringWidth); | ||
| /** | ||
| * Produces an array of values that describe the largest value length in the column. | ||
| * | ||
| * @param {Array[]} rows | ||
| * @return {Number[]} | ||
| */ | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
| exports['default'] = function (rows) { | ||
| var columns = undefined; | ||
| if (!rows[0]) { | ||
| throw new Error('Dataset must have at least one row.'); | ||
| } | ||
| columns = (0, _lodashArrayFill3['default'])(Array(rows[0].length), 0); | ||
| (0, _lodashCollectionForEach3['default'])(rows, function (row) { | ||
| (0, _lodashCollectionForEach3['default'])(row, function (value, index0) { | ||
| var valueLength = undefined; | ||
| valueLength = (0, _stringWidth2['default'])(value); | ||
| if ((0, _lodashLangIsUndefined3['default'])(columns[index0]) || columns[index0] < valueLength) { | ||
| columns[index0] = valueLength; | ||
| } | ||
| }); | ||
| }); | ||
| return columns; | ||
| }; | ||
| module.exports = exports['default']; | ||
| //# sourceMappingURL=calculateMaximumColumnValueIndex.js.map |
| {"version":3,"sources":["calculateMaximumColumnValueIndex.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;2BACuB,cAAc;;;;;;;;;;;;;qBAQtB,UAAC,IAAI,EAAK;AACrB,QAAI,OAAO,YAAA,CAAC;;AAEZ,QAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;AACV,cAAM,IAAI,KAAK,uCAAuC,CAAC;KAC1D;;AAED,WAAO,GAAG,kCAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;;AAE3C,8CAAU,IAAI,EAAE,UAAC,GAAG,EAAK;AACrB,kDAAU,GAAG,EAAE,UAAC,KAAK,EAAE,MAAM,EAAK;AAC9B,gBAAI,WAAW,YAAA,CAAC;;AAEhB,uBAAW,GAAG,8BAAW,KAAK,CAAC,CAAC;;AAEhC,gBAAI,wCAAc,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,GAAG,WAAW,EAAE;AACjE,uBAAO,CAAC,MAAM,CAAC,GAAG,WAAW,CAAC;aACjC;SACJ,CAAC,CAAC;KACN,CAAC,CAAC;;AAEH,WAAO,OAAO,CAAC;CAClB","file":"calculateMaximumColumnValueIndex.js","sourcesContent":["import _ from 'lodash';\nimport stringWith from 'string-width';\n\n/**\n * Produces an array of values that describe the largest value length in the column.\n *\n * @param {Array[]} rows\n * @return {Number[]}\n */\nexport default (rows) => {\n let columns;\n\n if (!rows[0]) {\n throw new Error(`Dataset must have at least one row.`);\n }\n\n columns = _.fill(Array(rows[0].length), 0);\n\n _.forEach(rows, (row) => {\n _.forEach(row, (value, index0) => {\n let valueLength;\n\n valueLength = stringWith(value);\n\n if (_.isUndefined(columns[index0]) || columns[index0] < valueLength) {\n columns[index0] = valueLength;\n }\n });\n });\n\n return columns;\n};\n"],"sourceRoot":"/source/"} |
| 'use strict'; | ||
| var _lodashCollectionMap2 = require('lodash/collection/map'); | ||
| var _lodashCollectionMap3 = _interopRequireDefault(_lodashCollectionMap2); | ||
| var _lodashStringRepeat2 = require('lodash/string/repeat'); | ||
| var _lodashStringRepeat3 = _interopRequireDefault(_lodashStringRepeat2); | ||
| Object.defineProperty(exports, '__esModule', { | ||
| value: true | ||
| }); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
| var drawBorder = undefined, | ||
| drawBorderBottom = undefined, | ||
| drawBorderJoin = undefined, | ||
| drawBorderTop = undefined; | ||
| /** | ||
| * @typedef drawBorder~parts | ||
| * @property {String} left | ||
| * @property {String} right | ||
| * @property {String} body | ||
| * @property {String} join | ||
| */ | ||
| /** | ||
| * @param {Number[]} columnSizeIndex | ||
| * @param {drawBorder~parts} parts | ||
| * @return {String} | ||
| */ | ||
| exports.drawBorder = drawBorder = function (columnSizeIndex, parts) { | ||
| var columns = undefined; | ||
| columns = (0, _lodashCollectionMap3['default'])(columnSizeIndex, function (size) { | ||
| return (0, _lodashStringRepeat3['default'])(parts.body, size); | ||
| }); | ||
| columns = columns.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 | ||
| * @return {String} | ||
| */ | ||
| exports.drawBorderTop = drawBorderTop = function (columnSizeIndex, parts) { | ||
| return drawBorder(columnSizeIndex, { | ||
| left: parts.topLeft, | ||
| right: parts.topRight, | ||
| body: parts.topBody, | ||
| join: parts.topJoin | ||
| }); | ||
| }; | ||
| /** | ||
| * @typedef drawBorderJoin~parts | ||
| * @property {String} joinLeft | ||
| * @property {String} joinRight | ||
| * @property {String} joinBody | ||
| * @property {String} joinJoin | ||
| */ | ||
| /** | ||
| * @param {Number[]} columnSizeIndex | ||
| * @param {drawBorderJoin~parts} parts | ||
| * @return {String} | ||
| */ | ||
| exports.drawBorderJoin = drawBorderJoin = function (columnSizeIndex, parts) { | ||
| return drawBorder(columnSizeIndex, { | ||
| left: parts.joinLeft, | ||
| right: parts.joinRight, | ||
| body: parts.joinBody, | ||
| join: parts.joinJoin | ||
| }); | ||
| }; | ||
| /** | ||
| * @typedef drawBorderBottom~parts | ||
| * @property {String} topLeft | ||
| * @property {String} topRight | ||
| * @property {String} topBody | ||
| * @property {String} topJoin | ||
| */ | ||
| /** | ||
| * @param {Number[]} columnSizeIndex | ||
| * @param {drawBorderBottom~parts} parts | ||
| * @return {String} | ||
| */ | ||
| exports.drawBorderBottom = drawBorderBottom = function (columnSizeIndex, parts) { | ||
| return drawBorder(columnSizeIndex, { | ||
| left: parts.bottomLeft, | ||
| right: parts.bottomRight, | ||
| body: parts.bottomBody, | ||
| join: parts.bottomJoin | ||
| }); | ||
| }; | ||
| exports.drawBorder = drawBorder; | ||
| exports.drawBorderTop = drawBorderTop; | ||
| exports.drawBorderJoin = drawBorderJoin; | ||
| exports.drawBorderBottom = drawBorderBottom; | ||
| //# sourceMappingURL=drawBorder.js.map |
| {"version":3,"sources":["drawBorder.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAEA,IAAI,UAAU,YAAA;IACV,gBAAgB,YAAA;IAChB,cAAc,YAAA;IACd,aAAa,YAAA,CAAC;;;;;;;;;;;;;;;AAelB,QA+EI,UAAU,GA/Ed,UAAU,GAAG,UAAC,eAAe,EAAE,KAAK,EAAK;AACrC,QAAI,OAAO,YAAA,CAAC;;AAEZ,WAAO,GAAG,sCAAM,eAAe,EAAE,UAAC,IAAI,EAAK;AACvC,eAAO,qCAAS,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;KACrC,CAAC,CAAC;;AAEH,WAAO,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;;AAEnC,gBAAU,KAAK,CAAC,IAAI,GAAG,OAAO,GAAG,KAAK,CAAC,KAAK,QAAK;CACpD,CAAC;;;;;;;;;;;;;;;AAeF,QAuDI,aAAa,GAvDjB,aAAa,GAAG,UAAC,eAAe,EAAE,KAAK,EAAK;AACxC,WAAO,UAAU,CAAC,eAAe,EAAE;AAC/B,YAAI,EAAE,KAAK,CAAC,OAAO;AACnB,aAAK,EAAE,KAAK,CAAC,QAAQ;AACrB,YAAI,EAAE,KAAK,CAAC,OAAO;AACnB,YAAI,EAAE,KAAK,CAAC,OAAO;KACtB,CAAC,CAAC;CACN,CAAC;;;;;;;;;;;;;;;AAeF,QAkCI,cAAc,GAlClB,cAAc,GAAG,UAAC,eAAe,EAAE,KAAK,EAAK;AACzC,WAAO,UAAU,CAAC,eAAe,EAAE;AAC/B,YAAI,EAAE,KAAK,CAAC,QAAQ;AACpB,aAAK,EAAE,KAAK,CAAC,SAAS;AACtB,YAAI,EAAE,KAAK,CAAC,QAAQ;AACpB,YAAI,EAAE,KAAK,CAAC,QAAQ;KACvB,CAAC,CAAC;CACN,CAAC;;;;;;;;;;;;;;;AAeF,QAaI,gBAAgB,GAbpB,gBAAgB,GAAG,UAAC,eAAe,EAAE,KAAK,EAAK;AAC3C,WAAO,UAAU,CAAC,eAAe,EAAE;AAC/B,YAAI,EAAE,KAAK,CAAC,UAAU;AACtB,aAAK,EAAE,KAAK,CAAC,WAAW;AACxB,YAAI,EAAE,KAAK,CAAC,UAAU;AACtB,YAAI,EAAE,KAAK,CAAC,UAAU;KACzB,CAAC,CAAC;CACN,CAAC;;QAGE,UAAU,GAAV,UAAU;QACV,aAAa,GAAb,aAAa;QACb,cAAc,GAAd,cAAc;QACd,gBAAgB,GAAhB,gBAAgB","file":"drawBorder.js","sourcesContent":["import _ from 'lodash';\n\nlet drawBorder,\n drawBorderBottom,\n drawBorderJoin,\n drawBorderTop;\n\n/**\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 * @return {String}\n */\ndrawBorder = (columnSizeIndex, parts) => {\n let columns;\n\n columns = _.map(columnSizeIndex, (size) => {\n return _.repeat(parts.body, size);\n });\n\n columns = columns.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 * @return {String}\n */\ndrawBorderTop = (columnSizeIndex, parts) => {\n return drawBorder(columnSizeIndex, {\n left: parts.topLeft,\n right: parts.topRight,\n body: parts.topBody,\n join: parts.topJoin\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 * @return {String}\n */\ndrawBorderJoin = (columnSizeIndex, parts) => {\n return drawBorder(columnSizeIndex, {\n left: parts.joinLeft,\n right: parts.joinRight,\n body: parts.joinBody,\n join: parts.joinJoin\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 * @return {String}\n */\ndrawBorderBottom = (columnSizeIndex, parts) => {\n return drawBorder(columnSizeIndex, {\n left: parts.bottomLeft,\n right: parts.bottomRight,\n body: parts.bottomBody,\n join: parts.bottomJoin\n });\n};\n\nexport {\n drawBorder,\n drawBorderTop,\n drawBorderJoin,\n drawBorderBottom\n};\n"],"sourceRoot":"/source/"} |
| /** | ||
| * @typedef {Object} drawRow~border | ||
| * @property {String} bodyLeft | ||
| * @property {String} bodyRight | ||
| * @property {String} bodyJoin | ||
| */ | ||
| /** | ||
| * @param {Number[]} columns | ||
| * @param {drawRow~border} border | ||
| * @return {String} | ||
| */ | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| exports["default"] = function (columns, border) { | ||
| return "" + border.bodyLeft + columns.join(border.bodyJoin) + border.bodyRight + "\n"; | ||
| }; | ||
| module.exports = exports["default"]; | ||
| //# sourceMappingURL=drawRow.js.map |
| {"version":3,"sources":["drawRow.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;qBAYe,UAAC,OAAO,EAAE,MAAM,EAAK;AAChC,cAAU,MAAM,CAAC,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC,SAAS,QAAK;CACpF","file":"drawRow.js","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 * @return {String}\n */\nexport default (columns, border) => {\n return `${border.bodyLeft}${columns.join(border.bodyJoin)}${border.bodyRight}\\n`;\n};\n"],"sourceRoot":"/source/"} |
| 'use strict'; | ||
| var _lodashCollectionMap2 = require('lodash/collection/map'); | ||
| var _lodashCollectionMap3 = _interopRequireDefault(_lodashCollectionMap2); | ||
| var _lodashArrayFill2 = require('lodash/array/fill'); | ||
| var _lodashArrayFill3 = _interopRequireDefault(_lodashArrayFill2); | ||
| Object.defineProperty(exports, '__esModule', { | ||
| value: true | ||
| }); | ||
| var _makeConfig = require('./makeConfig'); | ||
| var _makeConfig2 = _interopRequireDefault(_makeConfig); | ||
| /* eslint-disable no-loop-func */ | ||
| var _ansiSlice = require('ansi-slice'); | ||
| var _ansiSlice2 = _interopRequireDefault(_ansiSlice); | ||
| var _stringWidth = require('string-width'); | ||
| var _stringWidth2 = _interopRequireDefault(_stringWidth); | ||
| var _align = require('./align'); | ||
| var _align2 = _interopRequireDefault(_align); | ||
| /** | ||
| * @typedef formatData~columnConfig | ||
| * @property {String} align | ||
| * @property {Number} minWidth | ||
| * @property {Number} maxWidth | ||
| */ | ||
| /** | ||
| * @typedef formatData~config | ||
| * @property {formatData~columnConfig[]} columnConfig Column specific configuration. | ||
| */ | ||
| /** | ||
| * Transforms data rows to rows fit for printing in the CLI. Transformation consists of | ||
| * enforcing a fixed text width for values that are shorter than columnWidth and | ||
| * breaking values that are longer than columnWidth into two or more rows. | ||
| * | ||
| * The current implementation assumes RTL text alignment. | ||
| * | ||
| * @param {Array[]} rows | ||
| * @param {formatData~config} config | ||
| * @return {Array[]} | ||
| */ | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
| exports['default'] = function (rows) { | ||
| var config = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
| var derivedConfig = undefined, | ||
| formattedData = undefined, | ||
| index0 = undefined; | ||
| index0 = 0; | ||
| formattedData = (0, _lodashCollectionMap3['default'])(rows, function (columns) { | ||
| return (0, _lodashCollectionMap3['default'])(columns, function (cell) { | ||
| return String(cell); | ||
| }); | ||
| }); | ||
| derivedConfig = (0, _makeConfig2['default'])(formattedData, config); | ||
| var _loop = function () { | ||
| var nextRow = undefined, | ||
| row = undefined; | ||
| row = formattedData[index0]; | ||
| formattedData[index0] = (0, _lodashCollectionMap3['default'])(formattedData[index0], function (value, index1) { | ||
| var columnConfig = undefined; | ||
| columnConfig = derivedConfig.columnConfig[index1]; | ||
| if ((0, _stringWidth2['default'])(value) > columnConfig.maxWidth) { | ||
| if (!nextRow) { | ||
| nextRow = (0, _lodashArrayFill3['default'])([], '', 0, row.length); | ||
| formattedData.splice(index0 + 1, 0, nextRow); | ||
| } | ||
| nextRow[index1] = (0, _ansiSlice2['default'])(value, columnConfig.maxWidth); | ||
| return (0, _ansiSlice2['default'])(value, 0, columnConfig.maxWidth); | ||
| } | ||
| return (0, _align2['default'])(value, columnConfig.minWidth, columnConfig.alignment); | ||
| }); | ||
| index0++; | ||
| }; | ||
| while (index0 < formattedData.length) { | ||
| _loop(); | ||
| } | ||
| return formattedData; | ||
| }; | ||
| module.exports = exports['default']; | ||
| //# sourceMappingURL=formatData.js.map |
| {"version":3,"sources":["formatData.js"],"names":[],"mappings":";;;;;;;;;;;;;;0BAIuB,cAAc;;;;;;yBAEnB,YAAY;;;;2BAEN,cAAc;;;;qBAEpB,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAyBZ,UAAC,IAAI,EAAkB;QAAhB,MAAM,yDAAG,EAAE;;AAC7B,QAAI,aAAa,YAAA;QACb,aAAa,YAAA;QACb,MAAM,YAAA,CAAC;;AAEX,UAAM,GAAG,CAAC,CAAC;;AAEX,iBAAa,GAAG,sCAAM,IAAI,EAAE,UAAC,OAAO,EAAK;AACrC,eAAO,sCAAM,OAAO,EAAE,UAAC,IAAI,EAAK;AAC5B,mBAAO,MAAM,CAAC,IAAI,CAAC,CAAC;SACvB,CAAC,CAAC;KACN,CAAC,CAAC;;AAEH,iBAAa,GAAG,6BAAW,aAAa,EAAE,MAAM,CAAC,CAAC;;;AAG9C,YAAI,OAAO,YAAA;YACP,GAAG,YAAA,CAAC;;AAER,WAAG,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;;AAE5B,qBAAa,CAAC,MAAM,CAAC,GAAG,sCAAM,aAAa,CAAC,MAAM,CAAC,EAAE,UAAC,KAAK,EAAE,MAAM,EAAK;AACpE,gBAAI,YAAY,YAAA,CAAC;;AAEjB,wBAAY,GAAG,aAAa,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;;AAElD,gBAAI,8BAAY,KAAK,CAAC,GAAG,YAAY,CAAC,QAAQ,EAAE;AAC5C,oBAAI,CAAC,OAAO,EAAE;AACV,2BAAO,GAAG,kCAAO,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;;AAExC,iCAAa,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;iBAChD;;AAED,uBAAO,CAAC,MAAM,CAAC,GAAG,4BAAM,KAAK,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC;;AAEtD,uBAAO,4BAAM,KAAK,EAAE,CAAC,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC;aACjD;;AAED,mBAAO,wBAAM,KAAK,EAAE,YAAY,CAAC,QAAQ,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;SACtE,CAAC,CAAC;;AAEH,cAAM,EAAE,CAAC;;;AA1Bb,WAAO,MAAM,GAAG,aAAa,CAAC,MAAM,EAAE;;KA2BrC;;AAED,WAAO,aAAa,CAAC;CACxB","file":"formatData.js","sourcesContent":["/* eslint-disable no-loop-func */\n\nimport _ from 'lodash';\n\nimport makeConfig from './makeConfig';\n\nimport slice from 'ansi-slice';\n\nimport stringWidth from 'string-width';\n\nimport align from './align';\n\n/**\n * @typedef formatData~columnConfig\n * @property {String} align\n * @property {Number} minWidth\n * @property {Number} maxWidth\n */\n\n/**\n * @typedef formatData~config\n * @property {formatData~columnConfig[]} columnConfig Column specific configuration.\n */\n\n/**\n * Transforms data rows to rows fit for printing in the CLI. Transformation consists of\n * enforcing a fixed text width for values that are shorter than columnWidth and\n * breaking values that are longer than columnWidth into two or more rows.\n *\n * The current implementation assumes RTL text alignment.\n *\n * @param {Array[]} rows\n * @param {formatData~config} config\n * @return {Array[]}\n */\nexport default (rows, config = {}) => {\n let derivedConfig,\n formattedData,\n index0;\n\n index0 = 0;\n\n formattedData = _.map(rows, (columns) => {\n return _.map(columns, (cell) => {\n return String(cell);\n });\n });\n\n derivedConfig = makeConfig(formattedData, config);\n\n while (index0 < formattedData.length) {\n let nextRow,\n row;\n\n row = formattedData[index0];\n\n formattedData[index0] = _.map(formattedData[index0], (value, index1) => {\n let columnConfig;\n\n columnConfig = derivedConfig.columnConfig[index1];\n\n if (stringWidth(value) > columnConfig.maxWidth) {\n if (!nextRow) {\n nextRow = _.fill([], ``, 0, row.length);\n\n formattedData.splice(index0 + 1, 0, nextRow);\n }\n\n nextRow[index1] = slice(value, columnConfig.maxWidth);\n\n return slice(value, 0, columnConfig.maxWidth);\n }\n\n return align(value, columnConfig.minWidth, columnConfig.alignment);\n });\n\n index0++;\n }\n\n return formattedData;\n};\n"],"sourceRoot":"/source/"} |
| 'use strict'; | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
| var _table = require('./table'); | ||
| var _table2 = _interopRequireDefault(_table); | ||
| //# sourceMappingURL=index.js.map |
| {"version":3,"sources":["index.js"],"names":[],"mappings":";;;;qBAAkB,SAAS","file":"index.js","sourcesContent":["import table from './table';\n"],"sourceRoot":"/source/"} |
| 'use strict'; | ||
| var _lodashCollectionMap2 = require('lodash/collection/map'); | ||
| var _lodashCollectionMap3 = _interopRequireDefault(_lodashCollectionMap2); | ||
| var _lodashLangIsUndefined2 = require('lodash/lang/isUndefined'); | ||
| var _lodashLangIsUndefined3 = _interopRequireDefault(_lodashLangIsUndefined2); | ||
| Object.defineProperty(exports, '__esModule', { | ||
| value: true | ||
| }); | ||
| var _validateConfig = require('./validateConfig'); | ||
| var _validateConfig2 = _interopRequireDefault(_validateConfig); | ||
| var _calculateMaximumColumnValueIndex = require('./calculateMaximumColumnValueIndex'); | ||
| var _calculateMaximumColumnValueIndex2 = _interopRequireDefault(_calculateMaximumColumnValueIndex); | ||
| /** | ||
| * @param {Array[]} rows | ||
| * @param {formatData~config} config | ||
| * @return {formatData~config} | ||
| */ | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
| exports['default'] = function (rows) { | ||
| var config = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
| var maximumColumnValueIndex = undefined; | ||
| (0, _validateConfig2['default'])(rows, config); | ||
| maximumColumnValueIndex = (0, _calculateMaximumColumnValueIndex2['default'])(rows); | ||
| config.columnConfig = config.columnConfig || Array(rows[0].length); | ||
| config.columnConfig = (0, _lodashCollectionMap3['default'])(config.columnConfig, function (column, index0) { | ||
| if (column === undefined) column = {}; | ||
| if ((0, _lodashLangIsUndefined3['default'])(column.minWidth) || maximumColumnValueIndex[index0] > config.columnConfig[index0].minWidth) { | ||
| column.minWidth = maximumColumnValueIndex[index0]; | ||
| } | ||
| if ((0, _lodashLangIsUndefined3['default'])(column.alignment)) { | ||
| column.alignment = 'left'; | ||
| } | ||
| if ((0, _lodashLangIsUndefined3['default'])(column.maxWidth)) { | ||
| column.maxWidth = Infinity; | ||
| } else if (column.maxWidth < column.minWidth) { | ||
| column.minWidth = column.maxWidth; | ||
| } | ||
| return column; | ||
| }); | ||
| return config; | ||
| }; | ||
| module.exports = exports['default']; | ||
| //# sourceMappingURL=makeConfig.js.map |
| {"version":3,"sources":["makeConfig.js"],"names":[],"mappings":";;;;;;;;;;;;;;8BAE2B,kBAAkB;;;;gDACA,oCAAoC;;;;;;;;;;;;qBAOlE,UAAC,IAAI,EAAkB;QAAhB,MAAM,yDAAG,EAAE;;AAC7B,QAAI,uBAAuB,YAAA,CAAC;;AAE5B,qCAAe,IAAI,EAAE,MAAM,CAAC,CAAC;;AAE7B,2BAAuB,GAAG,mDAAiC,IAAI,CAAC,CAAC;;AAEjE,UAAM,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;;AAEnE,UAAM,CAAC,YAAY,GAAG,sCAAM,MAAM,CAAC,YAAY,EAAE,UAAC,MAAM,EAAO,MAAM,EAAK;YAAxB,MAAM,gBAAN,MAAM,GAAG,EAAE;;AACzD,YAAI,wCAAc,MAAM,CAAC,QAAQ,CAAC,IAAI,uBAAuB,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE;AAC1G,kBAAM,CAAC,QAAQ,GAAG,uBAAuB,CAAC,MAAM,CAAC,CAAC;SACrD;;AAED,YAAI,wCAAc,MAAM,CAAC,SAAS,CAAC,EAAE;AACjC,kBAAM,CAAC,SAAS,SAAS,CAAC;SAC7B;;AAED,YAAI,wCAAc,MAAM,CAAC,QAAQ,CAAC,EAAE;AAChC,kBAAM,CAAC,QAAQ,GAAG,QAAQ,CAAC;SAC9B,MAAM,IAAI,MAAM,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,EAAE;AAC1C,kBAAM,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;SACrC;;AAED,eAAO,MAAM,CAAC;KACjB,CAAC,CAAC;;AAEH,WAAO,MAAM,CAAC;CACjB","file":"makeConfig.js","sourcesContent":["import _ from 'lodash';\n\nimport validateConfig from './validateConfig';\nimport calculateMaximumColumnValueIndex from './calculateMaximumColumnValueIndex';\n\n/**\n * @param {Array[]} rows\n * @param {formatData~config} config\n * @return {formatData~config}\n */\nexport default (rows, config = {}) => {\n let maximumColumnValueIndex;\n\n validateConfig(rows, config);\n\n maximumColumnValueIndex = calculateMaximumColumnValueIndex(rows);\n\n config.columnConfig = config.columnConfig || Array(rows[0].length);\n\n config.columnConfig = _.map(config.columnConfig, (column = {}, index0) => {\n if (_.isUndefined(column.minWidth) || maximumColumnValueIndex[index0] > config.columnConfig[index0].minWidth) {\n column.minWidth = maximumColumnValueIndex[index0];\n }\n\n if (_.isUndefined(column.alignment)) {\n column.alignment = `left`;\n }\n\n if (_.isUndefined(column.maxWidth)) {\n column.maxWidth = Infinity;\n } else if (column.maxWidth < column.minWidth) {\n column.minWidth = column.maxWidth;\n }\n\n return column;\n });\n\n return config;\n};\n"],"sourceRoot":"/source/"} |
| 'use strict'; | ||
| var _lodashCollectionMap2 = require('lodash/collection/map'); | ||
| var _lodashCollectionMap3 = _interopRequireDefault(_lodashCollectionMap2); | ||
| var _lodashCollectionForEach2 = require('lodash/collection/forEach'); | ||
| var _lodashCollectionForEach3 = _interopRequireDefault(_lodashCollectionForEach2); | ||
| Object.defineProperty(exports, '__esModule', { | ||
| value: true | ||
| }); | ||
| var _border = require('./border'); | ||
| var _border2 = _interopRequireDefault(_border); | ||
| var _drawBorder = require('./drawBorder'); | ||
| var _drawRow = require('./drawRow'); | ||
| var _drawRow2 = _interopRequireDefault(_drawRow); | ||
| var _formatData = require('./formatData'); | ||
| var _formatData2 = _interopRequireDefault(_formatData); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
| var drawTop = undefined, | ||
| getColumnSizeIndex = undefined; | ||
| /** | ||
| * @param {String[]} columns | ||
| * @return {Number[]} | ||
| */ | ||
| getColumnSizeIndex = function (columns) { | ||
| return (0, _lodashCollectionMap3['default'])(columns, function (data) { | ||
| return data.length; | ||
| }); | ||
| }; | ||
| exports['default'] = function (data) { | ||
| var table = undefined, | ||
| columnSizeIndex = undefined, | ||
| rows = undefined; | ||
| rows = (0, _formatData2['default'])(data); | ||
| columnSizeIndex = getColumnSizeIndex(rows[0]); | ||
| table = ''; | ||
| table += (0, _drawBorder.drawBorderTop)(columnSizeIndex, _border2['default']); | ||
| (0, _lodashCollectionForEach3['default'])(rows, function (row, i) { | ||
| table += (0, _drawRow2['default'])(row, _border2['default']); | ||
| if (i + 1 !== rows.length) { | ||
| table += (0, _drawBorder.drawBorderJoin)(columnSizeIndex, _border2['default']); | ||
| } | ||
| }); | ||
| table += (0, _drawBorder.drawBorderBottom)(columnSizeIndex, _border2['default']); | ||
| return table; | ||
| }; | ||
| module.exports = exports['default']; | ||
| //# sourceMappingURL=table.js.map |
| {"version":3,"sources":["table.js"],"names":[],"mappings":";;;;;;;;;;;;;;sBAEmB,UAAU;;;;0BAMtB,cAAc;;uBAED,WAAW;;;;0BAER,cAAc;;;;;;AAErC,IAAI,OAAO,YAAA;IACP,kBAAkB,YAAA,CAAC;;;;;;AAMvB,kBAAkB,GAAG,UAAC,OAAO,EAAK;AAC9B,WAAO,sCAAM,OAAO,EAAE,UAAC,IAAI,EAAK;AAC5B,eAAO,IAAI,CAAC,MAAM,CAAC;KACtB,CAAC,CAAC;CACN,CAAC;;qBAEa,UAAC,IAAI,EAAK;AACrB,QAAI,KAAK,YAAA;QACL,eAAe,YAAA;QACf,IAAI,YAAA,CAAC;;AAET,QAAI,GAAG,6BAAW,IAAI,CAAC,CAAC;;AAExB,mBAAe,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;;AAE9C,SAAK,GAAG,EAAE,CAAC;AACX,SAAK,IAAI,+BAAc,eAAe,sBAAS,CAAC;;AAEhD,8CAAU,IAAI,EAAE,UAAC,GAAG,EAAE,CAAC,EAAK;AACxB,aAAK,IAAI,0BAAQ,GAAG,sBAAS,CAAC;;AAE9B,YAAI,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,MAAM,EAAE;AACvB,iBAAK,IAAI,gCAAe,eAAe,sBAAS,CAAC;SACpD;KACJ,CAAC,CAAC;;AAEH,SAAK,IAAI,kCAAiB,eAAe,sBAAS,CAAC;;AAEnD,WAAO,KAAK,CAAC;CAChB","file":"table.js","sourcesContent":["import _ from 'lodash';\n\nimport border from './border';\n\nimport {\n drawBorderTop,\n drawBorderJoin,\n drawBorderBottom\n} from './drawBorder';\n\nimport drawRow from './drawRow';\n\nimport formatData from './formatData';\n\nlet drawTop,\n getColumnSizeIndex;\n\n/**\n * @param {String[]} columns\n * @return {Number[]}\n */\ngetColumnSizeIndex = (columns) => {\n return _.map(columns, (data) => {\n return data.length;\n });\n};\n\nexport default (data) => {\n let table,\n columnSizeIndex,\n rows;\n\n rows = formatData(data);\n\n columnSizeIndex = getColumnSizeIndex(rows[0]);\n\n table = '';\n table += drawBorderTop(columnSizeIndex, border);\n\n _.forEach(rows, (row, i) => {\n table += drawRow(row, border);\n\n if (i + 1 !== rows.length) {\n table += drawBorderJoin(columnSizeIndex, border);\n }\n });\n\n table += drawBorderBottom(columnSizeIndex, border);\n\n return table;\n};\n"],"sourceRoot":"/source/"} |
| 'use strict'; | ||
| var _lodashArrayFirst2 = require('lodash/array/first'); | ||
| var _lodashArrayFirst3 = _interopRequireDefault(_lodashArrayFirst2); | ||
| var _lodashArrayDifference2 = require('lodash/array/difference'); | ||
| var _lodashArrayDifference3 = _interopRequireDefault(_lodashArrayDifference2); | ||
| var _lodashObjectKeys2 = require('lodash/object/keys'); | ||
| var _lodashObjectKeys3 = _interopRequireDefault(_lodashObjectKeys2); | ||
| var _lodashCollectionForEach2 = require('lodash/collection/forEach'); | ||
| var _lodashCollectionForEach3 = _interopRequireDefault(_lodashCollectionForEach2); | ||
| var _lodashLangIsUndefined2 = require('lodash/lang/isUndefined'); | ||
| var _lodashLangIsUndefined3 = _interopRequireDefault(_lodashLangIsUndefined2); | ||
| Object.defineProperty(exports, '__esModule', { | ||
| value: true | ||
| }); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
| /** | ||
| * @param {row[]} rows | ||
| * @param {formatData~config} config | ||
| * @return {undefined} | ||
| */ | ||
| exports['default'] = function (rows) { | ||
| var config = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
| var unknownPropertyName = undefined; | ||
| unknownPropertyName = (0, _lodashArrayFirst3['default'])((0, _lodashArrayDifference3['default'])((0, _lodashObjectKeys3['default'])(config), ['columnConfig'])); | ||
| if (unknownPropertyName) { | ||
| throw new Error('Config must not define unknown properties. "' + unknownPropertyName + '" is an unknown property.'); | ||
| } | ||
| if (config.columnConfig) { | ||
| (0, _lodashCollectionForEach3['default'])(config.columnConfig, function (columnConfig) { | ||
| unknownPropertyName = (0, _lodashArrayFirst3['default'])((0, _lodashArrayDifference3['default'])((0, _lodashObjectKeys3['default'])(columnConfig), ['align', 'minWidth', 'maxWidth'])); | ||
| if (unknownPropertyName) { | ||
| throw new Error('Column config must not define unknown properties. "' + unknownPropertyName + '" is an unknown property.'); | ||
| } | ||
| if (!(0, _lodashLangIsUndefined3['default'])(columnConfig.minWidth) && !(0, _lodashLangIsUndefined3['default'])(columnConfig.maxWidth) && columnConfig.minWidth > columnConfig.maxWidth) { | ||
| throw new Error('Column minWidth cannot be greater than maxWidth.'); | ||
| } | ||
| }); | ||
| } | ||
| }; | ||
| module.exports = exports['default']; | ||
| //# sourceMappingURL=validateConfig.js.map |
| {"version":3,"sources":["validateConfig.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAOe,UAAC,IAAI,EAAkB;QAAhB,MAAM,yDAAG,EAAE;;AAC7B,QAAI,mBAAmB,YAAA,CAAC;;AAExB,uBAAmB,GAAG,mCAAQ,wCAAa,mCAAO,MAAM,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC;;AAE9E,QAAI,mBAAmB,EAAE;AACrB,cAAM,IAAI,KAAK,kDAAgD,mBAAmB,+BAA4B,CAAC;KAClH;;AAED,QAAI,MAAM,CAAC,YAAY,EAAE;AACrB,kDAAU,MAAM,CAAC,YAAY,EAAE,UAAC,YAAY,EAAK;AAC7C,+BAAmB,GAAG,mCAAQ,wCAAa,mCAAO,YAAY,CAAC,EAAE,iCAAiC,CAAC,CAAC,CAAC;;AAErG,gBAAI,mBAAmB,EAAE;AACrB,sBAAM,IAAI,KAAK,yDAAuD,mBAAmB,+BAA4B,CAAC;aACzH;;AAED,gBAAI,CAAC,wCAAc,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,wCAAc,YAAY,CAAC,QAAQ,CAAC,IAAI,YAAY,CAAC,QAAQ,GAAG,YAAY,CAAC,QAAQ,EAAE;AACjI,sBAAM,IAAI,KAAK,oDAAoD,CAAC;aACvE;SACJ,CAAC,CAAC;KACN;CACJ","file":"validateConfig.js","sourcesContent":["import _ from 'lodash';\n\n/**\n * @param {row[]} rows\n * @param {formatData~config} config\n * @return {undefined}\n */\nexport default (rows, config = {}) => {\n let unknownPropertyName;\n\n unknownPropertyName = _.first(_.difference(_.keys(config), [`columnConfig`]));\n\n if (unknownPropertyName) {\n throw new Error(`Config must not define unknown properties. \"${unknownPropertyName}\" is an unknown property.`);\n }\n\n if (config.columnConfig) {\n _.forEach(config.columnConfig, (columnConfig) => {\n unknownPropertyName = _.first(_.difference(_.keys(columnConfig), [`align`, `minWidth`, `maxWidth`]));\n\n if (unknownPropertyName) {\n throw new Error(`Column config must not define unknown properties. \"${unknownPropertyName}\" is an unknown property.`);\n }\n\n if (!_.isUndefined(columnConfig.minWidth) && !_.isUndefined(columnConfig.maxWidth) && columnConfig.minWidth > columnConfig.maxWidth) {\n throw new Error(`Column minWidth cannot be greater than maxWidth.`);\n }\n });\n }\n};\n"],"sourceRoot":"/source/"} |
| 'use strict'; | ||
| var _lodashLangIsArray2 = require('lodash/lang/isArray'); | ||
| var _lodashLangIsArray3 = _interopRequireDefault(_lodashLangIsArray2); | ||
| var _lodashCollectionForEach2 = require('lodash/collection/forEach'); | ||
| var _lodashCollectionForEach3 = _interopRequireDefault(_lodashCollectionForEach2); | ||
| Object.defineProperty(exports, '__esModule', { | ||
| value: true | ||
| }); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
| /** | ||
| * @typedef {String} validateData~cell | ||
| */ | ||
| /** | ||
| * @typedef {validateData~cell[]} validateData~column | ||
| */ | ||
| /** | ||
| * @param {validateData~column[]} rows | ||
| * @return {undefined} | ||
| */ | ||
| exports['default'] = function (rows) { | ||
| var columnNumber = undefined; | ||
| if (!(0, _lodashLangIsArray3['default'])(rows)) { | ||
| throw new Error('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.'); | ||
| } | ||
| columnNumber = rows[0].length; | ||
| (0, _lodashCollectionForEach3['default'])(rows, function (columns) { | ||
| if (!(0, _lodashLangIsArray3['default'])(columns)) { | ||
| throw new Error('Table row data must be an array.'); | ||
| } | ||
| if (columns.length !== columnNumber) { | ||
| throw new Error('Table must have a consistent number of columns.'); | ||
| } | ||
| (0, _lodashCollectionForEach3['default'])(columns, function (cell) { | ||
| if (/[\x01-\x1A]/.test(cell)) { | ||
| throw new Error('Table data must not contain control characters.'); | ||
| } | ||
| }); | ||
| }); | ||
| }; | ||
| module.exports = exports['default']; | ||
| //# sourceMappingURL=validateData.js.map |
| {"version":3,"sources":["validateData.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAce,UAAC,IAAI,EAAK;AACrB,QAAI,YAAY,YAAA,CAAC;;AAEjB,QAAI,CAAC,oCAAU,IAAI,CAAC,EAAE;AAClB,cAAM,IAAI,KAAK,gCAAgC,CAAC;KACnD;;AAED,QAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;AACnB,cAAM,IAAI,KAAK,uCAAuC,CAAC;KAC1D;;AAED,QAAI,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;AACtB,cAAM,IAAI,KAAK,0CAA0C,CAAC;KAC7D;;AAED,gBAAY,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;;AAE9B,8CAAU,IAAI,EAAE,UAAC,OAAO,EAAK;AACzB,YAAI,CAAC,oCAAU,OAAO,CAAC,EAAE;AACrB,kBAAM,IAAI,KAAK,oCAAoC,CAAC;SACvD;;AAED,YAAI,OAAO,CAAC,MAAM,KAAK,YAAY,EAAE;AACjC,kBAAM,IAAI,KAAK,mDAAmD,CAAC;SACtE;;AAED,kDAAU,OAAO,EAAE,UAAC,IAAI,EAAK;AACzB,gBAAI,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;AAC1B,sBAAM,IAAI,KAAK,mDAAmD,CAAC;aACtE;SACJ,CAAC,CAAC;KACN,CAAC,CAAC;CACN","file":"validateData.js","sourcesContent":["import _ from 'lodash';\n\n/**\n * @typedef {String} validateData~cell\n */\n\n/**\n * @typedef {validateData~cell[]} validateData~column\n */\n\n/**\n * @param {validateData~column[]} rows\n * @return {undefined}\n */\nexport default (rows) => {\n let columnNumber;\n\n if (!_.isArray(rows)) {\n throw new Error(`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 columnNumber = rows[0].length;\n\n _.forEach(rows, (columns) => {\n if (!_.isArray(columns)) {\n throw new Error(`Table row data must be an array.`);\n }\n\n if (columns.length !== columnNumber) {\n throw new Error(`Table must have a consistent number of columns.`);\n }\n\n _.forEach(columns, (cell) => {\n if (/[\\x01-\\x1A]/.test(cell)) {\n throw new Error(`Table data must not contain control characters.`);\n }\n });\n });\n};\n"],"sourceRoot":"/source/"} |
+59
| import gulp from 'gulp'; | ||
| import del from 'del'; | ||
| import mocha from 'gulp-mocha'; | ||
| import babel from 'gulp-babel'; | ||
| import gutil from 'gulp-util'; | ||
| import sourcemaps from 'gulp-sourcemaps'; | ||
| import glob from 'globby'; | ||
| /* import { | ||
| lintFiles, | ||
| getPrinter | ||
| } from 'canonical'; */ | ||
| gulp.task('lint', () => { | ||
| return; | ||
| return glob(['./src/**/*.js', './test/**/*.js']) | ||
| .then((paths) => { | ||
| let printer, | ||
| report; | ||
| printer = getPrinter(); | ||
| report = lintFiles(paths); | ||
| if (report.errorCount || report.warningCount) { | ||
| console.log(printer(report)); | ||
| } | ||
| }); | ||
| }); | ||
| gulp.task('clean', ['lint'], () => { | ||
| return del([ | ||
| './dist/*', | ||
| ]); | ||
| }); | ||
| gulp.task('build-es5', ['clean'], () => { | ||
| return gulp | ||
| .src('./src/*') | ||
| .pipe(sourcemaps.init()) | ||
| .pipe(babel()) | ||
| .pipe(sourcemaps.write('./')) | ||
| .pipe(gulp.dest('./dist')); | ||
| }); | ||
| gulp.task('test', ['build-es5'], (done) => { | ||
| return gulp | ||
| .src('./test/**/*.js', { | ||
| read: false | ||
| }) | ||
| .pipe(mocha()); | ||
| }); | ||
| gulp.task('build', ['test']); | ||
| gulp.task('default', ['build']); | ||
| gulp.task('watch', () => { | ||
| gulp.watch(['./src/**/*', './test/**/*'], ['default']); | ||
| }); |
+24
| Copyright (c) 2015, Gajus Kuizinas (http://gajus.com/) | ||
| All rights reserved. | ||
| Redistribution and use in source and binary forms, with or without | ||
| modification, are permitted provided that the following conditions are met: | ||
| * Redistributions of source code must retain the above copyright | ||
| notice, this list of conditions and the following disclaimer. | ||
| * Redistributions in binary form must reproduce the above copyright | ||
| notice, this list of conditions and the following disclaimer in the | ||
| documentation and/or other materials provided with the distribution. | ||
| * Neither the name of the Gajus Kuizinas (http://gajus.com/) nor the | ||
| names of its contributors may be used to endorse or promote products | ||
| derived from this software without specific prior written permission. | ||
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
| ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
| WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
| DISCLAIMED. IN NO EVENT SHALL ANUARY BE LIABLE FOR ANY | ||
| DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
| (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
| ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+64
| import _ from 'lodash'; | ||
| import stringWidth from 'string-width'; | ||
| let alignments; | ||
| alignments = [ | ||
| `left`, | ||
| `right`, | ||
| `center` | ||
| ]; | ||
| /** | ||
| * @param {String} subject | ||
| * @param {Number} containerWidth | ||
| * @param {String} alignment (left, right, center) | ||
| * @return {String} | ||
| */ | ||
| export default (subject, containerWidth, alignment) => { | ||
| let availableWidth, | ||
| halfAvailableWidth, | ||
| subjectWidth; | ||
| if (!_.isString(subject)) { | ||
| throw new Error(`Subject parameter value must be a string.`); | ||
| } | ||
| if (!_.isNumber(containerWidth)) { | ||
| throw new Error(`Container width parameter value must be a number.`); | ||
| } | ||
| subjectWidth = stringWidth(subject); | ||
| if (subjectWidth > containerWidth) { | ||
| throw new Error(`Subject parameter value width cannot be greater than the container width.`); | ||
| } | ||
| if (!_.isString(alignment)) { | ||
| throw new Error(`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).`); | ||
| } | ||
| availableWidth = containerWidth - subjectWidth; | ||
| if (alignment === `left`) { | ||
| return subject + _.repeat(` `, availableWidth); | ||
| } | ||
| if (alignment === `right`) { | ||
| return _.repeat(` `, availableWidth) + subject; | ||
| } | ||
| halfAvailableWidth = availableWidth / 2; | ||
| if (halfAvailableWidth % 2 === 0) { | ||
| return _.repeat(` `, halfAvailableWidth) + subject + _.repeat(` `, halfAvailableWidth); | ||
| } else { | ||
| halfAvailableWidth = _.floor(halfAvailableWidth); | ||
| return _.repeat(` `, halfAvailableWidth) + subject + _.repeat(` `, halfAvailableWidth + 1); | ||
| } | ||
| }; |
| export default { | ||
| topBody: `═`, | ||
| topJoin: `╤`, | ||
| topLeft: `╔`, | ||
| topRight: `╗`, | ||
| bottomBody: `═`, | ||
| bottomJoin: `╧`, | ||
| bottomLeft: `╚`, | ||
| bottomRight: `╝`, | ||
| bodyLeft: `║`, | ||
| bodyRight: `║`, | ||
| bodyJoin: `│`, | ||
| joinBody: `─`, | ||
| joinLeft: `╟`, | ||
| joinRight: `╢`, | ||
| joinJoin: `┼` | ||
| }; |
| import _ from 'lodash'; | ||
| import stringWith from 'string-width'; | ||
| /** | ||
| * Produces an array of values that describe the largest value length in the column. | ||
| * | ||
| * @param {Array[]} rows | ||
| * @return {Number[]} | ||
| */ | ||
| export default (rows) => { | ||
| let columns; | ||
| if (!rows[0]) { | ||
| throw new Error(`Dataset must have at least one row.`); | ||
| } | ||
| columns = _.fill(Array(rows[0].length), 0); | ||
| _.forEach(rows, (row) => { | ||
| _.forEach(row, (value, index0) => { | ||
| let valueLength; | ||
| valueLength = stringWith(value); | ||
| if (_.isUndefined(columns[index0]) || columns[index0] < valueLength) { | ||
| columns[index0] = valueLength; | ||
| } | ||
| }); | ||
| }); | ||
| return columns; | ||
| }; |
| import _ from 'lodash'; | ||
| let drawBorder, | ||
| drawBorderBottom, | ||
| drawBorderJoin, | ||
| drawBorderTop; | ||
| /** | ||
| * @typedef drawBorder~parts | ||
| * @property {String} left | ||
| * @property {String} right | ||
| * @property {String} body | ||
| * @property {String} join | ||
| */ | ||
| /** | ||
| * @param {Number[]} columnSizeIndex | ||
| * @param {drawBorder~parts} parts | ||
| * @return {String} | ||
| */ | ||
| drawBorder = (columnSizeIndex, parts) => { | ||
| let columns; | ||
| columns = _.map(columnSizeIndex, (size) => { | ||
| return _.repeat(parts.body, size); | ||
| }); | ||
| columns = columns.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 | ||
| * @return {String} | ||
| */ | ||
| drawBorderTop = (columnSizeIndex, parts) => { | ||
| return drawBorder(columnSizeIndex, { | ||
| left: parts.topLeft, | ||
| right: parts.topRight, | ||
| body: parts.topBody, | ||
| join: parts.topJoin | ||
| }); | ||
| }; | ||
| /** | ||
| * @typedef drawBorderJoin~parts | ||
| * @property {String} joinLeft | ||
| * @property {String} joinRight | ||
| * @property {String} joinBody | ||
| * @property {String} joinJoin | ||
| */ | ||
| /** | ||
| * @param {Number[]} columnSizeIndex | ||
| * @param {drawBorderJoin~parts} parts | ||
| * @return {String} | ||
| */ | ||
| drawBorderJoin = (columnSizeIndex, parts) => { | ||
| return drawBorder(columnSizeIndex, { | ||
| left: parts.joinLeft, | ||
| right: parts.joinRight, | ||
| body: parts.joinBody, | ||
| join: parts.joinJoin | ||
| }); | ||
| }; | ||
| /** | ||
| * @typedef drawBorderBottom~parts | ||
| * @property {String} topLeft | ||
| * @property {String} topRight | ||
| * @property {String} topBody | ||
| * @property {String} topJoin | ||
| */ | ||
| /** | ||
| * @param {Number[]} columnSizeIndex | ||
| * @param {drawBorderBottom~parts} parts | ||
| * @return {String} | ||
| */ | ||
| drawBorderBottom = (columnSizeIndex, parts) => { | ||
| return drawBorder(columnSizeIndex, { | ||
| left: parts.bottomLeft, | ||
| right: parts.bottomRight, | ||
| body: parts.bottomBody, | ||
| join: parts.bottomJoin | ||
| }); | ||
| }; | ||
| export { | ||
| drawBorder, | ||
| drawBorderTop, | ||
| drawBorderJoin, | ||
| drawBorderBottom | ||
| }; |
| /** | ||
| * @typedef {Object} drawRow~border | ||
| * @property {String} bodyLeft | ||
| * @property {String} bodyRight | ||
| * @property {String} bodyJoin | ||
| */ | ||
| /** | ||
| * @param {Number[]} columns | ||
| * @param {drawRow~border} border | ||
| * @return {String} | ||
| */ | ||
| export default (columns, border) => { | ||
| return `${border.bodyLeft}${columns.join(border.bodyJoin)}${border.bodyRight}\n`; | ||
| }; |
| /* eslint-disable no-loop-func */ | ||
| import _ from 'lodash'; | ||
| import makeConfig from './makeConfig'; | ||
| import slice from 'ansi-slice'; | ||
| import stringWidth from 'string-width'; | ||
| import align from './align'; | ||
| /** | ||
| * @typedef formatData~columnConfig | ||
| * @property {String} align | ||
| * @property {Number} minWidth | ||
| * @property {Number} maxWidth | ||
| */ | ||
| /** | ||
| * @typedef formatData~config | ||
| * @property {formatData~columnConfig[]} columnConfig Column specific configuration. | ||
| */ | ||
| /** | ||
| * Transforms data rows to rows fit for printing in the CLI. Transformation consists of | ||
| * enforcing a fixed text width for values that are shorter than columnWidth and | ||
| * breaking values that are longer than columnWidth into two or more rows. | ||
| * | ||
| * The current implementation assumes RTL text alignment. | ||
| * | ||
| * @param {Array[]} rows | ||
| * @param {formatData~config} config | ||
| * @return {Array[]} | ||
| */ | ||
| export default (rows, config = {}) => { | ||
| let derivedConfig, | ||
| formattedData, | ||
| index0; | ||
| index0 = 0; | ||
| formattedData = _.map(rows, (columns) => { | ||
| return _.map(columns, (cell) => { | ||
| return String(cell); | ||
| }); | ||
| }); | ||
| derivedConfig = makeConfig(formattedData, config); | ||
| while (index0 < formattedData.length) { | ||
| let nextRow, | ||
| row; | ||
| row = formattedData[index0]; | ||
| formattedData[index0] = _.map(formattedData[index0], (value, index1) => { | ||
| let columnConfig; | ||
| columnConfig = derivedConfig.columnConfig[index1]; | ||
| if (stringWidth(value) > columnConfig.maxWidth) { | ||
| if (!nextRow) { | ||
| nextRow = _.fill([], ``, 0, row.length); | ||
| formattedData.splice(index0 + 1, 0, nextRow); | ||
| } | ||
| nextRow[index1] = slice(value, columnConfig.maxWidth); | ||
| return slice(value, 0, columnConfig.maxWidth); | ||
| } | ||
| return align(value, columnConfig.minWidth, columnConfig.alignment); | ||
| }); | ||
| index0++; | ||
| } | ||
| return formattedData; | ||
| }; |
| import table from './table'; |
| import _ from 'lodash'; | ||
| import validateConfig from './validateConfig'; | ||
| import calculateMaximumColumnValueIndex from './calculateMaximumColumnValueIndex'; | ||
| /** | ||
| * @param {Array[]} rows | ||
| * @param {formatData~config} config | ||
| * @return {formatData~config} | ||
| */ | ||
| export default (rows, config = {}) => { | ||
| let maximumColumnValueIndex; | ||
| validateConfig(rows, config); | ||
| maximumColumnValueIndex = calculateMaximumColumnValueIndex(rows); | ||
| config.columnConfig = config.columnConfig || Array(rows[0].length); | ||
| config.columnConfig = _.map(config.columnConfig, (column = {}, index0) => { | ||
| if (_.isUndefined(column.minWidth) || maximumColumnValueIndex[index0] > config.columnConfig[index0].minWidth) { | ||
| column.minWidth = maximumColumnValueIndex[index0]; | ||
| } | ||
| if (_.isUndefined(column.alignment)) { | ||
| column.alignment = `left`; | ||
| } | ||
| if (_.isUndefined(column.maxWidth)) { | ||
| column.maxWidth = Infinity; | ||
| } else if (column.maxWidth < column.minWidth) { | ||
| column.minWidth = column.maxWidth; | ||
| } | ||
| return column; | ||
| }); | ||
| return config; | ||
| }; |
+51
| import _ from 'lodash'; | ||
| import border from './border'; | ||
| import { | ||
| drawBorderTop, | ||
| drawBorderJoin, | ||
| drawBorderBottom | ||
| } from './drawBorder'; | ||
| import drawRow from './drawRow'; | ||
| import formatData from './formatData'; | ||
| let drawTop, | ||
| getColumnSizeIndex; | ||
| /** | ||
| * @param {String[]} columns | ||
| * @return {Number[]} | ||
| */ | ||
| getColumnSizeIndex = (columns) => { | ||
| return _.map(columns, (data) => { | ||
| return data.length; | ||
| }); | ||
| }; | ||
| export default (data) => { | ||
| let table, | ||
| columnSizeIndex, | ||
| rows; | ||
| rows = formatData(data); | ||
| columnSizeIndex = getColumnSizeIndex(rows[0]); | ||
| table = ''; | ||
| table += drawBorderTop(columnSizeIndex, border); | ||
| _.forEach(rows, (row, i) => { | ||
| table += drawRow(row, border); | ||
| if (i + 1 !== rows.length) { | ||
| table += drawBorderJoin(columnSizeIndex, border); | ||
| } | ||
| }); | ||
| table += drawBorderBottom(columnSizeIndex, border); | ||
| return table; | ||
| }; |
| import _ from 'lodash'; | ||
| /** | ||
| * @param {row[]} rows | ||
| * @param {formatData~config} config | ||
| * @return {undefined} | ||
| */ | ||
| export default (rows, config = {}) => { | ||
| let unknownPropertyName; | ||
| unknownPropertyName = _.first(_.difference(_.keys(config), [`columnConfig`])); | ||
| if (unknownPropertyName) { | ||
| throw new Error(`Config must not define unknown properties. "${unknownPropertyName}" is an unknown property.`); | ||
| } | ||
| if (config.columnConfig) { | ||
| _.forEach(config.columnConfig, (columnConfig) => { | ||
| unknownPropertyName = _.first(_.difference(_.keys(columnConfig), [`align`, `minWidth`, `maxWidth`])); | ||
| if (unknownPropertyName) { | ||
| throw new Error(`Column config must not define unknown properties. "${unknownPropertyName}" is an unknown property.`); | ||
| } | ||
| if (!_.isUndefined(columnConfig.minWidth) && !_.isUndefined(columnConfig.maxWidth) && columnConfig.minWidth > columnConfig.maxWidth) { | ||
| throw new Error(`Column minWidth cannot be greater than maxWidth.`); | ||
| } | ||
| }); | ||
| } | ||
| }; |
| import _ from 'lodash'; | ||
| /** | ||
| * @typedef {String} validateData~cell | ||
| */ | ||
| /** | ||
| * @typedef {validateData~cell[]} validateData~column | ||
| */ | ||
| /** | ||
| * @param {validateData~column[]} rows | ||
| * @return {undefined} | ||
| */ | ||
| export default (rows) => { | ||
| let columnNumber; | ||
| if (!_.isArray(rows)) { | ||
| throw new Error(`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.`); | ||
| } | ||
| columnNumber = rows[0].length; | ||
| _.forEach(rows, (columns) => { | ||
| if (!_.isArray(columns)) { | ||
| throw new Error(`Table row data must be an array.`); | ||
| } | ||
| if (columns.length !== columnNumber) { | ||
| throw new Error(`Table must have a consistent number of columns.`); | ||
| } | ||
| _.forEach(columns, (cell) => { | ||
| if (/[\x01-\x1A]/.test(cell)) { | ||
| throw new Error(`Table data must not contain control characters.`); | ||
| } | ||
| }); | ||
| }); | ||
| }; |
| /* eslint-disable max-nested-callbacks */ | ||
| import { | ||
| expect | ||
| } from 'chai'; | ||
| import align from './../src/align'; | ||
| import chalk from 'chalk'; | ||
| describe(`align`, () => { | ||
| context(`subject parameter value is not a string`, () => { | ||
| it(`throws an error`, () => { | ||
| expect(() => { | ||
| align(); | ||
| }).to.throw(Error, `Subject parameter value must be a string.`); | ||
| }); | ||
| }); | ||
| context(`container width parameter value is not a string`, () => { | ||
| it(`throws an error`, () => { | ||
| expect(() => { | ||
| align(``); | ||
| }).to.throw(Error, `Container width parameter value must be a number.`); | ||
| }); | ||
| }); | ||
| context(`subject parameter value width is greater than the container width`, () => { | ||
| it(`throws an error`, () => { | ||
| expect(() => { | ||
| align(`aa`, 1, `left`); | ||
| }).to.throw(Error, `Subject parameter value width cannot be greater than the container width.`); | ||
| }); | ||
| }); | ||
| context(`container alignment parameter value is not a string`, () => { | ||
| it(`throws an error`, () => { | ||
| expect(() => { | ||
| align(``, 1); | ||
| }).to.throw(Error, `Alignment parameter value must be a string.`); | ||
| }); | ||
| }); | ||
| context(`container alignment parameter value is not a known alignment parameter value`, () => { | ||
| it(`throws an error`, () => { | ||
| expect(() => { | ||
| align(``, 1, `foo`); | ||
| }).to.throw(Error, `Alignment parameter value must be a known alignment parameter value (left, right, center).`); | ||
| }); | ||
| }); | ||
| context(`subject parameter value`, () => { | ||
| context(`plain text`, () => { | ||
| context(`alignment`, () => { | ||
| context(`left`, () => { | ||
| it(`pads the string on the right side using a whitespace character`, () => { | ||
| expect(align(`aa`, 6, `left`)).to.equal(`aa `); | ||
| }); | ||
| }); | ||
| context(`right`, () => { | ||
| it(`pads the string on the left side using a whitespace character`, () => { | ||
| expect(align(`aa`, 6, `right`)).to.equal(` aa`); | ||
| }); | ||
| }); | ||
| context(`center`, () => { | ||
| it(`pads the string on both sides using a whitespace character`, () => { | ||
| expect(align(`aa`, 6, `center`)).to.equal(` aa `); | ||
| }); | ||
| context(`uneven number of available with`, () => { | ||
| it(`floors the available width; adds extra space to the end of the string`, () => { | ||
| expect(align(`aa`, 7, `center`)).to.equal(` aa `); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| context(`text containing ANSI escape codes`, () => { | ||
| context(`alignment`, () => { | ||
| context(`left`, () => { | ||
| it(`pads the string on the right side using a whitespace character`, () => { | ||
| expect(align(chalk.red(`aa`), 6, `left`)).to.equal(`${chalk.red(`aa`)} `); | ||
| }); | ||
| }); | ||
| context(`right`, () => { | ||
| it(`pads the string on the left side using a whitespace character`, () => { | ||
| expect(align(chalk.red(`aa`), 6, `right`)).to.equal(` ${chalk.red(`aa`)}`); | ||
| }); | ||
| }); | ||
| context(`center`, () => { | ||
| it(`pads the string on both sides using a whitespace character`, () => { | ||
| expect(align(chalk.red(`aa`), 6, `center`)).to.equal(` ${chalk.red(`aa`)} `); | ||
| }); | ||
| context(`uneven number of available with`, () => { | ||
| it(`floors the available width; adds extra space to the end of the string`, () => { | ||
| expect(align(chalk.red(`aa`), 7, `center`)).to.equal(` ${chalk.red(`aa`)} `); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
| import { | ||
| expect | ||
| } from 'chai'; | ||
| import chalk from 'chalk'; | ||
| import calculateMaximumColumnValueIndex from './../src/calculateMaximumColumnValueIndex'; | ||
| describe(`calculateMaximumColumnValueIndex`, () => { | ||
| it(`throws an error when attempting to calculate maximum column value index for an empty data set`, () => { | ||
| expect(() => { | ||
| calculateMaximumColumnValueIndex([]); | ||
| }).to.throw(Error, `Dataset must have at least one row.`); | ||
| }); | ||
| it(`calculates the maximum column value index`, () => { | ||
| let maximumColumnValueIndex; | ||
| maximumColumnValueIndex = calculateMaximumColumnValueIndex([ | ||
| [ | ||
| ``, | ||
| `a`, | ||
| `b`, | ||
| `c` | ||
| ], | ||
| [ | ||
| ``, | ||
| `a`, | ||
| `bbbbbbbbbb`, | ||
| `c` | ||
| ], | ||
| [ | ||
| ``, | ||
| ``, | ||
| `b`, | ||
| `ccccc` | ||
| ] | ||
| ]); | ||
| expect(maximumColumnValueIndex).to.deep.equal([0, 1, 10, 5]); | ||
| }); | ||
| context(`cell values contain ANSI codes`, () => { | ||
| it(`uses visual width of the string`, () => { | ||
| let maximumColumnValueIndex; | ||
| maximumColumnValueIndex = calculateMaximumColumnValueIndex([ | ||
| [ | ||
| chalk.red(`aaaaa`) | ||
| ] | ||
| ]); | ||
| expect(maximumColumnValueIndex[0]).to.equal(5); | ||
| }); | ||
| }); | ||
| context(`cell values contain fullwidth characters`, () => { | ||
| it(`uses visual width of the string`, () => { | ||
| let maximumColumnValueIndex; | ||
| maximumColumnValueIndex = calculateMaximumColumnValueIndex([ | ||
| [ | ||
| chalk.red(`古`) | ||
| ] | ||
| ]); | ||
| expect(maximumColumnValueIndex[0]).to.equal(2); | ||
| }); | ||
| }); | ||
| }); |
| import { | ||
| expect | ||
| } from 'chai'; | ||
| import { | ||
| drawBorder, | ||
| drawBorderTop | ||
| } from './../src/drawBorder'; | ||
| describe(`drawBorder`, () => { | ||
| it(`draws a border using parts`, () => { | ||
| let parts; | ||
| parts = { | ||
| left: `╔`, | ||
| right: `╗`, | ||
| body: `═`, | ||
| join: `╤` | ||
| }; | ||
| expect(drawBorder([1], parts)).to.equal(`╔═╗\n`); | ||
| expect(drawBorder([1, 1], parts)).to.equal(`╔═╤═╗\n`); | ||
| expect(drawBorder([5, 10], parts)).to.equal(`╔═════╤══════════╗\n`); | ||
| }); | ||
| }); | ||
| describe(`drawBorderTop`, () => { | ||
| it(`draws a border using parts`, () => { | ||
| let parts; | ||
| parts = { | ||
| topLeft: `╔`, | ||
| topRight: `╗`, | ||
| topBody: `═`, | ||
| topJoin: `╤` | ||
| }; | ||
| expect(drawBorderTop([1], parts)).to.equal(`╔═╗\n`); | ||
| expect(drawBorderTop([1, 1], parts)).to.equal(`╔═╤═╗\n`); | ||
| expect(drawBorderTop([5, 10], parts)).to.equal(`╔═════╤══════════╗\n`); | ||
| }); | ||
| }); |
| /* eslint-disable max-nested-callbacks */ | ||
| import { | ||
| expect | ||
| } from 'chai'; | ||
| import _ from 'lodash'; | ||
| import formatData from './../src/formatData'; | ||
| import chalk from 'chalk'; | ||
| describe(`formatData`, () => { | ||
| it(`casts data to a string`, () => { | ||
| let rows; | ||
| rows = formatData([ | ||
| [1] | ||
| ]); | ||
| expect(rows[0][0]).to.be.a(`string`); | ||
| expect(rows[0][0]).to.equal(`1`); | ||
| }); | ||
| context(`cell value`, () => { | ||
| context(`is plain`, () => { | ||
| context(`length is lesser than minWidth`, () => { | ||
| it(`pads the string on the right side using a whitespace character`, () => { | ||
| let rows; | ||
| rows = formatData([ | ||
| [`a`] | ||
| ], { | ||
| columnConfig: [ | ||
| { | ||
| minWidth: 10 | ||
| } | ||
| ] | ||
| }); | ||
| expect(rows[0][0]).to.equal(`a `); | ||
| }); | ||
| }); | ||
| context(`length is greater than minWidth`, () => { | ||
| it(`does not affect the string`, () => { | ||
| let rows; | ||
| rows = formatData([ | ||
| [`aaaaaaaaaa`] | ||
| ], { | ||
| columnConfig: [ | ||
| { | ||
| minWidth: 5 | ||
| } | ||
| ] | ||
| }); | ||
| expect(rows[0][0]).to.equal(`aaaaaaaaaa`); | ||
| }); | ||
| }); | ||
| context(`length is greater than maxWidth`, () => { | ||
| it(`splits the string across multiple rows`, () => { | ||
| let rows; | ||
| rows = formatData([ | ||
| [`aaabbbccc`] | ||
| ], { | ||
| columnConfig: [ | ||
| { | ||
| maxWidth: 3 | ||
| } | ||
| ] | ||
| }); | ||
| expect(_.pluck(rows, 0)).to.deep.equal([`aaa`, `bbb`, `ccc`]); | ||
| }); | ||
| }); | ||
| }); | ||
| context(`contains ANSI escape codes`, () => { | ||
| context(`length is lesser than minWidth`, () => { | ||
| it(`pads the string on the right side using a whitespace character`, () => { | ||
| let rows; | ||
| rows = formatData([ | ||
| [ | ||
| chalk.red(`a`) | ||
| ] | ||
| ], { | ||
| columnConfig: [ | ||
| { | ||
| minWidth: 10 | ||
| } | ||
| ] | ||
| }); | ||
| expect(rows[0][0]).to.equal(`${chalk.red(`a`)} `); | ||
| }); | ||
| }); | ||
| context(`length is greater than minWidth`, () => { | ||
| it(`does not affect the string`, () => { | ||
| let rows; | ||
| rows = formatData([ | ||
| [ | ||
| chalk.red(`aaaaaaaaaa`) | ||
| ] | ||
| ], { | ||
| columnConfig: [ | ||
| { | ||
| minWidth: 5 | ||
| } | ||
| ] | ||
| }); | ||
| expect(rows[0][0]).to.equal(chalk.red(`aaaaaaaaaa`)); | ||
| }); | ||
| }); | ||
| context(`length is greater than maxWidth`, () => { | ||
| it(`splits the string across multiple rows`, () => { | ||
| let rows; | ||
| rows = formatData([ | ||
| [ | ||
| chalk.red(`aaabbbccc`) | ||
| ] | ||
| ], { | ||
| columnConfig: [ | ||
| { | ||
| maxWidth: 3 | ||
| } | ||
| ] | ||
| }); | ||
| expect(_.pluck(rows, 0)).to.deep.equal([chalk.red(`aaa`), chalk.red(`bbb`), chalk.red(`ccc`)]); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
| /* eslint-disable max-nested-callbacks */ | ||
| import { | ||
| expect | ||
| } from 'chai'; | ||
| import _ from 'lodash'; | ||
| import makeConfig from './../src/makeConfig'; | ||
| describe(`makeConfig`, () => { | ||
| context(`column specific alignment is not provided`, () => { | ||
| it(`defaults to 'left'`, () => { | ||
| let config; | ||
| config = makeConfig([ | ||
| [ | ||
| `aaaaa` | ||
| ] | ||
| ]); | ||
| expect(config.columnConfig[0].alignment).to.equal(`left`); | ||
| }); | ||
| }); | ||
| context(`column specific minWidth is not provided`, () => { | ||
| context(`maxWidth is not set`, () => { | ||
| it(`uses the maximum value length`, () => { | ||
| let config; | ||
| config = makeConfig([ | ||
| [ | ||
| `aaaaa` | ||
| ] | ||
| ]); | ||
| expect(config.columnConfig[0].minWidth).to.equal(5); | ||
| }); | ||
| }); | ||
| context(`maxWidth is set`, () => { | ||
| context(`maxWidth is larger than maximum value length`, () => { | ||
| it(`uses the maximum value length`, () => { | ||
| let config; | ||
| config = makeConfig([ | ||
| [ | ||
| `aaaaa` | ||
| ] | ||
| ], { | ||
| columnConfig: [ | ||
| { | ||
| maxWidth: 10 | ||
| } | ||
| ] | ||
| }); | ||
| expect(config.columnConfig[0].minWidth).to.equal(5); | ||
| }); | ||
| }); | ||
| context(`maxWidth is lesser than maximum value length`, () => { | ||
| it(`uses the maxWidth value`, () => { | ||
| let config; | ||
| config = makeConfig([ | ||
| [ | ||
| `aaaaaaaaaa` | ||
| ] | ||
| ], { | ||
| columnConfig: [ | ||
| { | ||
| maxWidth: 5 | ||
| } | ||
| ] | ||
| }); | ||
| expect(config.columnConfig[0].minWidth).to.equal(5); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| context(`column specific minWidth is provided`, () => { | ||
| context(`column specific minWidth is larger than maximum value length`, () => { | ||
| it(`uses the maximum value length`, () => { | ||
| let config; | ||
| config = makeConfig([ | ||
| [ | ||
| `aaaaa` | ||
| ] | ||
| ], { | ||
| columnConfig: [ | ||
| { | ||
| minWidth: 10 | ||
| } | ||
| ] | ||
| }); | ||
| expect(_.pluck(config.columnConfig, `minWidth`)).to.deep.equal([10]); | ||
| }); | ||
| }); | ||
| context(`column specific minWidth is smaller than maximum value length`, () => { | ||
| it(`uses the maximum value length`, () => { | ||
| let config; | ||
| config = makeConfig([ | ||
| [ | ||
| `aaaaa` | ||
| ] | ||
| ], { | ||
| columnConfig: [ | ||
| { | ||
| minWidth: 2 | ||
| } | ||
| ] | ||
| }); | ||
| expect(_.pluck(config.columnConfig, `minWidth`)).to.deep.equal([5]); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
| import { | ||
| expect | ||
| } from 'chai'; | ||
| import _ from 'lodash'; | ||
| import table from './../src/table'; | ||
| describe(`table`, () => { | ||
| let expectTable; | ||
| before(() => { | ||
| expectTable = (rows, contents) => { | ||
| expect(rows).to.equal(_.trim(contents) + `\n`); | ||
| }; | ||
| }); | ||
| it(`draws expected table`, () => { | ||
| expectTable(table([ | ||
| ['a'] | ||
| ] | ||
| ), ` | ||
| ╔═╗ | ||
| ║a║ | ||
| ╚═╝ | ||
| `); | ||
| expectTable(table([ | ||
| [`a`, `b`] | ||
| ] | ||
| ), ` | ||
| ╔═╤═╗ | ||
| ║a│b║ | ||
| ╚═╧═╝ | ||
| `); | ||
| expectTable(table([ | ||
| [`a`, `b`], | ||
| [`0`, `1`] | ||
| ] | ||
| ), ` | ||
| ╔═╤═╗ | ||
| ║a│b║ | ||
| ╟─┼─╢ | ||
| ║0│1║ | ||
| ╚═╧═╝ | ||
| `); | ||
| }); | ||
| }); |
| /* eslint-disable max-nested-callbacks */ | ||
| import { | ||
| expect | ||
| } from 'chai'; | ||
| import validateConfig from './../src/validateConfig'; | ||
| describe(`validateConfig`, () => { | ||
| context(`config defines an unknown property`, () => { | ||
| it(`throws an error`, () => { | ||
| expect(() => { | ||
| validateConfig([[`a`]], { | ||
| unknownProperty: true | ||
| }); | ||
| }).to.throw(Error, `Config must not define unknown properties. "unknownProperty" is an unknown property.`); | ||
| }); | ||
| }); | ||
| context(`columnConfig`, () => { | ||
| context(`config defines an unknown property`, () => { | ||
| it(`throws an error`, () => { | ||
| expect(() => { | ||
| validateConfig([[`a`]], { | ||
| columnConfig: [ | ||
| { | ||
| unknownProperty: true | ||
| } | ||
| ] | ||
| }); | ||
| }).to.throw(Error, `Column config must not define unknown properties. "unknownProperty" is an unknown property.`); | ||
| }); | ||
| }); | ||
| context(`column specific minWidth and maxWidth are provided`, () => { | ||
| context(`minWidth is greater than maxWidth`, () => { | ||
| it(`throws an error`, () => { | ||
| expect(() => { | ||
| validateConfig([[`a`]], { | ||
| columnConfig: [ | ||
| { | ||
| minWidth: 10, | ||
| maxWidth: 5 | ||
| } | ||
| ] | ||
| }); | ||
| }).to.throw(Error, `Column minWidth cannot be greater than maxWidth.`); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
| /* eslint-disable max-nested-callbacks */ | ||
| import { | ||
| expect | ||
| } from 'chai'; | ||
| import validateData from './../src/validateData'; | ||
| describe(`validateData`, () => { | ||
| context(`table does not have a row`, () => { | ||
| it(`throws an error`, () => { | ||
| expect(() => { | ||
| validateData([]); | ||
| }).to.throw(Error, `Table must define at least one row.`); | ||
| }); | ||
| }); | ||
| context(`table does not have a column`, () => { | ||
| it(`throws an error`, () => { | ||
| expect(() => { | ||
| validateData([[]]); | ||
| }).to.throw(Error, `Table must define at least one column.`); | ||
| }); | ||
| }); | ||
| context(`row data is not an array`, () => { | ||
| it(`throws an error`, () => { | ||
| expect(() => { | ||
| validateData({}); | ||
| }).to.throw(Error, `Table data must be an array.`); | ||
| }); | ||
| }); | ||
| context(`column data is not an array`, () => { | ||
| it(`throws an error`, () => { | ||
| expect(() => { | ||
| validateData([{}]); | ||
| }).to.throw(Error, `Table row data must be an array.`); | ||
| }); | ||
| }); | ||
| context(`cell data contains a control character`, () => { | ||
| it(`throws an error`, () => { | ||
| expect(() => { | ||
| validateData([ | ||
| [ | ||
| [ | ||
| String.fromCodePoint(0x01) | ||
| ] | ||
| ] | ||
| ]); | ||
| }).to.throw(Error, `Table data must not contain control characters.`); | ||
| }); | ||
| }); | ||
| context(`rows have inconsistent number of columns`, () => { | ||
| it(`throws an error`, () => { | ||
| expect(() => { | ||
| validateData([ | ||
| [`a`, `b`, `c`], | ||
| [`a`, `b`] | ||
| ]); | ||
| }).to.throw(Error, `Table must have a consistent number of columns.`); | ||
| }); | ||
| }); | ||
| }); |
+45
-9
| { | ||
| "name": "table", | ||
| "description": "Node Tables", | ||
| "version": "0.0.5", | ||
| "author": "Jan Gorman <gorman.jan@gmail.com>", | ||
| "keywords": ["table", "cli", "text"], | ||
| "dependencies": { "vows": ">=0.5.3"}, | ||
| "repository" : {"type": "git" , "url": "https://github.com/JanGorman/node-table" }, | ||
| "directories": { | ||
| "lib": "./lib" | ||
| "version": "1.0.0", | ||
| "description": "Formats data into a string table.", | ||
| "main": "./dist/index.js", | ||
| "author": { | ||
| "name": "Gajus Kuizinas", | ||
| "email": "gk@anuary.com", | ||
| "url": "http://gajus.com" | ||
| }, | ||
| "engines": { "node": ">= 0.2.0" } | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/gajus/table" | ||
| }, | ||
| "keywords": [ | ||
| "ascii", | ||
| "text", | ||
| "table" | ||
| ], | ||
| "scripts": { | ||
| "test": "babel-node ./node_modules/.bin/gulp lint", | ||
| "build": "babel-node ./node_modules/.bin/gulp build", | ||
| "watch": "babel-node ./node_modules/.bin/gulp watch" | ||
| }, | ||
| "devDependencies": { | ||
| "babel-core": "^5.8.24", | ||
| "babel-loader": "^5.3.2", | ||
| "babel-plugin-lodash": "^0.2.0", | ||
| "canonical": "^1.0.1", | ||
| "chai": "^3.2.0", | ||
| "chalk": "^1.1.1", | ||
| "del": "^2.0.2", | ||
| "globby": "^3.0.1", | ||
| "gulp": "^3.9.0", | ||
| "gulp-babel": "^5.2.1", | ||
| "gulp-mocha": "^2.1.3", | ||
| "gulp-sourcemaps": "^1.5.2", | ||
| "gulp-util": "^3.0.6" | ||
| }, | ||
| "dependencies": { | ||
| "ansi-slice": "^1.0.3", | ||
| "bluebird": "^2.10.0", | ||
| "lodash": "^3.10.1", | ||
| "string-length": "^1.0.1", | ||
| "string-width": "^1.0.1", | ||
| "strip-ansi": "^3.0.0", | ||
| "xregexp": "slevithan/xregexp#baef6b6429fbd6f9aeb3c2c86a41b5422b023e18" | ||
| } | ||
| } |
+22
-37
@@ -1,47 +0,32 @@ | ||
| ## About | ||
| # Table | ||
| table is a component to create text based tables. This might be useful for text emails or to display tables in the CLI. | ||
| [](https://www.npmjs.com/package/table) | ||
| [](https://github.com/gajus/canonical) | ||
| ## Install | ||
| (This library is work in progress. The working library will be released in 2.0.0.) | ||
| npm install table | ||
| Formats data into a string table. | ||
| ## Example | ||
| * Works with strings containing [fullwidth](https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms) characters. | ||
| * Works with strings containing [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code). | ||
| * Supports `minWidth`, `maxWidth` properties per column. | ||
| * Supports expanding long cell values into multiple rows. | ||
| var sys = require('sys'), Table = require('table'); | ||
| ## Usage | ||
| var table = new Table( [15, 20] ); | ||
| table | ||
| .setDefaultColumnAlignment(['left', 'center']) | ||
| .appendRow(['Node', 'Table']) | ||
| .appendRow(['Second', 'Row']) | ||
| .appendRow(['Third', 'Row']) | ||
| .appendRow(["Fourth\nsecond line", 'Row']); | ||
| sys.puts(table.render()); | ||
| will result in a nice looking table: | ||
| ### Basic Table | ||
| +---------------+--------------------+ | ||
| |Node | Table | | ||
| |---------------+--------------------| | ||
| |Second | Row | | ||
| |---------------+--------------------| | ||
| |Third | Row | | ||
| |---------------+--------------------| | ||
| |Fourth | Row | | ||
| |second line | | | ||
| +---------------+--------------------+ | ||
| Valid alignments are 'left', 'center' and 'right'. | ||
| Table data is described using an array of arrays. | ||
| ## Build | ||
| ```js | ||
| let table = require('table'), | ||
| data; | ||
| To build the project call | ||
| data = [ | ||
| ['0A', '0B', '0C'], | ||
| ['1A', '1B', '1C'], | ||
| ['2A', '2B', '2C'] | ||
| ]; | ||
| cake build | ||
| ## Test | ||
| To run the test simply call | ||
| cake test | ||
| console.log(table(data)); | ||
| ``` |