README
安装与使用
安装:
npm install print-details --save
使用:
import PrintTable from 'print-details';
const dataSource = {
"menu1": [
{ name: 'fn1', type: 'aaa1', return: 'bbb1' },
{ name: 'fn2', type: 'aaa2', return: 'bbb2' }
],
"menu2": [
{ name: 'fn3', type: 'aaa3', return: 'bbb3' }
],
"menu3": [
{ name: 'fn4', type: 'aaa4', return: 'bbb4' },
{ name: 'fn5', type: 'aaa5', return: 'bbb5' },
{ name: 'fn6', type: 'aaa6', return: 'bbb6' },
]
}
let table = new PrintTable(dataSource, 'name');
printTitle
作用: 打印一级标题或一级标题下所有的主键,也就是dataSource
的key
语法: printTitle(head, cellWidth);
参数:
-
head
: {string} [必填] 表格的名字 -
cellWidth
: {number} [必填] 单元格的长度 -
title
:{string} **[可选]**指定的一级标题
返回值:{void} 无返回值
实例:
table.printTitle('The all constructor function', 20);
/**
* ╔══════════════════════╗
║ The all constructor ║
║ function ║
╟──────────────────────╢
║ menu1 ║
╟──────────────────────╢
║ menu2 ║
╟──────────────────────╢
║ menu3 ║
╚══════════════════════╝
*/
table.printTitle('The function', 20, 'menu3');
/**
* ╔══════════════════════╗
║ The function ║
╟──────────────────────╢
║ fn4 ║
╟──────────────────────╢
║ fn5 ║
╟──────────────────────╢
║ fn6 ║
╚══════════════════════╝
*/
printContent
作用: 打印指定name的数据集
语法: printContent(tableHead, name, columns);
参数:
-
tableHead
: {string[]} [必填] 表头 [推荐英文],长度应该与 dataSource 每条数据一样 -
name
: {string|string[]} [必填] 主键对应的值 -
columns
:{[{alignment: 'center'|'left'|'right', width: number}]} [可选] 单元格参数的设置,不设置宽度则为自适应
返回值:{void} 无返回值
实例:
// 不设置columns参数
table.printContent(['function name', 'type', 'returns'], 'fn2');
/**
* ╔════════════════════════════════╗
║ The result of search ║
╟───────────────┬──────┬─────────╢
║ function name │ type │ returns ║
╟───────────────┼──────┼─────────╢
║ fn2 │ aaa2 │ bbb2 ║
╚═══════════════╧══════╧═════════╝
*/
// 设置columns参数
const columns = [
{ alignment: 'center', width: 10},
{ alignment: 'center' },
{ alignment: 'right' }
]
table.printContent(['function name', 'type', 'returns'], 'fn2', columns);
/**
* ╔═════════════════════════════╗
║ The result of search ║
╟────────────┬──────┬─────────╢
║ function n │ type │ returns ║
║ ame │ │ ║
╟────────────┼──────┼─────────╢
║ fn2 │ aaa2 │ bbb2 ║
╚════════════╧══════╧═════════╝
*/
// name为数组传输
table.printContent(['function name', 'type', 'returns'], ['fn1', 'fn2']);
/**
* ╔════════════════════════════════╗
║ The result of search ║
╟───────────────┬──────┬─────────╢
║ function name │ type │ returns ║
╟───────────────┼──────┼─────────╢
║ fn1 │ aaa1 │ bbb1 ║
╟───────────────┼──────┼─────────╢
║ fn2 │ aaa2 │ bbb2 ║
╚═══════════════╧══════╧═════════╝
*/