npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@wll8/text2table

v1.0.0

Published

一个强大的文本转表格工具,支持将层级结构的文本转换为多种表格格式

Readme

Text2Table

一个强大的文本转表格工具,支持将层级结构的文本转换为多种表格格式。

🚀 特性

  • 多格式支持:支持 YAML、JSON、CSV、HTML、Excel、Markdown 等输出格式
  • 智能解析:自动识别缩进、标题、列表等层级结构
  • 混合格式:支持多种标记符号混合使用(标题 + 列表 + 缩进)
  • 注解功能:支持 -- 分隔符添加注解信息
  • Excel 优化:支持合并单元格、自动换行、自定义列宽
  • 自定义列名:支持自定义表头和 ${serial} 模板变量

📦 安装

npm install @wll8/text2table

开发安装

git clone https://github.com/wll8/text2table.git
cd text2table
npm install
npm run build

🎯 快速开始

基本用法

# 默认输出 YAML 格式
npx text2table -i input.txt

# 输出 CSV 格式
npx text2table -i input.txt -f csv

# 输出 Excel 文件
npx text2table -i input.txt -f xlsx -o output.xlsx

自定义列名

# 使用自定义列名
npx text2table -i input.txt -f csv -c "系统模块,${serial}级功能,说明"

# Excel 格式使用自定义列名
npx text2table -i input.txt -f xlsx -o output.xlsx -c "业务模块,${serial}级组件,详细描述"

📝 支持的文本格式

1. 标题格式

## 首页模块
### 轮播图
### 快捷分类入口

## 商品模块
### 商品详情
#### 商品信息展示
#### 库存状态显示

2. 列表格式

- 首页模块
  - 轮播图
  - 快捷分类入口
- 商品模块
  - 商品详情
    - 商品信息展示
    - 库存状态显示

3. 编号格式

1. 首页模块
   1. 轮播图
   2. 快捷分类入口
2. 商品模块
   1. 商品详情
      1. 商品信息展示
      2. 库存状态显示

4. 缩进格式

首页模块
  轮播图
  快捷分类入口
商品模块
  商品详情
    商品信息展示
    库存状态显示

5. 混合格式

## 首页模块
- 轮播图
- 快捷分类入口

## 商品模块
- 商品详情
  - 商品信息展示
  - 库存状态显示

💬 注解功能

使用 -- 分隔符添加注解:

首页模块
  轮播图 -- 在页面顶部,可以手动切换,支持视频
  快捷分类入口 -- 提供快速进入各分类的入口

📊 输出格式

CSV 格式

模块,1级功能,2级功能,注解
首页模块,轮播图,,在页面顶部,可以手动切换,支持视频
首页模块,快捷分类入口,,提供快速进入各分类的入口

YAML 格式(层级结构)

- content: 首页模块
  level: 1
  children:
    - content: 轮播图
      annotation: 在页面顶部,可以手动切换,支持视频
      level: 2
      children: []
    - content: 快捷分类入口
      annotation: 提供快速进入各分类的入口
      level: 2
      children: []

Excel 格式

  • 专业表头:1厘米高度,水平垂直居中
  • 智能合并:相同父级自动合并单元格
  • 注解列优化:20厘米宽度,自动换行
  • 自适应宽度:其他列根据内容自动调整

⚙️ CLI 选项

-i, --input <file>           输入文件路径
-o, --output <file>          输出文件路径
-f, --format <format>        输出格式: csv, html, yaml, json, md-level, xlsx (默认: yaml)
-l, --max-length <number>    最大字符长度限制 (默认: 20)
-s, --separator <string>     注解分隔符 (默认: " -- ")
-c, --columns <headers>      自定义列名称,用逗号分隔 (默认: "模块, ${serial}级功能, 注解")
--no-annotations             不包含注解列
-h, --help                   显示帮助信息

自定义列名模板

使用 ${serial} 作为序号占位符:

  • 模块, ${serial}级功能, 注解模块, 1级功能, 2级功能, 注解
  • 系统, ${serial}级组件, 说明系统, 1级组件, 2级组件, 说明

📚 API 使用

import { Text2Table } from '@wll8/text2table';

// 基本使用
const converter = new Text2Table();
const csvResult = converter.toCsv(text);
const yamlResult = converter.toYaml(text);

// 自定义配置
const customConverter = new Text2Table({
  maxLength: 30,
  annotationSeparator: ' :: ',
  columnHeaders: '业务模块, ${serial}级功能, 详细说明'
});

// 生成 Excel 文件
await converter.convertToXlsx(text, 'output.xlsx');

// 便捷方法
const csv = converter.toCsv(text);
const html = converter.toHtml(text);
const yaml = converter.toYaml(text);
const json = converter.toJson(text);

💡 使用场景

1. AI 生成内容整理

将 ChatGPT、Claude 等大模型生成的功能清单、分类列表转换为结构化表格。

2. 文档结构化

将会议纪要、需求文档中的层级内容转换为 Excel 表格进行管理。

3. 数据可视化

将文本形式的层级数据转换为表格,便于进一步分析和处理。

🔧 技术栈

  • TypeScript - 类型安全的开发体验
  • Node.js - 跨平台运行时
  • ExcelJS - Excel 文件生成和处理
  • js-yaml - YAML 格式支持
  • Vitest - 现代化测试框架

🧪 开发

# 安装依赖
npm install

# 构建项目
npm run build

# 运行测试
npm test

# 监控测试
npm run test:watch

📈 项目结构

text2table/
├── src/
│   ├── types.ts           # 类型定义
│   ├── parser.ts          # 文本解析器
│   ├── table-generator.ts # 表格生成器
│   ├── text2table.ts      # 主转换类
│   ├── cli.ts             # 命令行工具
│   └── index.ts           # 入口文件
├── tests/                 # 测试文件
│   ├── parser.test.ts
│   ├── table-generator.test.ts
│   ├── text2table.test.ts
│   └── mixed-format.test.ts
├── dist/                  # 编译输出
└── package.json

🤝 贡献

欢迎提交 Issue 和 Pull Request!

📄 许可证

MIT License