Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

font-color-contrast

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

font-color-contrast - npm Package Compare versions

Comparing version 9.0.0 to 9.0.1

2

package.json
{
"name": "font-color-contrast",
"version": "9.0.0",
"version": "9.0.1",
"description": "JavaScript module to use black or white font according to the given background color",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -5,3 +5,3 @@ # font-color-contrast

[![CI Pipeline](https://github.com/russoedu/font-color-contrast/actions/workflows/main.yml/badge.svg)](https://github.com/russoedu/font-color-contrast/actions/workflows/main.yml)
[![Build Status](https://scrutinizer-ci.com/g/russoedu/sequential-id-generator/badges/build.png?b=main)](https://scrutinizer-ci.com/g/russoedu/sequential-id-generator/build-status/main)
[![Build Status](https://scrutinizer-ci.com/g/russoedu/font-color-contrast/badges/build.png?b=main)](https://scrutinizer-ci.com/g/russoedu/font-color-contrast/build-status/main)
[![Coverage Status](https://coveralls.io/repos/github/russoedu/font-color-contrast/badge.svg?branch=ts)](https://coveralls.io/github/russoedu/font-color-contrast?branch=ts)

@@ -21,31 +21,63 @@ [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/russoedu/font-color-contrast/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/russoedu/font-color-contrast/?branch=master)

You can use the module 3 ways:
- with an hexadecimal string color, i.e. fontColor("#f7d4fc")
- with a RGB separated by comma color (number or string), i.e. fontColor(223, 0, "255")
- with a RGB array color (number or string), i.e. fontColor([223, 0, "255"])
- with a hexadecimal color (number or string), i.e. fontColor("#f7d4fc") or fontColor(0xf7d56a) or even fontColor(16242026)
- with an RGB separated by comma color (number), i.e. fontColor(223, 0, 255)
- with an RGB array color (number), i.e. fontColor([223, 0, 255])
If any other format is sent, the function will respond with white by default.
```Typescript
import fontColorContrast from 'font-color-contrast'
```javascript
var fontColorContrast = require('font-color-contrast');
const myStringBg = '#00CC99'
const fontColor = fontColorContrast(myStringBg) // '#000000'
var lightGreenBackground: "#b6e9be";
var paleYellowBackground = ["255", "246", "199"];
var darkBlueRedBackground = 20;
var darkBlueGreenBackground = 85;
var darkBlueBlueBackground = 91;
const myNumberBg = 0x00cc99
const fontColor = fontColorContrast(myNumberBg) // '#000000'
var fontColor1 = fontColorContrast(lightGreenBackground);
// fontColor will be a string for black hexadecimal color: "#000000"
const myRgbBg = {
red: 0,
green: 204,
blue: 153
}
const fontColor = fontColorContrast(myRgbBg.red, myRgbBg.green, myRgbBg.blue) // '#000000'
var fontColor2 = fontColorContrast(paleYellowBackground);
// fontColor will be a string for black hexadecimal color: "#000000"
const myArrayBg = [0, green: 204, blue: 153]
const fontColor = fontColorContrast(myArrayBg) // '#000000'
var fontColor3 = fontColorContrast(
darkBlueRedBackground,
darkBlueGreenBackground,
darkBlueBlueBackground
);
// fontColor will be a string for white hexadecimal color: "#ffffff"
```
The 4 possible overflows are described next:
```Typescript
/**
* @param hex The hex color number that must be a valid hexadecimal color number, with 6 characters, to work correctly
* @example fontColorContrast(0XF3DC56) === fontColorContrast(15981654)
*/
function fontColorContrast (hex: number): '#ffffff' | '#000000'
```
```Typescript
/**
* @param hex The hex color string that must be a valid hexadecima color number to work correctly. Works with or without '#', with 3 or 6 color chars
* @example fontColorContrast('00FFDD') === fontColorContrast('0FD') === fontColorContrast('#00FFDD') === fontColorContrast('#0FD')
*/
function fontColorContrast (hex: string): '#ffffff' | '#000000'
```
```Typescript
/**
* @param red The red portion of the color. Must be a number between 0 and 255
* @param green The green portion of the color. Must be a number between 0 and 255
* @param blue The blue portion of the color. Must be a number between 0 and 255
* @example fontColorContrast('00', 'F3', D8) === fontColorContrast(0, 243, 216) === fontColorContrast(0x0, 0xF3, 0xd8)
*/
function fontColorContrast (red: number, green: number, blue: number): '#ffffff' | '#000000'
```
```Typescript
/**
* @param redGreenBlue Array with red, green and blue. Each value must be a number between 0 and 255
* @example fontColorContrast(['00', 'F3', 'D8']) === fontColorContrast([0, 243, 216]) === fontColorContrast([0x0, 0xF3, 0xd8])
*/
function fontColorContrast (redGreenBlue: number[]): '#ffffff' | '#000000'
```
## Tests

@@ -52,0 +84,0 @@

@@ -62,3 +62,3 @@ const hashRegEx = /#/

/**
* Converts an hexadecimal string to it's correspondent integer
* Converts a hexadecimal string to it's correspondent integer
* @param hexString The hexadecimal string

@@ -65,0 +65,0 @@ * @returns The integer value

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc