You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
3.9 KiB

{"version":3,"sources":["table.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAyEe,UAAC,IAAI,EAAsB;MAApB,UAAU,yDAAG,EAAE;;AACjC,MAAI,cAAc,YAAA;MACd,MAAM,YAAA;MACN,cAAc,YAAA;MACd,IAAI,YAAA,CAAC;;AAET,mCAAkB,IAAI,CAAC,CAAC;;AAExB,MAAI,GAAG,kCAAmB,IAAI,CAAC,CAAC;;AAEhC,QAAM,GAAG,0BAAW,IAAI,EAAE,UAAU,CAAC,CAAC;;AAEtC,MAAI,GAAG,iCAAkB,IAAI,EAAE,MAAM,CAAC,CAAC;;AAEvC,gBAAc,GAAG,uCAAwB,IAAI,EAAE,MAAM,CAAC,CAAC;;AAEvD,MAAI,GAAG,0CAA2B,IAAI,EAAE,cAAc,EAAE,MAAM,CAAC,CAAC;AAChE,MAAI,GAAG,8BAAe,IAAI,EAAE,MAAM,CAAC,CAAC;AACpC,MAAI,GAAG,4BAAa,IAAI,EAAE,MAAM,CAAC,CAAC;;AAElC,gBAAc,GAAG,uCAAwB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;;AAElD,SAAO,yBAAU,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAC;CACpG","file":"table.js","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 {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 * @return {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 * @return {string}\n */\nexport default (data, userConfig = {}) => {\n let cellWidthIndex,\n config,\n rowHeightIndex,\n rows;\n\n validateTableData(data);\n\n rows = stringifyTableData(data);\n\n config = makeConfig(rows, userConfig);\n\n rows = truncateTableData(data, config);\n\n rowHeightIndex = calculateRowHeightIndex(rows, config);\n\n rows = mapDataUsingRowHeightIndex(rows, rowHeightIndex, config);\n rows = alignTableData(rows, config);\n rows = padTableData(rows, config);\n\n cellWidthIndex = calculateCellWidthIndex(rows[0]);\n\n return drawTable(rows, config.border, cellWidthIndex, rowHeightIndex, config.drawHorizontalLine);\n};\n"],"sourceRoot":"/source/"}