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

repl-rainbow

v0.1.1

Published

A lib for easily translating and manipulating colors and sets of colors centered around xterm-256 pallette

Downloads

4

Readme

Repl-Rainbow

Hop aboard the rainbow. Have some colors. I found all existing libs out there either not adequate for my needs and usually lacking most of the tools I wanted.

Goals

  • provide easy translating between core color spaces of RGB and HSL and 256 color Ansi
  • translate from any one to any other with ease and terse syntax
  • provide baseline tools for generating sets of colors like gradients and nearest colors
  • transform arrays of colors at at a single time

Basic Usage

The api is designed to be very easy to use. The base exports is the Rainbow function which attempts to determine from given inputs what type of color you want.

var rainbow = require('repl-rainbow');

// explicit
rainbow('hsl', 180, 1, 0.5);

// guessing from numbers
rainbow(255,0,0); //rgb
rainbow(50) //ansi

// arrays work
rainbow([255,0,0]);

Detailed Usage

Aside from the main function there's also a direct function for each. They all have identical methods. RGB has an rgb method that returns itself, for example, for the sake of consistency.

The differences are:

  • rainbow.RGB has r, g, b
  • rainbow.HSL has h, s, l
  • rainbow.Ansi has code

The common api is:

  • rgb(): return an rgb instance for the color
  • hsl(): return an hsl instance for the color
  • ansi(): return an ansi instance for the color
  • hex(): return the HTML hex code for the color as rgb
  • closest(n): return the n closest colors, using that color space's rules
  • gradient(c,n): returns an array of n length with colors interpolating to c in that color space

A few bonus extras are avaiable on Ansi types

  • basic(bg): convert to the nearest of the basic 16 colors for downgradging. Set bg to true to get the bg escape
  • escape(text, type): escapes the text with the full ansi escape sequence for the color. Set bg to true for the bg escape

Arrays

The return type for operations that return sets is ColorSet. A ColorSet is just an array with a bit of extra functionality. All the Array functions that return new arrays are wrapped so that you always get back a ColorSet. This allows you to do multiple filters and mappings and still have a ColorSet.

  • hsl(): maps the ColorSet to another ColorSet where all the values have been converted to hsl's
  • rgb(): same for rgb
  • ansi(): same for ansi