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

colour-codes

v1.0.8

Published

Convert color codes from Rgba to Hex, Rgba to Hsl, Hex to Rgba, Hex to Hsl, Hsl to Rgba, Hsl to Hex

Downloads

48

Readme

colour-codes

colour-codes is an npm package that provides functions to convert color codes between different formats, including RGBA, HEX, HSLA, RGB, and HSL. With this package, you can easily perform color code conversions in your JavaScript/TypeScript projects.

Installation

You can install colour-codes using npm:

npm install colour-codes

Usage

import {
  rgbaToHex,
  rgbaToHsla,
  hexToHsla,
  hexToRgba,
  hslaToHex,
  hslaToRgba,
  rgbaToRgb,
  rgbToRgba,
  hslaToHsl,
  hslToHsla,
  ColourCode
} from 'colour-codes';

// Convert RGBA to HEX
const test1 = rgbaToHex('rgba(255, 255, 255, 1)');
console.log(test1); // Output: "#ffffff"

// Convert RGBA to HSLA
const test2 = rgbaToHsla('rgba(255, 255, 255, 0.5)');
console.log(test2); // Output: { type: "hsla", hue: 0, saturation: 0, lightness: 100, alpha: 0.5, hslaString: "hsla(0, 0%, 100%, 0.5)" }

// Convert HEX to HSLA
const test3 = hexToHsla('#f34fffed');
console.log(test3); // Output: { type: "hsla", hue: 308, saturation: 61, lightness: 74, alpha: 0.93, hslaString: "hsla(308, 61%, 74%, 0.93)" }

// Convert HEX to RGBA
const test4 = hexToRgba('#f34fffed');
console.log(test4); // Output: { type: "rgba", red: 243, green: 79, blue: 255, alpha: 0.93, rgbaString: "rgba(243, 79, 255, 0.93)" }

// Convert HSLA to HEX
const test5 = hslaToHex('hsla(300, 53%, 57%, 1)');
console.log(test5); // Output: "#9c4b6e"

// Convert HSLA to RGBA
const test6 = hslaToRgba('hsla(300, 53%, 57%, 1)').rgbaString;
console.log(test6); // Output: "rgba(156, 75, 110, 1)"

// Convert RGBA to RGB
const test7 = rgbaToRgb('rgba(255, 255, 255, 1)');
console.log(test7); // Output: { type: "rgb", red: 255, green: 255, blue: 255, rgbString: "rgb(255, 255, 255)" }

// Convert RGB to RGBA
const test8 = rgbToRgba('rgb(255, 255, 255)');
console.log(test8); // Output: { type: "rgba", red: 255, green: 255, blue: 255, alpha: 1, rgbaString: "rgba(255, 255, 255, 1)" }

// Convert HSLA to HSL
const test9 = hslaToHsl('hsla(300, 53%, 57%, 1)');
console.log(test9); // Output: { type: "hsl", hue: 300, saturation: 53, lightness: 57, hslString: "hsl(300, 53%, 57%)" }

// Convert HSL to HSLA
const test10 = hslToHsla('hsl(300, 53%, 57%)');
console.log(test10); // Output: { type: "hsla", hue: 300, saturation: 53, lightness: 57, alpha: 1, hslaString: "hsla(300, 53%, 57%, 1)" }

// Convert color to desired format using ColourCode function
const test11 = ColourCode('rgba(255, 255, 255, 1)', 'hsla');
console.log(test11); // Output: "hsla(0, 0%, 100%, 1)"

const test12 = ColourCode('#ffffff', 'hex');
console.log(test12); // Output: "#ffffff"

const test13 = ColourCode('rgba(255, 255, 255, 1)', 'rgba');
console.log(test13); // Output: "rgba(255, 255, 255, 1)"

const test14 = ColourCode('rgba(255, 255, 255, 1)', 'rgb');
console.log(test14); // Output: "rgb(255, 255, 255)"

const test15 = ColourCode('rgba(255, 255, 255, 1)', 'hsl');
console.log(test15); // Output: "hsl(0, 0%, 100%)"

API

The following functions are available in the colour-codes package:

  • rgbaToHex(colour): Converts an RGBA color code to a hexadecimal color code.
  • rgbaToHsla(colour): Converts an RGBA color code to an HSLA color code.
  • hexToHsla(hexColor): Converts a hexadecimal color code to an HSLA color code.
  • hslaToHex(hsla): Converts an HSLA color code to a hexadecimal color code.
  • hexToRgba(hexColor): Converts a hexadecimal color code to an RGBA color code.
  • hslaToRgba(hsla): Converts an HSLA color code to an RGBA color code.
  • rgbaToRgb(colour): Converts an RGBA color code to an RGB color code.
  • rgbToRgba(colour): Converts an RGB color code to an RGBA color code.
  • hslaToHsl(colour): Converts an HSLA color code to an HSL color code.
  • hslToHsla(colour): Converts an HSL color code to an HSLA color code.
  • ColourCode(colour, format): Converts a color code to the desired format.

License

This package is licensed under the MIT License. See the LICENSE file for more information.

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvement, please open an issue or submit a pull request on the GitHub repository.

Author

Bugs/Issues

If you encounter any bugs or have any specific issues with the package, please report them on the GitHub Issues page.


Feel free to modify the content further to match your project's specific use cases and requirements.