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 🙏

© 2025 – Pkg Stats / Ryan Hefner

style-log

v1.0.2

Published

這是用來產生有顏色 (樣式) 的 Log 訊息的模組

Downloads

4

Readme

style-log

這是用來產生有顏色 (樣式) 的 Log 訊息的模組

NPM

NPM

簡介

  • 使用 ES6 的語法
  • 可指定 log 函數
  • 可指定預設的樣式,以及串接訊息的字串

執行需求

  • node.js 版本 6.0.0 以上

安裝

npm install style-log --save

範例

let styleLog = require('style-log');
let gutil = require('gulp-util');
let colors = gutil.colors;

let log = new styleLog({
  log: gutil.log,
  pairJoin: ' => ',
  inlineJoin: ', ',
  labelStyle: colors.magenta,
  textStyle: colors.gray
});

let options = {labelStyle: colors.magenta, textStyle: colors.gray, inlineJoin: false};
let styleArrayItems = [['text1', options], 123];
let pairObjectItem = {key1: 'value1', key2: 'value2'};
let pairArrayItems = [['key1', 'value1', options], 123];

log.style('single text', colors.green);
log.styleArray(styleArrayItems, options);
log.pair('key', 'value', options);
log.pairArray(pairArrayItems, options);
log.pairObject(pairObjectItem, options);

參數

底下是創建 Log 實體時,可傳入的參數:

  • log function: 實際上執行 log 功能時的函數,預設值為 console.log

  • pairJoin string: 處理 Key-Value 訊息時,串接 Key 與 Value 間的字串,著色時不會有任何樣式,預設值為 :

  • inlineJoin string: 把多行訊息合併成一行時,串接多行訊息的字串,著色時不會有任何樣式,預設值為 ,

  • labelStyle function: 處理 Key-Value 訊息時,Key 的樣式函數,預設值為 (text) => '' + text

  • textStyle function: 預設的樣式函數,預設值為 (text) => '' + text

API

  • style(text = '', textStyle = this.options.textStyle, log = true)

    • text string: 要處理的字串
    • textStyle function: 字串的樣式函數
    • log boolean: 是否要進行 Log

    傳回值 string:著色完的字串

  • styleArray(items = [], options = {}, log = true)

    • items string[][]: 一個二維陣列,該陣列的內部元素可以是可丟進 style 處理的陣列;而其他的非陣列值會被當成字串來處理
    • options object: 請參考 參數 一節
    • log boolean: 是否要進行 Log

    傳回值 string[]:著色完後的字串陣列

  • pair(label = '', text = '', options = {}, log = true)

    • label string: 字串1
    • text string: 字串2
    • options object: 請參考 參數 一節
    • log boolean: 是否要進行 Log

    傳回值 string:著色完後的 字串1 + pairJoin + 字串2

  • pairArray(items = [], options = {}, log = true)

    • items string[][]: 一個二維陣列,該陣列的內部元素可以是可丟進 pair 處理的陣列;而其他的非陣列值會被當成字串來處理
    • options object: 請參考 參數 一節
    • log boolean: 是否要進行 Log

    傳回值 string[]:著色完後的字串陣列

  • pairObject(items = {}, options = {}, log = true)

    • items object: 一個 label : text 的物件,label 與 text 可丟進 pair 處理
    • options object: 請參考 參數 一節
    • log boolean: 是否要進行 Log

    傳回值 string[]:著色完後的字串陣列

備註

  • 有 options 參數的 API,會將傳入的 options 與創建時的 options 做結合運算,確定實際使用的參數。

  • 對於 styleArray、pairArray、pairObject 這幾個 API 來說,inlineJoin 還有另外一個額外的意義:

    • 如果 false == inlineJoin,在實際做 Log 時,會做多行輸出
    • 其他狀況會把訊息合併成一行輸出,但傳回值依然是字串陣列