# colour-codes

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

Latest version **1.0.8** (published 2023-07-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install colour-codes
pnpm add colour-codes
yarn add colour-codes
bun add colour-codes
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score; declining downloads.

## Facts

| | |
|---|---|
| Version | 1.0.8 |
| Published | 2023-07-19 |
| First published | 2023-07-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 33.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Yug Bhanushali |
| Maintainers | yug03 |
| Keywords | color, codes, rgba, hex, hsl, convert, converter, colour, colour-codes, rgba-to-hex, rgba-to-hsl, hex-to-rgba, hex-to-hsl, hsl-to-rgba, hsl-to-hex |

## Links

- npm: https://www.npmjs.com/package/colour-codes
- Repository: https://github.com/YugBhanushali/color-codes-npm-package
- Issues: https://github.com/YugBhanushali/color-codes-npm-package/issues
- npm.io page: https://npm.io/package/colour-codes

## Alternatives

- [postcss-color-hex-alpha](https://npm.io/package/postcss-color-hex-alpha.md) — 6.4M weekly downloads
- [randomcolor](https://npm.io/package/randomcolor.md) — 348.0K weekly downloads
- [bows](https://npm.io/package/bows.md) — 1.3K weekly downloads
- [ep_prefer_color_scheme](https://npm.io/package/ep_prefer_color_scheme.md) — 260 weekly downloads
- [coc-yank](https://npm.io/package/coc-yank.md) — 61 weekly downloads

## Recent versions

- 1.0.8 (latest) — 2023-07-19
- 1.0.7 — 2023-07-19
- 1.0.3 — 2023-07-12
- 1.0.2 — 2023-07-12
- 1.0.1 — 2023-07-10
- 1.0.0 — 2023-07-10

## 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:

```shell
npm install colour-codes
```

## Usage

```javascript
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](./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](https://github.com/YugBhanushali/color-codes-npm-package).

## Author

- [Yug Bhanushali](https://github.com/YugBhanushali)

## Bugs/Issues

If you encounter any bugs or have any specific issues with the package, please report them on the [GitHub Issues](https://github.com/YugBhanushali/color-codes-npm-package/issues) page.
```

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

---
_Source: https://npm.io/package/colour-codes · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
