# colorize-foreground

> Validate a hexadecimal value, Convert hexadecimal to HSL, determine if the colour needs a light or dark foreground.

Latest version **1.0.2** (published 2019-08-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install colorize-foreground
pnpm add colorize-foreground
yarn add colorize-foreground
bun add colorize-foreground
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2019-08-09 |
| First published | 2019-08-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Austin Paquette |
| Maintainers | austinpaquette |

## Links

- npm: https://www.npmjs.com/package/colorize-foreground
- Repository: https://github.com/pqt/colorize-foreground
- Homepage: https://github.com/pqt/colorize-foreground#readme
- Issues: https://github.com/pqt/colorize-foreground/issues
- npm.io page: https://npm.io/package/colorize-foreground

## Recent versions

- 1.0.2 (latest) — 2019-08-09
- 1.0.1 — 2019-08-09
- 1.0.0 — 2019-08-09
- 0.0.1 — 2019-08-04
- 0.0.0 — 2019-08-04

## README

# Colorize Foreground

Validate a hexadecimal value, Convert hexadecimal to HSL, determine if the colour needs a light or dark foreground.

## Installation

```bash
npm i colorize-foreground --save
```

```bash
yarn add colorize-foreground
```

## Usage

```js
import { colorizeForeground } from "colorize-foreground";
// OR
const { colorizeForeground } = require("colorize-foreground");

// could be "fff" | "#fff" | "ffffff" | "#ffffff"
const backgroundColor = "#fff";

// value becomes: { color: "000000", type: "dark" }
const foregroundColor = colorizeForeground(backgroundColor);
```

## Functions

| function                | parameter: type                  | returns         |
| ----------------------- | -------------------------------- | --------------- |
| removeHash              | color: string                    | string          |
| expandHexadecimal       | color: string                    | string          |
| parseHexadecimal        | color: string                    | RegExpExecArray |
| isValidHexadecimal      | color: string                    | boolean         |
| convertHexadecimalToHSL | color: string                    | number[]        |
| colorizeForeground      | color: string, threshold: number | object          |

## Parameters Insight

The `color` parameter should be a valid hexidecimal code, either with or without the hash. All functions remove the hash immediately and any hexidecimal values returned will be without it. So be conscious of that.

The `threshold` parameter in the `colorizeForeground` function starts at 75. This is the "lightness" of the passed color (in HSL format). If the lightness of the color is **greater than** the threshold, a dark color suggestion will be made. If the lightness is **equal to or less than** the allowed threshold a light color suggestion will be returned instead.

## Validations and Errors

When using any of the functions, the hexidecimal value is validated and stripped of the hash (#). The validation process accepts most accepted forms for a color hex code. This includes both shorthand and full length.

Validation is **case-insensitive**.

**Validation Passing Formats**

```
fff
#fff
ffffff
#ffffff
```

Validation of new-era hexidecimal is not _yet_ supported or on the roadmap since it is very seldom used. If you'd like to see it though feel free to post an issue and I'll revisit this opinion there.

## License

MIT

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