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

style-logger

v1.1.0

Published

logs to stdout or a stream optionaly using styles passed by the consumer

Downloads

4

Readme

style-logger

A very basic, isomorphic logger that accepts a style function object that can be used to provide colour output to stdout using ANSI escape sequences in node or CSS style fomatting foe console.log.

Usage

npm install style-logger

StyleLogger([{WriteStream}[, {object}]]) optionaly takes a stream and a style functions object and returns a logger

Builds a logger complex including the provided styles and returns a customisable, logger complex including customisation methods. If no write stream is provided it will log to stdout.

    const StyleLogger  = require('style-logger')
    
    function logger(logStream) {
    
        var ESC = '\x1b[', gEND = "m", allOFF = `${ESC}0m`, BOLD = 1, ITALIC = 3, UNDERLINE = 4, IMAGENEGATIVE = 7, FONTDEFAULT = 10, FONT2 = 11, FONT3 = 12, FONT4 = 13, FONT5 = 14, FONT6 = 15, IMAGEPOSITIVE = 27, BLACK = 30, RED = 31, GREEN = 32, YELLOW = 33, BLUE = 34, MAGENTA = 35, CYAN = 36, WHITE = 37, BG_BLACK = 40, BG_RED = 41, BG_GREEN = 42, BG_YELLOW = 43, BG_BLUE = 44, BG_MAGENTA = 45, BG_CYAN = 46, BG_WHITE = 47, CLEAR_SCREEN = `${ESC}2J`;
    
        var ansiStyles = {
            h1: (m, s, e) => `${ESC}${BOLD};${RED}m${m}${allOFF}`,
            h2: (m, s, e) => `${ESC}${BOLD};${BLUE}m${m}${allOFF}`,
            h3: (m, s, e) => `${ESC}${BOLD};${YELLOW}m${m}${allOFF}`
        };
        var cssRed = '#c04848', cssBlue = '#07c', cssYellow = '#ead10e';
        var cssStyles = {
            h1: (m) => [`%c${m}`, `font-weight: bold; color: ${cssRed}`],
            h2: (m) => [`%c${m}`, `font-weight: bold; color: ${cssBlue}`],
            h3: (m) => [`%c${m}`, `font-weight: bold; color: ${cssYellow}`]
        };
    
        return StyleLogger(
            logStream,
            typeof window !== 'undefined' ? cssStyles : ansiStyles,
            {isStart: /.*start/i, isEnd: /.*end/i}
        )
    
    }
     
    // If a logStream is not provided, logs to stdout
    var log = logger();
   
    // returns styled logs...
    log.h1(_message_)
    log.h2(_message_)
    log.h3(_message_)
    
    // or default vanilla
    log(_message_)
    
    // with or without escape sequences (for non-TTY output)
    log.plain();
    log.fancy();
    
    // enable or dissable
    log.om();
    log.off();
    
    // apply a transform to the message before it is wrapped
    log.transform(m => timeStamp() + '\t' + m)
    
    // provide a callback for async operation
    log.h1(_message_, done)  // will call back after write is completed
    
    // also provides events for finnish and errors
    log.onfinish(() => console.log("finished writing to " + this.path || "stdout");
    log.onerror((e) => console.log("error writing to " + this.path || "stdout\n" + e.message);