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

@log-rush/log-formatter

v1.1.1

Published

Parse/Format/Style colored logs

Downloads

7

Readme

log-formatter

A javascript library for displaying color logs in the browser (by parsing and formatting SGR commands)!

Features

  • Parse SGR commands into an AST tree
  • convert logs into a styled html representation
  • remove ugly \x1b[35m statements from your logs
  • get an array of attribute an style the logs for your self

Installation

yarn add @log-rush/log-formatter

or

npm i @log-rush/log-formatter

Usage

Using the format() method direct:

import '@log-rush/log-formatter/dist/index.css';
import { LogFormat, LogFormatter, Optimization } from '@log-rush/log-formatter';

document.body.innerHtml = LogFormatter.format(
    '\x1b[1;32mHello \x1b[34mWorld\x1b[0m'
    LogFormat.ColoredHtml,
    Optimization.O2
)

or by creating a LogFormatter instance with the options:

import '@log-rush/log-formatter/dist/index.css';
import { LogFormat, LogFormatter, Optimization } from '@log-rush/log-formatter';

const formatter = new LogFormatter({
  format: LogFormat.ColoredHtml,
  optimizations: Optimization.O2,
});

document.body.innerHtml = formatter.format('\x1b[1;32mHello \x1b[34mWorld\x1b[0m')

Options

Format

LogFormat.ColoredHtml: a string containing styled html

Note: don't forget to import the "@log-rush/log-formatter/dist/index.css" stylesheet so that the all styles get applied

LogFormat.RawText: a string containing the raw text (excluding the sgr commands)

LogFormat.AttributesArray: an array containing chunks of content with the associated styles using the following format:

export type TextAttribute = {
    weight?: 'bold' | 'faint'
    italic?: true
    underline?: 'single' | 'double'
    foreground?: string
    background?: string
    blink?: 'slow' | 'rapid'
    inverted?: true
    crossedOut?: true
    concealed?: true
    content: string
}

Optimizations

Simply parsing the SGR commands may results in nodes with empty content or concatenated nodes with empty content or the same styles. This may results in a slight computation overhead (eg. rendering empty nodes or processing too much attributes). To solve this issue @log-rush/log-formatter comas with built-in optimizers:

Optimization.O1 will remove all nodes with empty content in a single pass (O(n) complexity)

Optimization.O2 will remove all nodes with empty content and merges nodes with the same attributes into a single node (O(n) complexity, but expensive attribute comparison)

Facts

@log-rush/log-formatter runs in O(n) time and space complexity