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

hagen

v2.0.2

Published

A colorful logger for JS in Node and the Browser

Downloads

324

Readme

Hagen

A colorful logger for JS/TS in Node and modern Browsers.

Getting Started

Installation

npm i hagen or yarn add hagen

Usage

Hagen extends console.log, console.warn, and console.error. It takes two parameters: a string label and a message.

The label's color is chosen randomly from a list of terminal colors by analyzing the string. The color will remain the same every time you use the same label. You can additionally pass in an integer as a third parameter to manually select the color.

The library is written in TypeScript, so types are available for autocomplete/Intellisense in both JS and TS.

Importing

hagen is exported as both a CommonJS and ESM module. You can import it in your project like this:

Node (TypeScript via ts-node or tsc)
import hagen from "hagen";
Node (JavaScript)
const hagen = require("hagen").default;
Browser (Webpack/Parcel or frameworks like Next.js)
import hagen from "hagen";
Browser (Dev bundlers like Vite)
import hagen from "hagen";

Vite also needs to be configured with the following in vite.config.js to handle CommonJS modules:

import { defineConfig } from "vite";
import { viteCommonjs } from "@originjs/vite-plugin-commonjs"; // <-- install this with `npm i @originjs/vite-plugin-commonjs`

export default defineConfig({
	plugins: [viteCommonjs()],
	define: {
		"process.env": process.env,
	},
});

Commands

hagen.log("LABEL", "Hello, World!"); // normal log
hagen.info("LABEL", "This is some unimportant info."); // info log
hagen.success("LABEL", "You did it!"); // success log
hagen.warn("LABEL", "Something happened!"); // warning log
hagen.error("LABEL", "This is bad."); // error log

hagen.info("", "This is a blank label."); // just the message, no label
hagen.log("LABEL"); // just the label, no message

hagen.log("LABEL", { hello: "world", how: "are you?" }); // object log
hagen.log("LABEL", "Hello, World!", 3); // custom color

// grouping
console.group();
hagen.log(`LEVEL 1`);
console.group();
hagen.log(`LEVEL 2`);
console.groupEnd();
console.groupEnd();

VSCode

In recent versions of VSCode the default minimum color-contrast ratio is set to 4.5; sometimes VSCode will automatically change the color of the label text to meet this requirement.

To disable this, set "terminal.integrated.minimumContrastRatio": 1, in settings.json.

Major Technologies

Inspirations

Authors

License

MIT © John Mars