colored-table 0.0.0 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +25 -0
- package/README.md +60 -2
- package/index.cjs +1 -0
- package/index.d.ts +13 -0
- package/index.mjs +1 -0
- package/package.json +34 -13
- package/src/build/buildBody.d.ts +3 -0
- package/src/build/buildHeader.d.ts +3 -0
- package/src/build/computerMaxLen.d.ts +3 -0
- package/src/build/createPen.d.ts +2 -0
- package/src/build/index.d.ts +3 -0
- package/src/core.d.ts +3 -0
- package/src/ele/rowEle.d.ts +3 -0
- package/src/ele/tableEle.d.ts +3 -0
- package/src/global.d.ts +30 -0
- package/src/lines.d.ts +36 -0
- package/src/parse/parse.d.ts +7 -0
- package/src/parse/parseCell.d.ts +3 -0
- package/src/parse/parseRow.d.ts +11 -0
- package/src/proto/createHeaderProto.d.ts +3 -0
- package/src/proto/setPro.d.ts +3 -0
- package/src/types.d.ts +105 -0
- package/index.js +0 -24
package/LICENSE
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) <2025> <earthnut.dev>
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
|
|
17
|
+
# MIT 许可证
|
|
18
|
+
|
|
19
|
+
版权所有 (c) [2025] [花生亻]
|
|
20
|
+
|
|
21
|
+
特此免费授予任何获得本软件及相关文档文件(以下简称“软件”)副本的人不受限制地处置该软件的权利,包括不受限制地使用、复制、修改、合并、发布、分发、再许可和/或出售该软件副本的权利,并允许向其提供该软件的人这样做,但须遵守以下条件:
|
|
22
|
+
|
|
23
|
+
上述版权声明和本许可声明应包含在所有副本或软件的重要部分中。
|
|
24
|
+
|
|
25
|
+
软件按“原样”提供,不附带任何形式的明示或暗示的保证,包括但不限于适销性、特定用途适用性和不侵权的保证。在任何情况下,作者或版权持有人均不对因合同、侵权或其他方式引起的任何索赔、损害或其他责任负责,无论是在与软件或软件的使用或其他交易有关的任何诉讼中。
|
package/README.md
CHANGED
|
@@ -1,3 +1,61 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 彩色表格
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
~~一个在控制台构建表格的工具(自定义版 console.table )~~
|
|
4
|
+
|
|
5
|
+
~~本来想着写成在终端(node 环境)和控制台(浏览器环境)公用的,但是发现在浏览器环境表现不佳,且不同的浏览器环境渲染效果不同,还不如使用 `console.table`~~
|
|
6
|
+
|
|
7
|
+
现在支持在浏览器环境打印彩色文本的表格,但是目前不支持自定义边框及长文本换行。因为在 `node` 使用的终端和浏览器的控制台渲染的方式不同,其核心代码也不尽相同。
|
|
8
|
+
|
|
9
|
+
(目前的小问题就是当同行表情过多时会产生偏移)
|
|
10
|
+
|
|
11
|
+
## 安装
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install --save colored-table
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## 使用
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { ColoredTable } from 'colored-table';
|
|
21
|
+
|
|
22
|
+
/** 构建表格,可传入初始化的数据,也可直接不使用参数而使用 `addRow` 添加行 */
|
|
23
|
+
const table = new ColoredTable([
|
|
24
|
+
['我在第一行第一列', '我在第一行第二列'],
|
|
25
|
+
['我在第二行第一列', '我在第二行第二列'],
|
|
26
|
+
]);
|
|
27
|
+
|
|
28
|
+
// 因为一个表只有一个表头,所以每次调用 `setHeader` 都将覆盖上一次配置表头
|
|
29
|
+
/** 设置表头,也可以在实例化时使用对象配置表头 */
|
|
30
|
+
table.setHeader(['第一列', '第二列']);
|
|
31
|
+
|
|
32
|
+
/** 使用 `addRow` 添加行,会追加到已有行后 */
|
|
33
|
+
table.addRow(['我在第三行第一列', '我在第三行第二列']);
|
|
34
|
+
// 构建表
|
|
35
|
+
table();
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
效果:
|
|
39
|
+
|
|
40
|
+
| 第一列 | 第二列 |
|
|
41
|
+
| :--------------- | :--------------- |
|
|
42
|
+
| 我在第一行第一列 | 我在第一行第二列 |
|
|
43
|
+
| 我在第二行第一列 | 我在第二行第二列 |
|
|
44
|
+
| 我在第三行第一列 | 我在第三行第二列 |
|
|
45
|
+
|
|
46
|
+
### setFontSize
|
|
47
|
+
|
|
48
|
+
除了 `addRow` 和 `setHeader` 两个方法,实例上还存在 `setFontSize` 方法。该方法将控制最终渲染的表格的字符大小。当然,这仅可在浏览器环境使用
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
table.setFontSize(8); // 渲染表格会在控制台显示更小
|
|
52
|
+
table.setFontSize(16); // 渲染表格会在控制台显示更大
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### ColoredTableGlobalData
|
|
56
|
+
|
|
57
|
+
包还导出了 `ColoredTableGlobalData` 用于指定默认全局的样式。在该数据上的更改将直接影响所有没有特殊配置样式的文本或是边框。
|
|
58
|
+
|
|
59
|
+
## 文档地址
|
|
60
|
+
|
|
61
|
+
[colored-table](https://earthnut.dev/colored-table)
|
package/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("a-js-tools"),t=require("a-type-of-js"),o=require("color-pen"),r=require("@color-pen/static");const n=e.createConstructor((function(e){return this.data=[],Object.setPrototypeOf(this,e),this}));function l(e,o){if(o.align&&(e.align=o.align),o.bgColor&&(e.bgColor=o.bgColor),o.color&&(e.color=o.color),o.italic&&(e.italic=o.italic),o.underline&&(e.underline=o.underline),o.border)if(t.isType(o.border,(e=>t.isString(e)))){const t=o.border;e.border={left:{color:void 0,style:t},right:{color:void 0,style:t},top:{color:void 0,style:t},bottom:{color:void 0,style:t}}}else if(t.isType(o.border,(e=>["color","style"].some((o=>!t.isUndefined(e[o])))))){const t=o.border,r=t.style,n=t.color||void 0;e.border=JSON.parse(JSON.stringify({left:{color:n,style:r},right:{color:n,style:r},top:{color:n,style:r},bottom:{color:n,style:r}},((e,t)=>""===t?void 0:t)))}else t.isType(o.border,(e=>["left","right","top","bottom"].some((o=>!t.isUndefined(e[o])))))&&(e.border=o.border)}class i{}function s(e,o){t.isArray(e)&&(e={data:e});const r=new i;l(r,e);const s=new n(r);return Object.setPrototypeOf(r,o),e.data?.forEach((e=>{e&&s.data.push(function(e,o){if(t.isUndefined(e))return;t.isType(e,(e=>!t.isPlainObject(e)))&&(e={content:e});const r={content:e.content};return l(r,e),Object.setPrototypeOf(r,o),r}(e,r))})),s}class c extends i{border={left:{style:"bold",color:void 0},right:{style:"bold",color:void 0},top:{style:"bold",color:void 0},bottom:{style:"bold",color:void 0}}}function a(e){const t=new c;return Object.setPrototypeOf(t,e),t}const d=!e.isNode(),u={emojiLength:2.08,emojiRegex:/[\u{1F600}-\u{1F64F}\u{1F300}-\u{1F5FF}\u{1F680}-\u{1F6FF}\u{1F900}-\u{1F9FF}]/gu,chineseLength:1.8,chineseRegex:/[\u4E00-\u9FFF]/g};const f=new class{align="left";color="";bgColor="";bold=!1;underline=!1;italic=!1;border={left:{color:void 0,style:"simple"},right:{color:void 0,style:"simple"},top:{color:void 0,style:"simple"},bottom:{color:void 0,style:"simple"}}},h=e.createConstructor((function(e){return this.body=[],this.header=void 0,Object.setPrototypeOf(this,e),this}));class b{}function g(e){let r=o.pen;return t.isType(e)&&(e.bold&&(r=r.bold),t.isBusinessEmptyString(e.bgColor)||t.isUndefined(e.bgColor)||(r=r.bgColor(e.bgColor)),t.isBusinessEmptyString(e.color)||t.isUndefined(e.color)||(r=r.color(e.color)),e.italic&&(r=r.italic),e.underline&&(r=r.underline)),r}const y={fine:{lt:"┌",ct:"┬",rt:"┐",lc:"├",c:"┼",rc:"┤",lb:"└",cb:"┴",rb:"┘",l:"─",v:"│"}};function p(e){let t=0;return[...e].forEach((e=>{u.emojiRegex.lastIndex=0,u.chineseRegex.lastIndex=0,e.match(u.emojiRegex)?t+=u.emojiLength:e.match(u.chineseRegex)?t+=u.chineseLength:t++})),Math.ceil(t)}function m(e,n){const l=function(e){const t=[];return e.header&&e.header.data.forEach(((e,r)=>{const n=e?.content?.toString()??"";t[r]=Math.max(t[r]??0,d?p(n):o.strInTerminalLength(n))})),e.body&&e.body.forEach((e=>{e.data.forEach(((e,r)=>{const n=e?.content?.toString()??"";t[r]=Math.max(t[r]??0,d?p(n):o.strInTerminalLength(n))}))})),t}(e);let i=!1,s="";e.header&&(i=!0,s+=function(e,n){let l="";const i=n.length-1,{fine:s}=y,c=g(e);return n.forEach(((e,t)=>{0===t&&(l+=s.lt),l+=r.terminalResetStyle,l+=s.l.repeat(e+2),t===i?(l+=r.terminalResetStyle,l+=s.rt):(l+=r.terminalResetStyle,l+=s.ct)})),l+="\n",n.forEach(((n,a)=>{l+=r.terminalResetStyle,l+=s.v;const d=e.data[a];if(t.isUndefined(d)||t.isNull(d))l+=r.terminalResetStyle,l+=c(" ".repeat(n+2));else{const e=g(d);let t=d.content?.toString()??"";t=t.replace(/[\n]/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t"),l+=r.terminalResetStyle,l+=e`\u2002${o.cutoffStringWithChar(t,n)}\u2002`}a===i&&(l+=s.v)})),l+="\n",l}(e.header,l)),s+=function(e,n,l){let i="";const s=n.length-1,{fine:c}=y;return n.forEach(((e,t)=>{0===t&&(i+=r.terminalResetStyle,i+=l?c.lc:c.lt),i+=r.terminalResetStyle,i+=c.l.repeat(e+2),t===s?(i+=r.terminalResetStyle,i+=l?c.rc:c.rt):(i+=r.terminalResetStyle,i+=l?c.c:c.ct)})),i+="\n",e.forEach(((l,a)=>{const d=g(l);n.forEach(((e,n)=>{i+=r.terminalResetStyle,i+=c.v;const a=l.data[n];if(t.isUndefined(a)||t.isNull(a))i+=d`${" ".repeat(e+2)}`;else{const t=g(a);let n=a.content?.toString()||"";n=n.replace(/[\n]/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t"),i+=r.terminalResetStyle,i+=t`\u2002${o.cutoffStringWithChar(n,e)}\u2002`}n===s&&(i+=r.terminalResetStyle,i+=c.v)})),i+="\n";const u=e.length-1===a;n.forEach(((e,t)=>{0===t&&(i+=r.terminalResetStyle,i+=u?c.lb:c.lc),i+=r.terminalResetStyle,i+=c.l.repeat(e+2),t===s?(i+=r.terminalResetStyle,i+=u?c.rb:c.rc):(i+=r.terminalResetStyle,i+=u?c.cb:c.c)})),i+="\n"})),i}(e.body,l,i);const c=o.colorText(s);if(d){const e=c[0].split("%c"),t=c.map(((t,r)=>{if(r>0){const l=[...e[r]].reduce(((e,t)=>o.strInTerminalLength(t)>1?(u.emojiRegex.lastIndex=0,t.match(u.emojiRegex)?e-(u.emojiLength-2):e+(2-u.chineseLength)):e),0);return t+"font-family: Consolas,Monaco,Courier,'Courier New','等宽字体',monospace; font-size:"+n+"px;word-spacing:normal;padding:0;margin:0;padding-right:"+l*n+"px"}return t}));console.log(...t)}else console.log(...c)}const S=e.createConstructor((function(e){const[o,r]=function(e){t.isUndefined(e)&&(e={}),t.isArray(e)&&(e={body:e});const o=new b;l(o,e),Object.setPrototypeOf(o,f);const r=new h(o);return e.header&&(r.header=s(e.header,a(o))),e.body?.forEach((e=>r.body.push(s(e,o)))),[r,o]}(e);let n=12;const i=()=>m(o,n);return Object.setPrototypeOf(i,this),Object.defineProperties(i,{addRow:{value:e=>(o.body.push(s(e,r)),i),configurable:!1,writable:!1,enumerable:!1},setHeader:{value:e=>(o.header=s(e,a(r)),i),configurable:!1,writable:!1,enumerable:!1},setFontSize:{value:e=>(n=e,i)}}),i}));exports.ColoredTable=S,exports.ColoredTableGlobalData=f,exports.Table=S;
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* # 构建 DIY 表单
|
|
4
|
+
*
|
|
5
|
+
* 使用 console.table 构建的表单默认不支持彩色文本(目前我没找到支持的方法),遂花几日写该方法
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
declare const tableClass: import("a-js-tools").CreateConstructor<import("./src/types").ColoredTable, [options?: import(".").ColoredTableOptions]>;
|
|
11
|
+
export { tableClass as ColoredTable, tableClass as Table };
|
|
12
|
+
export type { ColoredTableCellValue, ColoredTableBorderStyle, ColoredTableUnilateralBorder, ColoredTableUnilateralBorderOptions, ColoredTableBorder, ColoredTableBorderOptions, ColoredBorderOptions, ColoredTableContentAlign, ColoredTableCommon, ColoredTableCommonOption, ColoredTableCellNoBorder, ColoredTableCell, ColoredTableRowOption, ColoredTableEle, ColoredTableOptions, } from './src/types';
|
|
13
|
+
export { globalData as ColoredTableGlobalData } from './src/global';
|
package/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createConstructor as o,isNode as e}from"a-js-tools";import{isType as t,isString as r,isUndefined as n,isPlainObject as l,isArray as c,isBusinessEmptyString as i,isNull as s}from"a-type-of-js";import{pen as a,cutoffStringWithChar as d,strInTerminalLength as b,colorText as u}from"color-pen";import{terminalResetStyle as f}from"@color-pen/static";const h=o((function(o){return this.data=[],Object.setPrototypeOf(this,o),this}));function g(o,e){if(e.align&&(o.align=e.align),e.bgColor&&(o.bgColor=e.bgColor),e.color&&(o.color=e.color),e.italic&&(o.italic=e.italic),e.underline&&(o.underline=e.underline),e.border)if(t(e.border,(o=>r(o)))){const t=e.border;o.border={left:{color:void 0,style:t},right:{color:void 0,style:t},top:{color:void 0,style:t},bottom:{color:void 0,style:t}}}else if(t(e.border,(o=>["color","style"].some((e=>!n(o[e])))))){const t=e.border,r=t.style,n=t.color||void 0;o.border=JSON.parse(JSON.stringify({left:{color:n,style:r},right:{color:n,style:r},top:{color:n,style:r},bottom:{color:n,style:r}},((o,e)=>""===e?void 0:e)))}else t(e.border,(o=>["left","right","top","bottom"].some((e=>!n(o[e])))))&&(o.border=e.border)}class p{}function m(o,e){c(o)&&(o={data:o});const r=new p;g(r,o);const i=new h(r);return Object.setPrototypeOf(r,e),o.data?.forEach((o=>{o&&i.data.push(function(o,e){if(n(o))return;t(o,(o=>!l(o)))&&(o={content:o});const r={content:o.content};return g(r,o),Object.setPrototypeOf(r,e),r}(o,r))})),i}class y extends p{border={left:{style:"bold",color:void 0},right:{style:"bold",color:void 0},top:{style:"bold",color:void 0},bottom:{style:"bold",color:void 0}}}function v(o){const e=new y;return Object.setPrototypeOf(e,o),e}const F=!e(),j={emojiLength:2.08,emojiRegex:/[\u{1F600}-\u{1F64F}\u{1F300}-\u{1F5FF}\u{1F680}-\u{1F6FF}\u{1F900}-\u{1F9FF}]/gu,chineseLength:1.8,chineseRegex:/[\u4E00-\u9FFF]/g};const x=new class{align="left";color="";bgColor="";bold=!1;underline=!1;italic=!1;border={left:{color:void 0,style:"simple"},right:{color:void 0,style:"simple"},top:{color:void 0,style:"simple"},bottom:{color:void 0,style:"simple"}}},O=o((function(o){return this.body=[],this.header=void 0,Object.setPrototypeOf(this,o),this}));class C{}function E(o){let e=a;return t(o)&&(o.bold&&(e=e.bold),i(o.bgColor)||n(o.bgColor)||(e=e.bgColor(o.bgColor)),i(o.color)||n(o.color)||(e=e.color(o.color)),o.italic&&(e=e.italic),o.underline&&(e=e.underline)),e}const w={fine:{lt:"┌",ct:"┬",rt:"┐",lc:"├",c:"┼",rc:"┤",lb:"└",cb:"┴",rb:"┘",l:"─",v:"│"}};function R(o){let e=0;return[...o].forEach((o=>{j.emojiRegex.lastIndex=0,j.chineseRegex.lastIndex=0,o.match(j.emojiRegex)?e+=j.emojiLength:o.match(j.chineseRegex)?e+=j.chineseLength:e++})),Math.ceil(e)}function P(o,e){const t=function(o){const e=[];return o.header&&o.header.data.forEach(((o,t)=>{const r=o?.content?.toString()??"";e[t]=Math.max(e[t]??0,F?R(r):b(r))})),o.body&&o.body.forEach((o=>{o.data.forEach(((o,t)=>{const r=o?.content?.toString()??"";e[t]=Math.max(e[t]??0,F?R(r):b(r))}))})),e}(o);let r=!1,l="";o.header&&(r=!0,l+=function(o,e){let t="";const r=e.length-1,{fine:l}=w,c=E(o);return e.forEach(((o,e)=>{0===e&&(t+=l.lt),t+=f,t+=l.l.repeat(o+2),e===r?(t+=f,t+=l.rt):(t+=f,t+=l.ct)})),t+="\n",e.forEach(((e,i)=>{t+=f,t+=l.v;const a=o.data[i];if(n(a)||s(a))t+=f,t+=c(" ".repeat(e+2));else{const o=E(a);let r=a.content?.toString()??"";r=r.replace(/[\n]/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t"),t+=f,t+=o`\u2002${d(r,e)}\u2002`}i===r&&(t+=l.v)})),t+="\n",t}(o.header,t)),l+=function(o,e,t){let r="";const l=e.length-1,{fine:c}=w;return e.forEach(((o,e)=>{0===e&&(r+=f,r+=t?c.lc:c.lt),r+=f,r+=c.l.repeat(o+2),e===l?(r+=f,r+=t?c.rc:c.rt):(r+=f,r+=t?c.c:c.ct)})),r+="\n",o.forEach(((t,i)=>{const a=E(t);e.forEach(((o,e)=>{r+=f,r+=c.v;const i=t.data[e];if(n(i)||s(i))r+=a`${" ".repeat(o+2)}`;else{const e=E(i);let t=i.content?.toString()||"";t=t.replace(/[\n]/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t"),r+=f,r+=e`\u2002${d(t,o)}\u2002`}e===l&&(r+=f,r+=c.v)})),r+="\n";const b=o.length-1===i;e.forEach(((o,e)=>{0===e&&(r+=f,r+=b?c.lb:c.lc),r+=f,r+=c.l.repeat(o+2),e===l?(r+=f,r+=b?c.rb:c.rc):(r+=f,r+=b?c.cb:c.c)})),r+="\n"})),r}(o.body,t,r);const c=u(l);if(F){const o=c[0].split("%c"),t=c.map(((t,r)=>{if(r>0){const n=[...o[r]].reduce(((o,e)=>b(e)>1?(j.emojiRegex.lastIndex=0,e.match(j.emojiRegex)?o-(j.emojiLength-2):o+(2-j.chineseLength)):o),0);return t+"font-family: Consolas,Monaco,Courier,'Courier New','等宽字体',monospace; font-size:"+e+"px;word-spacing:normal;padding:0;margin:0;padding-right:"+n*e+"px"}return t}));console.log(...t)}else console.log(...c)}const S=o((function(o){const[e,t]=function(o){n(o)&&(o={}),c(o)&&(o={body:o});const e=new C;g(e,o),Object.setPrototypeOf(e,x);const t=new O(e);return o.header&&(t.header=m(o.header,v(e))),o.body?.forEach((o=>t.body.push(m(o,e)))),[t,e]}(o);let r=12;const l=()=>P(e,r);return Object.setPrototypeOf(l,this),Object.defineProperties(l,{addRow:{value:o=>(e.body.push(m(o,t)),l),configurable:!1,writable:!1,enumerable:!1},setHeader:{value:o=>(e.header=m(o,v(t)),l),configurable:!1,writable:!1,enumerable:!1},setFontSize:{value:o=>(r=o,l)}}),l}));export{S as ColoredTable,x as ColoredTableGlobalData,S as Table};
|
package/package.json
CHANGED
|
@@ -1,31 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "colored-table",
|
|
3
|
-
"version": "0.0.0",
|
|
4
3
|
"type": "module",
|
|
5
|
-
"
|
|
4
|
+
"version": "0.0.2",
|
|
5
|
+
"description": "一个简单的在控制台及控制台构建彩色文本表格的工具 🔧",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@color-pen/static": "^1.0.0",
|
|
9
|
+
"a-js-tools": "^1.0.0",
|
|
10
|
+
"a-type-of-js": "^1.0.1",
|
|
11
|
+
"color-pen": "^2.0.10"
|
|
12
|
+
},
|
|
6
13
|
"author": {
|
|
7
|
-
"name": "
|
|
14
|
+
"name": "earthnut",
|
|
8
15
|
"email": "earthnut.dev@outlook.com",
|
|
9
16
|
"url": "https://earthnut.dev"
|
|
10
17
|
},
|
|
11
|
-
"homepage": "https://earthnut.dev/vue",
|
|
12
|
-
"license": "ISC",
|
|
13
|
-
"description": "但是你如果有需要,可以邮我转让 <earthnut.dev@outlook.com>",
|
|
14
18
|
"files": [
|
|
15
|
-
"index.
|
|
19
|
+
"index.mjs",
|
|
20
|
+
"index.cjs",
|
|
21
|
+
"index.d.ts",
|
|
22
|
+
"src"
|
|
16
23
|
],
|
|
17
|
-
"
|
|
18
|
-
"
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"import": {
|
|
27
|
+
"default": "./index.mjs",
|
|
28
|
+
"types": "./index.d.ts"
|
|
29
|
+
},
|
|
30
|
+
"require": {
|
|
31
|
+
"default": "./index.cjs",
|
|
32
|
+
"types": "./index.d.ts"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
19
35
|
},
|
|
20
36
|
"keywords": [
|
|
21
|
-
"
|
|
37
|
+
"colored-table"
|
|
22
38
|
],
|
|
39
|
+
"homepage": "https://earthnut.dev/colored-table",
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/earthnutDev/qqi/issues",
|
|
42
|
+
"email": "earthnut.dev@outlook.com"
|
|
43
|
+
},
|
|
23
44
|
"repository": {
|
|
24
45
|
"type": "git",
|
|
25
|
-
"url": "git+https://github.com/
|
|
46
|
+
"url": "git+https://github.com/earthnutDev/qqi.git"
|
|
26
47
|
},
|
|
27
48
|
"publishConfig": {
|
|
28
49
|
"access": "public",
|
|
29
|
-
"registry": "https://registry.npmjs.org"
|
|
50
|
+
"registry": "https://registry.npmjs.org/"
|
|
30
51
|
}
|
|
31
|
-
}
|
|
52
|
+
}
|
package/src/core.d.ts
ADDED
package/src/global.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ColoredTableBorder, ColoredTableContentAlign } from './types';
|
|
2
|
+
/** 浏览器环境 */
|
|
3
|
+
export declare const browserEnv: boolean;
|
|
4
|
+
export declare const data: {
|
|
5
|
+
emojiLength: number;
|
|
6
|
+
emojiRegex: RegExp;
|
|
7
|
+
chineseLength: number;
|
|
8
|
+
/** 中文的正则 */
|
|
9
|
+
chineseRegex: RegExp;
|
|
10
|
+
};
|
|
11
|
+
/** 全局的属性 */
|
|
12
|
+
declare class ColoredTableGlobalData {
|
|
13
|
+
align: ColoredTableContentAlign;
|
|
14
|
+
color: string;
|
|
15
|
+
bgColor: string;
|
|
16
|
+
bold: boolean;
|
|
17
|
+
underline: boolean;
|
|
18
|
+
italic: boolean;
|
|
19
|
+
border: ColoredTableBorder;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* 全局 table 配置
|
|
24
|
+
*
|
|
25
|
+
* 若没有其他特殊说名,将使用该数据作为最终的渲染依据
|
|
26
|
+
*
|
|
27
|
+
* 即为默认属性
|
|
28
|
+
*/
|
|
29
|
+
export declare const globalData: ColoredTableGlobalData;
|
|
30
|
+
export {};
|
package/src/lines.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export declare const lines: {
|
|
2
|
+
lt: {
|
|
3
|
+
'00': string;
|
|
4
|
+
'01': string;
|
|
5
|
+
'02': string;
|
|
6
|
+
'03': string;
|
|
7
|
+
'10': string;
|
|
8
|
+
'11': string;
|
|
9
|
+
'12': string;
|
|
10
|
+
'13': string;
|
|
11
|
+
'20': string;
|
|
12
|
+
'21': string;
|
|
13
|
+
'22': string;
|
|
14
|
+
'23': string;
|
|
15
|
+
};
|
|
16
|
+
ct: {
|
|
17
|
+
'000': string;
|
|
18
|
+
'111': string;
|
|
19
|
+
'101': string;
|
|
20
|
+
'010': string;
|
|
21
|
+
'': string;
|
|
22
|
+
};
|
|
23
|
+
fine: {
|
|
24
|
+
lt: string;
|
|
25
|
+
ct: string;
|
|
26
|
+
rt: string;
|
|
27
|
+
lc: string;
|
|
28
|
+
c: string;
|
|
29
|
+
rc: string;
|
|
30
|
+
lb: string;
|
|
31
|
+
cb: string;
|
|
32
|
+
rb: string;
|
|
33
|
+
l: string;
|
|
34
|
+
v: string;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ColoredTableCommonOption, ColoredTableRow, ColoredTableRowOption } from '../types';
|
|
2
|
+
/** 表格的行原型 */
|
|
3
|
+
export declare class RowProto {
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* 解析行
|
|
7
|
+
*
|
|
8
|
+
* @param data 行数据
|
|
9
|
+
* @param parentPro 父级的属性参数
|
|
10
|
+
*/
|
|
11
|
+
export declare function parseRow(data: ColoredTableRowOption, parentPro: ColoredTableCommonOption): ColoredTableRow;
|
package/src/types.d.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/** 表格的单元格的内容数据格式 */
|
|
2
|
+
export type ColoredTableCellValue = string | number | undefined | boolean | null;
|
|
3
|
+
/** 表格的边框样式 (当前版本仅 `simple`、`undefined` 值可用) */
|
|
4
|
+
export type ColoredTableBorderStyle = undefined | 'simple' | 'bold' | 'double' | 'dash';
|
|
5
|
+
/** 表格的边框 */
|
|
6
|
+
export type ColoredTableUnilateralBorder = {
|
|
7
|
+
style: ColoredTableBorderStyle;
|
|
8
|
+
color: string | undefined;
|
|
9
|
+
};
|
|
10
|
+
/** 配置单边边框属性 */
|
|
11
|
+
export type ColoredTableUnilateralBorderOptions = {
|
|
12
|
+
[x in keyof ColoredTableUnilateralBorder]?: ColoredTableUnilateralBorder[x];
|
|
13
|
+
};
|
|
14
|
+
/** 表格的单边边框(最终解析) */
|
|
15
|
+
export type ColoredTableBorder = {
|
|
16
|
+
left: ColoredTableUnilateralBorder;
|
|
17
|
+
right: ColoredTableUnilateralBorder;
|
|
18
|
+
top: ColoredTableUnilateralBorder;
|
|
19
|
+
bottom: ColoredTableUnilateralBorder;
|
|
20
|
+
};
|
|
21
|
+
/** 配置四个方向的边框 */
|
|
22
|
+
export type ColoredTableBorderOptions = {
|
|
23
|
+
[x in keyof ColoredTableBorder]?: ColoredTableUnilateralBorderOptions;
|
|
24
|
+
};
|
|
25
|
+
/** 边框配置 */
|
|
26
|
+
export type ColoredBorderOptions = ColoredTableBorderStyle | ColoredTableBorderOptions | ColoredTableUnilateralBorderOptions;
|
|
27
|
+
/** 文本对齐方式 */
|
|
28
|
+
export type ColoredTableContentAlign = 'left' | 'center' | 'right';
|
|
29
|
+
/** 公有属性,继承制 */
|
|
30
|
+
export type ColoredTableCommon = {
|
|
31
|
+
/** 对齐 */
|
|
32
|
+
align: ColoredTableContentAlign;
|
|
33
|
+
/** 文本色 */
|
|
34
|
+
color: string;
|
|
35
|
+
/** 背景色 */
|
|
36
|
+
bgColor: string;
|
|
37
|
+
/** 是否为粗体 */
|
|
38
|
+
bold: boolean;
|
|
39
|
+
/** 是否含下划线 */
|
|
40
|
+
underline: boolean;
|
|
41
|
+
/** 是否为斜文本 */
|
|
42
|
+
italic: boolean;
|
|
43
|
+
};
|
|
44
|
+
/** 一个使用的简单的除数据外的属性 */
|
|
45
|
+
export type ColoredTableCommonOption = {
|
|
46
|
+
[x in keyof ColoredTableCommon]?: ColoredTableCommon[x];
|
|
47
|
+
} & {
|
|
48
|
+
border?: ColoredBorderOptions;
|
|
49
|
+
};
|
|
50
|
+
/** 表格的单元格配置 */
|
|
51
|
+
export type ColoredTableCellNoBorder = {
|
|
52
|
+
/** 内容(文本) */
|
|
53
|
+
content: ColoredTableCellValue;
|
|
54
|
+
} & ColoredTableCommon;
|
|
55
|
+
/** 带表格的单元格配置 */
|
|
56
|
+
export type ColoredTableCell = ColoredTableCellNoBorder & {
|
|
57
|
+
border: ColoredTableBorder;
|
|
58
|
+
};
|
|
59
|
+
/** 单行 */
|
|
60
|
+
export type ColoredTableRow = {
|
|
61
|
+
data: (ColoredTableCell | undefined)[];
|
|
62
|
+
} & ColoredTableCommon & {
|
|
63
|
+
border: ColoredTableBorder;
|
|
64
|
+
};
|
|
65
|
+
export type ColoredTableRowOptionData = ColoredTableCellValue | ({
|
|
66
|
+
[x in keyof ColoredTableCellNoBorder]?: ColoredTableCellNoBorder[x];
|
|
67
|
+
} & {
|
|
68
|
+
border?: ColoredBorderOptions;
|
|
69
|
+
}) | undefined;
|
|
70
|
+
/** 单行表数据 */
|
|
71
|
+
export type ColoredTableRowOption = ColoredTableRowOptionData[] | ({
|
|
72
|
+
data?: ColoredTableRowOptionData[];
|
|
73
|
+
} & ColoredTableCommonOption);
|
|
74
|
+
/** 使用单元格 */
|
|
75
|
+
export type ColoredTableEle = {
|
|
76
|
+
/** 表头 */
|
|
77
|
+
header?: ColoredTableRow;
|
|
78
|
+
/** 表干 */
|
|
79
|
+
body: ColoredTableRow[];
|
|
80
|
+
} & ColoredTableCommon & ColoredTableBorder;
|
|
81
|
+
/** 单元格 */
|
|
82
|
+
export type ColoredTableOptions = ({
|
|
83
|
+
/** 头部 */
|
|
84
|
+
header?: ColoredTableRowOption;
|
|
85
|
+
/** 内容 */
|
|
86
|
+
body?: ColoredTableRowOption[];
|
|
87
|
+
} & ColoredTableCommonOption) | ColoredTableRowOption[] | undefined;
|
|
88
|
+
/** 表 */
|
|
89
|
+
export type ColoredTable = {
|
|
90
|
+
/** 开始构建 */
|
|
91
|
+
(): void;
|
|
92
|
+
} & {
|
|
93
|
+
/** 添加表头 */
|
|
94
|
+
setHeader(data: ColoredTableRowOption): ColoredTable;
|
|
95
|
+
/** 添加行 */
|
|
96
|
+
addRow(data: ColoredTableRowOption): ColoredTable;
|
|
97
|
+
/**
|
|
98
|
+
* 设置字体大小
|
|
99
|
+
*
|
|
100
|
+
* (该值仅影响浏览器环境,不支持终端环境)
|
|
101
|
+
*
|
|
102
|
+
* 缺省值: 12
|
|
103
|
+
*/
|
|
104
|
+
setFontSize(fontSize: number): ColoredTable;
|
|
105
|
+
};
|
package/index.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { readFileToJsonSync } from "a-node-tools";
|
|
2
|
-
import { default as pen } from "color-pen";
|
|
3
|
-
import { writeFileSync } from "node:fs";
|
|
4
|
-
|
|
5
|
-
const fileInfo = readFileToJsonSync("./info.json");
|
|
6
|
-
|
|
7
|
-
const npmLists = fileInfo.objects
|
|
8
|
-
.map((i) => i.package.name)
|
|
9
|
-
.filter((name) => name.length < 4)
|
|
10
|
-
.sort()
|
|
11
|
-
.reduce((accumulator, currentName, i) => {
|
|
12
|
-
// const pkgName = pen.hex(i % 255)(currentName);
|
|
13
|
-
// if (i % 3 === 2) {
|
|
14
|
-
// accumulator += pen(`${currentName.padEnd(36, " ")}\n${" ".repeat(4)}`);
|
|
15
|
-
// } else {
|
|
16
|
-
// accumulator += `${currentName.padEnd(36, " ")}`;
|
|
17
|
-
// }
|
|
18
|
-
accumulator += `${currentName.padEnd(3, " ")}\n`;
|
|
19
|
-
return accumulator;
|
|
20
|
-
}, " ".repeat(4));
|
|
21
|
-
|
|
22
|
-
console.log(npmLists);
|
|
23
|
-
|
|
24
|
-
writeFileSync("./npm-lists.txt", npmLists);
|