LipGloss.js (英语)
你所知道和所爱的唇膏 现在在JavaScript.
[尖叫声] LipGloss.js是斯图尔实验.
安装
npm i @charmland/lipgloss
示例
const { Table, TableData, Style, Color, List, Tree, Leaf, Bullet, RoundedEnumerator } = require("@charmland/lipgloss");
var s = new Style().foreground(Color("240")).render;
console.log(
new Table()
.wrap(false)
.headers("Drink", "Description")
.row("Bubble Tea", s("Milky"))
.row("Milk Tea", s("Also milky"))
.row("Actual milk", s("Milky as well"))
.render(),
);
// TableData example - for more complex data management
const employeeData = new TableData(
["Employee ID", "Name", "Department"],
["001", "John Doe", "Engineering"],
["002", "Jane Smith", "Marketing"],
["003", "Mike Johnson", "Sales"]
);
console.log(
new Table()
.data(employeeData)
.styleFunc((row, col) => {
if (row === -1) {
return new Style().foreground(Color("99")).bold(true);
}
return new Style().padding(0, 1);
})
.render()
);
// List example
const groceries = new List("Bananas", "Barley", "Cashews", "Milk")
.enumerator(Bullet)
.itemStyle(new Style().foreground(Color("255")));
console.log(groceries.render());
// Tree example with Leaf nodes
const makeupTree = new Tree()
.root("⁜ Makeup")
.child(
"Glossier",
"Fenty Beauty",
new Tree().child(
new Leaf("Gloss Bomb Universal Lip Luminizer"),
new Leaf("Hot Cheeks Velour Blushlighter")
),
new Leaf("Nyx"),
new Leaf("Mac"),
"Milk"
)
.enumerator(RoundedEnumerator)
.enumeratorStyle(new Style().foreground(Color("63")).marginRight(1))
.rootStyle(new Style().foreground(Color("35")))
.itemStyle(new Style().foreground(Color("212")));
console.log(makeupTree.render());
表格数据
这个 TableData 类提供了比起使用单个行来管理表格数据的更结构化的方法. 需要时特别有用:
- 动态构建表格
- 在方案上访问各个单元
- 管理大数据集
- 将数据逻辑与演示文稿分开
基本用途
const { Table, TableData, Style, Color } = require("@charmland/lipgloss");
// Create TableData with initial rows
const data = new TableData(
["Name", "Age", "City"],
["Alice", "25", "New York"],
["Bob", "30", "San Francisco"]
);
// Or build it incrementally
const data2 = new TableData()
.append(["Product", "Price"])
.append(["Laptop", "$999"])
.append(["Mouse", "$25"]);
// Use with Table
const table = new Table()
.data(data)
.styleFunc((row, col) => {
if (row === -1) return new Style().bold(true); // Header
return new Style().padding(0, 1);
})
.render();
表格数据方法
new TableData(...rows)- 以可选初始行创建.append(row)- 添加一行(字符串阵列).rows(...rows)- 一次添加多行.at(row, col)- 在特定位置获得价值.rowCount()- 获取行数.columnCount()- 获取列数
见 examples/table-data.js 比较全面的例子.
环境变量
您可以使用环境变量控制调试输出 :
LIPGLOSS_DEBUG=true- 启用所有 lipgloss 调试输出DEBUG=lipgloss- 启用 lipgloss 调试输出(标准调试模式)DEBUG=*- 启用所有调试输出
示例
node your-script.js
兼容性
在JavaScript中Lipgloss是实验性的,很多已存在的功能还没有被移植到JavaScript上.
规模(100%)
| 函数 | 状态 |
|---|---|
Width | ✅ |
Height | ✅ |
Size | ✅ |
颜色 (100%)
| 函数 | 状态 |
|---|---|
Color | ✅ |
NoColor | ✅ |
Complete | ✅ |
LightDark | ✅ |
RGBA | ✅ |
边界(100%)
| 函数 | 状态 |
|---|---|
NormalBorder | ✅ |
RoundedBorder | ✅ |
BlockBorder | ✅ |
OuterHalfBlockBorder | ✅ |
InnerHalfBlockBorder | ✅ |
ThickBorder | ✅ |
DoubleBorder | ✅ |
HiddenBorder | ✅ |
MarkdownBorder | ✅ |
ASCIIBorder | ✅ |
样式(97.62%)
| 函数 | 状态 |
|---|---|
Foreground | ✅ |
Background | ✅ |
Width | ✅ |
Height | ✅ |
Align | ✅ |
AlignHorizontal | ✅ |
AlignVertical | ✅ |
Padding | ✅ |
PaddingLeft | ✅ |
PaddingRight | ✅ |
PaddingTop | ✅ |
PaddingBottom | ✅ |
ColorWhitespace | ✅ |
Margin | ✅ |
MarginLeft | ✅ |
MarginRight | ✅ |
MarginTop | ✅ |
MarginBottom | ✅ |
MarginBackground | ✅ |
Border | ✅ |
BorderStyle | ✅ |
SetBorderRight | ✅ |
SetBorderLeft | ✅ |
SetBorderTop | ✅ |
SetBorderBottom | ✅ |
BorderForeground | ✅ |
BorderTopForeground | ✅ |
BorderRightForeground | ✅ |
BorderBottomForeground | ✅ |
BorderLeftForeground | ✅ |
BorderBackground | ✅ |
BorderTopBackground | ✅ |
BorderRightBackground | ✅ |
BorderBottomBackground | ✅ |
BorderLeftBackground | ✅ |
Inline | ✅ |
MaxWidth | ✅ |
MaxHeight | ✅ |
TabWidth | ✅ |
UnderlineSpaces | ✅ |
Underline | ✅ |
Reverse | ✅ |
SetString | ✅ |
Inherit | ✅ |
Faint | ✅ |
Italic | ✅ |
Strikethrough | ✅ |
StrikethroughSpaces | ✅ |
Transform | ⏳ |
表格(100%)
| 函数 | 状态 |
|---|---|
table.New | ✅ |
table.Rows | ✅ |
table.Headers | ✅ |
table.Render | ✅ |
table.ClearRows | ✅ |
table.BorderTop | ✅ |
table.BorderBottom | ✅ |
table.BorderLeft | ✅ |
table.BorderRight | ✅ |
table.BorderHeader | ✅ |
table.BorderColumn | ✅ |
table.BorderRow | ✅ |
table.Width | ✅ |
table.Height | ✅ |
table.Offset | ✅ |
table.String | ✅ |
table.StyleFunc | ✅ |
table.Data | ✅ |
table.Border | ✅ |
table.BorderStyle | ✅ |
名单(100%)
| 函数 | 状态 |
|---|---|
Hidden | ✅ |
Hide | ✅ |
Offset | ✅ |
Value | ✅ |
String | ✅ |
Indenter | ✅ |
ItemStyle | ✅ |
ItemStyleFunc | ✅ |
EnumeratorStyle | ✅ |
EnumeratorStyleFunc | ✅ |
Item | ✅ |
Items | ✅ |
Enumerator | ✅ |
树 (95%)
| 函数 | 状态 |
|---|---|
tree.New | ✅ |
tree.Root | ✅ |
tree.Child | ✅ |
tree.Hidden | ✅ |
tree.Hide | ✅ |
tree.SetHidden | ✅ |
tree.Offset | ✅ |
tree.Value | ✅ |
tree.SetValue | ✅ |
tree.String | ✅ |
tree.Render | ✅ |
tree.EnumeratorStyle | ✅ |
tree.EnumeratorStyleFunc | ✅ |
tree.ItemStyle | ✅ |
tree.ItemStyleFunc | ✅ |
tree.RootStyle | ✅ |
tree.Enumerator | ✅ |
tree.Indenter | ✅ |
tree.DefaultEnumerator | ✅ |
tree.RoundedEnumerator | ✅ |
tree.DefaultIndenter | ✅ |
NewLeaf | ✅ |
Leaf.Value | ✅ |
Leaf.SetValue | ✅ |
Leaf.Hidden | ✅ |
Leaf.SetHidden | ✅ |
Leaf.String | ✅ |
| 自定义数字 | ⏳ |
| 自定义缩进 | ⏳ |
加入(100%)
| 函数 | 状态 |
|---|---|
JoinHorizontal | ✅ |
JoinVertical | ✅ |
职位(100%)
| 函数 | 状态 |
|---|---|
Center | ✅ |
Right | ✅ |
Bottom | ✅ |
Top | ✅ |
Left | ✅ |
Place | ✅ |
查询( 50%)
| 函数 | 状态 |
|---|---|
BackgroundColor | ⏳ |
HasDarkBackground | ✅ |
对齐(0%)
| 函数 | 状态 |
|---|---|
EnableLegacyWindowsANSI | ⏳ |
捐款
我们很乐意你出力 请看 提供指南 更多信息.
测试
JavaScript装订包括一个全面的测试套件:
# From bindings directory
npm test # Run all tests
npm run test:simple # Basic table functionality
npm run test:comprehensive # Complete TableData tests
npm run examples # Showcase functionality
# Or from examples directory
cd examples && npm test
测试位于 examples/tests/ 并覆盖:
- 基本表格功能
- 表格数据操作
- 样式函数
- Unicode 处理( 有已知限制)
见 捐款。 。 。 .
反馈
我们很想听听你对这个项目的看法。 给我们留个字条吧!
许可证
部分 魅力。 。 。 .
• 魅力爱开源
