@charmland/lipgloss

中文文档
2.0.0-beta.3-0e280f3发布于 2025/10/06MITES Module零依赖近 30 天下载 1.5万

Style definitions for nice terminal layouts 👄

原始使用文档
文档目录22 节
  1. Installation
  2. Example
  3. TableData
  4. Basic Usage
  5. TableData Methods
  6. Environment Variables
  7. Compability
  8. Size (100%)
  9. Color (100%)
  10. Borders (100%)
  11. Style (97.62%)
  12. Table (100%)
  13. List (100%)
  14. Tree (95%)
  15. Join (100%)
  16. Position (100%)
  17. Query (50%)
  18. Align (0%)
  19. Contributing
  20. Testing
  21. Feedback
  22. License

LipGloss.js

The lipgloss that you know and love, now in JavaScript.

[!WARNING] LipGloss.js is stll experimental.

Installation

npm i @charmland/lipgloss

Example

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

The TableData class provides a more structured way to manage table data compared to using individual rows. It's particularly useful when you need to:

  • Build tables dynamically
  • Access individual cells programmatically
  • Manage large datasets
  • Separate data logic from presentation

Basic Usage

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();

TableData Methods

  • new TableData(...rows) - Create with optional initial rows
  • .append(row) - Add a single row (array of strings)
  • .rows(...rows) - Add multiple rows at once
  • .at(row, col) - Get value at specific position
  • .rowCount() - Get number of rows
  • .columnCount() - Get number of columns

See examples/table-data.js for more comprehensive examples.

Environment Variables

You can control debug output using environment variables:

  • LIPGLOSS_DEBUG=true - Enable all lipgloss debug output
  • DEBUG=lipgloss - Enable lipgloss debug output (standard debug pattern)
  • DEBUG=* - Enable all debug output

Example:

node your-script.js

Compability

Lipgloss in JavaScript it's experimental and a lot of existing functionalities are not still ported to JavaScript.

Size (100%)

FunctionStatus
Width✅
Height✅
Size✅

Color (100%)

FunctionStatus
Color✅
NoColor✅
Complete✅
LightDark✅
RGBA✅

Borders (100%)

FunctionStatus
NormalBorder✅
RoundedBorder✅
BlockBorder✅
OuterHalfBlockBorder✅
InnerHalfBlockBorder✅
ThickBorder✅
DoubleBorder✅
HiddenBorder✅
MarkdownBorder✅
ASCIIBorder✅

Style (97.62%)

FunctionStatus
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⏳

Table (100%)

FunctionStatus
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✅

List (100%)

FunctionStatus
Hidden✅
Hide✅
Offset✅
Value✅
String✅
Indenter✅
ItemStyle✅
ItemStyleFunc✅
EnumeratorStyle✅
EnumeratorStyleFunc✅
Item✅
Items✅
Enumerator✅

Tree (95%)

FunctionStatus
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✅
Custom Enumerators⏳
Custom Indenters⏳

Join (100%)

FunctionStatus
JoinHorizontal✅
JoinVertical✅

Position (100%)

FunctionStatus
Center✅
Right✅
Bottom✅
Top✅
Left✅
Place✅

Query (50%)

FunctionStatus
BackgroundColor⏳
HasDarkBackground✅

Align (0%)

FunctionStatus
EnableLegacyWindowsANSI⏳

Contributing

We'd love to have you contribute! Please see the contributing guidelines for more information.

Testing

The JavaScript bindings include a comprehensive test suite:

# 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

Tests are located in examples/tests/ and cover:

  • Basic table functionality
  • TableData operations
  • Style functions
  • Unicode handling (with known limitations)

See contributing.

Feedback

We’d love to hear your thoughts on this project. Feel free to drop us a note!

License

MIT


Part of Charm.

The Charm logo

Charm热爱开源 • Charm loves open source

版本与发布记录

@charmland/lipgloss 共发布 2 个版本,首次发布于 2025/10/06;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.0.0-beta.3-0e280f3latest2025/10/061.1 年前
0.0.12025/10/021.1 年前

关于 @charmland/lipgloss 的常见问题

@charmland/lipgloss 是什么?

Style definitions for nice terminal layouts 👄

如何安装 @charmland/lipgloss?

在项目目录运行 npm install @charmland/lipgloss,或使用 pnpm add / yarn add / bun add。

@charmland/lipgloss 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/charmland__lipgloss 是否存在。

@charmland/lipgloss 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@charmland/lipgloss 可以商用吗?

@charmland/lipgloss 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@charmland/lipgloss 的下载量有多少?

根据 npm 官方下载统计,@charmland/lipgloss 在 2026/10/10 – 2026/11/08 这 30 天内被下载 15,450 次,日均约 515 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@charmland/lipgloss 还在维护吗?

最新版本 2.0.0-beta.3-0e280f3 发布于 2025/10/06(1.1 年前);至今共发布 2 个版本,其中过去 12 个月发布了 0 个;首次发布于 2025/10/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。