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

constructiv

v0.1.1

Published

Fast and lightweight terminal color styling library with chalk-like API

Downloads

8

Readme

yanse

Fast and lightweight terminal color styling library with a chalk-like API. Yanse (颜色, yánsè) means "color" in Chinese.

Why? We got tired of chalk's ESM-only errors and needed control over our dependencies. This utility is too simple to justify depending on chalk and wrestling with module: true.

Features

  • Fast & Lightweight - Zero dependencies, optimized for performance
  • Chalk-like API - Drop-in replacement for chalk with familiar syntax
  • TypeScript Support - Fully typed with comprehensive type definitions
  • Nested Colors - Proper handling of nested color styles without bugs
  • Chained Styles - Chain multiple colors and modifiers
  • Toggle Support - Easily enable/disable colors
  • Themes & Aliases - Create custom color themes and aliases

Install

npm install yanse

Usage

Basic Colors

import yanse, { red, green, blue, yellow, cyan } from 'yanse';

console.log(red('Error message'));
console.log(green('Success message'));
console.log(blue('Info message'));
console.log(yellow('Warning message'));
console.log(cyan('Debug message'));

Chained Colors

import yanse from 'yanse';

console.log(yanse.bold.red('Bold red text'));
console.log(yanse.bold.yellow.italic('Bold yellow italic text'));
console.log(yanse.green.bold.underline('Bold green underlined text'));

Nested Colors

import { yellow, red, cyan } from 'yanse';

console.log(yellow(`foo ${red.bold('red')} bar ${cyan('cyan')} baz`));

Logger Example

Perfect for building loggers with colored output:

import yanse, { cyan, yellow, red, green, bold } from 'yanse';

type LogLevel = 'info' | 'warn' | 'error' | 'debug' | 'success';

const levelColors: Record<LogLevel, typeof cyan> = {
  info: cyan,
  warn: yellow,
  error: red,
  debug: yanse.gray,
  success: green
};

class Logger {
  constructor(private scope: string) {}

  log(level: LogLevel, message: string) {
    const tag = bold(`[${this.scope}]`);
    const color = levelColors[level];
    const prefix = color(`${level.toUpperCase()}:`);

    console.log(`${tag} ${prefix} ${message}`);
  }
}

const logger = new Logger('MyApp');
logger.log('info', 'Application started');
logger.log('success', 'Connection established');
logger.log('warn', 'Deprecated API used');
logger.log('error', 'Failed to connect');

Available Styles

Colors

  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white
  • gray / grey

Background Colors

  • bgBlack
  • bgRed
  • bgGreen
  • bgYellow
  • bgBlue
  • bgMagenta
  • bgCyan
  • bgWhite

Bright Colors

  • blackBright, redBright, greenBright, yellowBright
  • blueBright, magentaBright, cyanBright, whiteBright

Bright Background Colors

  • bgBlackBright, bgRedBright, bgGreenBright, bgYellowBright
  • bgBlueBright, bgMagentaBright, bgCyanBright, bgWhiteBright

Style Modifiers

  • bold
  • dim
  • italic
  • underline
  • inverse
  • hidden
  • strikethrough
  • reset

Toggle Color Support

import yanse from 'yanse';

// Disable colors
yanse.enabled = false;
console.log(yanse.red('This will not be colored'));

// Re-enable colors
yanse.enabled = true;
console.log(yanse.red('This will be red'));

Strip ANSI Codes

import yanse from 'yanse';

const styled = yanse.blue.bold('Hello World');
console.log(yanse.unstyle(styled)); // 'Hello World'
console.log(yanse.stripColor(styled)); // 'Hello World' (alias)

Themes & Aliases

Create Aliases

import yanse from 'yanse';

yanse.alias('primary', yanse.blue);
yanse.alias('secondary', yanse.gray);

console.log(yanse.primary('Primary text'));
console.log(yanse.secondary('Secondary text'));

Create Themes

import yanse from 'yanse';

yanse.theme({
  danger: yanse.red,
  success: yanse.green,
  warning: yanse.yellow,
  info: yanse.cyan,
  primary: yanse.blue,
  muted: yanse.dim.gray
});

console.log(yanse.danger('Error occurred!'));
console.log(yanse.success('Operation successful!'));
console.log(yanse.warning('Be careful!'));

Create Custom Instances

import { create } from 'yanse';

const customYanse = create();
customYanse.enabled = false; // This instance has colors disabled

console.log(customYanse.red('Not colored'));

API

Properties

  • enabled: boolean - Enable/disable color output
  • visible: boolean - Make output visible/invisible
  • ansiRegex: RegExp - Regex for matching ANSI codes

Methods

  • hasColor(str: string): boolean - Check if string contains ANSI codes
  • hasAnsi(str: string): boolean - Alias for hasColor
  • unstyle(str: string): string - Remove ANSI codes from string
  • stripColor(str: string): string - Alias for unstyle
  • alias(name: string, color: YanseColor): void - Create color alias
  • theme(colors: Record<string, YanseColor>): void - Create color theme
  • create(): YanseColors - Create new yanse instance

Why Yanse?

  • Zero Dependencies - No external dependencies, minimal bundle size
  • Fast - Optimized for performance
  • Correct Nested Colors - Unlike some libraries, yanse correctly handles nested color styles
  • TypeScript First - Written in TypeScript with full type support
  • Familiar API - Drop-in replacement for chalk

Developing

When first cloning the repo:

pnpm install
pnpm build

Testing

pnpm test

Credits

Inspired by chalk and ansi-colors.