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

chalk-log-plus

v0.0.1

Published

A friendly terminal log output library based on chalk encapsulation

Downloads

2

Readme

Github Stars Chalk Version license Author

English

为什么要开发这玩意儿

因为我在给一个express项目添加日志输出的时候,发现如果直接使用chalk,会导致代码重复片段过多,并且有些多余。所以我就简简单单的封装了一个库。

怎么食用

安装chalk (版本低于且不是5)

chalk在版本5后不再支持在nodejs中require()导入,所以选择使用版本4的chalk。未来将会考虑适配版本5以后的chalk

npm install --save chalk@4

调用ChalkLog

  1. 首先下载该项目并置于你的项目中

  2. 然后调用这个库

const log = require("./chalk-log")

代码使用

log是一个class类,包括以下函数

  • add
  • output

初始化

const clog = new log();

初始化时,可以考虑加入前缀,ChalkLog有以下前缀预设

  • info
  • error
  • success
  • connect

例如

// 对大小写并不敏感
const clog = new log("info");

如果这些前缀预设无法满足你,你还可以自己定义chalk样式

// 以下代码都相当于设置了“chalk.rgb(0,0,0).bold”样式

// 1
const chalk = require("chalk");
const clog = new log(chalk.rgb(0,0,0).bold,"text");

// 2
const clog = new log("rgb(0,0,0).bold","text");

// 3
const clog = new log([ "rgb(0,0,0)","bold" ],"text");

add()函数可以追加输出

如果你只需要输出内容,而不需要字体样式搭配,你只需要传入一个参数:输出的内容

clog.add("infomations")

输出的内容。否则,你需要传入两个参数

第一个参数可以为预设颜色名字,ChalkLog提供了以下颜色预设 (preset_color)

  • host
  • error

如同初始化的时候一样,如果预设颜色无法满足你,你也可以自己定义,方式与初始化的时候一样

第二个参数则是输出的内容

最后,只有调用output()时才会输出内容

clog.output();

在使用output()输出后,您仍可以使用add()继续追加内容,并再次用output()输出

简写支持

这段代码

const clog = new log("rgb(0,0,0).bold","text");
clog.add("infomations")
clog.output();

可以简写成这样

new log("rgb(0,0,0).bold","text").add("infomations").output();

需要注意的是,如果采用简写的方法,在使用output()输出后,你无法使用add()继续追加内容,也无法使用output()输出

书写注意

  1. 在传入非chalk函数的自定义样式时,你不需要太过于注意书写方法(例如当需要粗体时,“bold”与“bold()”都是可以的)