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

tie-dye

v1.0.3

Published

A simple modular color converter.

Downloads

88

Readme

tie-dye

Although there are a bunch of color conversion libraries on npm, I couldn't find one where it was simple to just import the conversions you want. While importing a library is not a big deal in node, for the browser there is not reason to load a whole library of code you are not using. Normally I find I only need one conversion.

Current API

Hexadecimal to HSL
import hexToHsl from 'tie-dye/hexToHsl';

const paleCornflowerBlueHsl = hexToHsl('#ABCDEF');

console.log(paleCornflowerBlueHsl); // => { h: 210, s: 68, l: 80.3921568627451}
Hexadecimal to RGB
import hexToRgb from 'tie-dye/hexToRgb';

const paleCornflowerBlueRgb = hexToRgb('#ABCDEF');

console.log(paleCornflowerBlueRgb); // => { r: 171, g: 205, b: 239 }
RGB to Hexadecimal
import rgbToHex from 'tie-dye/rgbToHex';

const mintGreenHex = rgbToHex(152, 255, 152);

console.log(mintGreenHex); // => '#98FF98'
RGB to HSL
import rgbToHsl from 'tie-dye/rgbToHsl';

const dreamyRedHsl = rgbToHsl(139, 255, 138);

console.log(dreamyRedHsl); // => { h: 0, s: 70.13574660633485, l: 56.666666666666664 }
HSL to Hexadecimal
import hslToHex from 'tie-dye/hslToHex';

const mauveHex = hslToHex(276, 100, 85);

console.log(mauveHex); // => '#e0B3FF'
HSL to RGB
import hslToRgb from 'tie-dye/hslToRgb';

const foamGreenRgb = hslToRgb(96, 46, 59);

console.log(foamGreenRgb); // => { r: 140.83139999999997, g: 198.543, b: 102.35699999999997 }

Keeping it simple


In the spirit of keeping it unixy this library does not aim to round your results, or allow you to pass arguments with r g b / h s l properties, etc. If you wanna do that here are some really simple examples.

Passing objects with h s l properties
import hslToRgb from 'tie-dye/hslToRgb';

const hslObjectToRgb = obj => hslToRgb(obj.h, obj.s, obj.l);

const foamGreenHsl = {h: 96, s: 46, l: 59};

const foamGreenRgb = hslObjectToRgb(foamGreenHsl);

console.log(foamGreenRgb); // => { r: 140.83139999999997, g: 198.543, b: 102.35699999999997 }
Rounding results to two decimal places
import hslToRgb from 'tie-dye/hslToRgb';
import { mapValues } from 'lodash/fp';

const roundTo2Decimal = x => Math.round(x * 100) / 100;
const roundObject = mapValues(roundTo2Decimal);

const foamGreenRgb = roundObject(hslToRgb(96, 46, 59));

console.log(foamGreenRgb); // => { r: 140.83, g: 198.54, b: 102.36 }