1.0.2 • Published 2 years ago

print-details v1.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

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

作用: 打印一级标题或一级标题下所有的主键,也就是dataSourcekey

语法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);

参数:

返回值:{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    ║
   ╚═══════════════╧══════╧═════════╝
 */
1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago