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 🙏

© 2024 – Pkg Stats / Ryan Hefner

cubb

v1.0.5

Published

cubb是一种命令行的文本标记语言, 用于输出更友好的命令行文本。

Downloads

42

Readme

cubb

cubb是一种命令行的文本标记语言,用于输出更友好的命令行文本。

安装与使用

安装

$ npm install cubb --save

使用

var options = {};
var Cubb = require('cubb');
var cubb = new Cubb(options);
cubb.render('<b>some text</b>');

选项

构造函数支持传入渲染选项

  • options.tab: 如果显示\t,默认为4空格
  • options.box: 盒子渲染选项
  • options.box.margin: 盒子与前后内容之间的行距,默认为1行
  • options.box.padding: 盒子左内补,默认为2空格
  • options.box.borderColor: 边框颜色,默认为'yellow'
  • options.box.paddingVertical: 盒子内垂直间距,默认为0行
  • options.box.paddingHorizontal: 盒子内水平间距,默认为1空格
  • options.list: 列表渲染选项
  • options.list.style: 列表项修饰符号
  • options.list.space: 列表项与列表项之间的行距,默认为0行
  • options.list.margin: 列表与前后内容之间的行距,默认为1行
  • options.list.padding: 列表左内补,默认为2空格
  • options.table: 表格渲染选项
  • options.table.margin: 表格与前后内容之间的行距,默认为1行
  • options.table.padding: 表格左内补,默认为2空格
  • options.table.rowSpace: 两行之间的行距,默认为0行
  • options.table.colSpace: 两个单元格之间的间距,默认为4空格
  • options.table.titlePadding: 标题行左内补,默认为2空格

方法

render(text,options)

将标记文本渲染成可以在命令行正确显示的文本。

  • text: 要渲染的完整文本内容
  • options: 同选项,只对当前渲染有效

clean(text)

清除所有标记样式。

语法

所有语法标签都支持嵌套使用。

粗体

<b>some text</b>
[b]some text[/b]

斜体

<b>some text</b>
[b]some text[/b]

下划线

<u>some text</u>
[u]some text[/u]

弱化

<d>some text</d>
[d]some text[/d]

文本颜色

支持的颜色: black,red,green,yellow,blue,magenta,cyan,white,gray,redBright,greenBright,yellowBright,blueBright,magentaBright,cyanBright,whiteBright。

<red>some text</red>
<color red>some text</color>
[red]some text[/red]
[color=red]some text[/color]

背景颜色

<bgRed>some text</bgRed>
<bgColor red>some text</bgColor>
[bgRed]some text[/bgRed]
[bgColor=red]some text[/bgColor]

列表

* list item1
* list item2
* list item3

盒子

单边框

:----------------:
| some text      |
| some long text |
:----------------:

双边框

=================:
║ some text      ║
║ some long text ║
=================:

文本对齐

通过在左边或者右边添加:可以指定盒子内部文本的对齐方式。

表格

带表头表格

与markdown的表格一样,支持使用冒号定义单元格左右对齐方式。单元格的宽度是自动计算的,并不强行要求预先定义好。

title行是一个特殊的行,需要使用[]将标题文本内容包裹起来。

| Feature                             | Chrome   | Edge         | Firefox (Gecko)  | Internet Explorer            | Opera  | Safari |
| ----------------------------------- | :------: | :----------: | :--------------: | :--------------------------: | :----: | :----: |
| [title 1]                                                                                                                         |
| Basic support                       | 38       | 12<u>[1]</u> | 36 (36)          | <red><b>No support</b></red> | 25     | 9      |
| Symbol.iterator (@@iterator)        | 38       | 12           | 36 (36)          | <red><b>No support</b></red> | 25     | 9      |
| [title 2]                                                                                                                         |
| Symbol.unscopables (@@unscopables)  | 38       | 12           | 48 (48)          | <red><b>No support</b></red> | 25     | 9      |
| Symbol.species (@@species)          | 51       | ?            | 41 (41)          | <red><b>No support</b></red> | ?      | ?      |

无表头表格

暂不支持定义单元格左右对齐方式。

| [<b>title 1</b>]                                                                                                                         |
| Basic support                       | 38       | 12<u>[1]</u> | 36 (36)          | <red><b>No support</b></red> | 25     | 9      |
| Symbol.iterator (@@iterator)        | 38       | 12           | 36 (36)          | <red><b>No support</b></red> | 25     | 9      |
| [<b>title 2</b>]                                                                                                                         |
| Symbol.unscopables (@@unscopables)  | 38       | 12           | 48 (48)          | <red><b>No support</b></red> | 25     | 9      |
| Symbol.species (@@species)          | 51       | ?            | 41 (41)          | <red><b>No support</b></red> | ?      | ?      |

与chalk对比

  • chalk支持更多的颜色与样式定义

    chalk支持了一些只有在某些特定终端上才可以使用的特性,并在不兼容的时候做降级处理,cubb只实现了能够兼容所有终端的特性。

  • 使用方式不同

    相比chalk采用api的方式,标记语言的方式使用起来更加直观方便。

  • cubb支持listtable块的渲染

    chalk只处理纯文本的渲染,相对而言,cubb更适合用于大段内容的渲染。

致谢

在实现cubb框架过程中,参考了chalkmarked的部分代码,在此表示感谢!