src/index.ts   A
last analyzed

Complexity

Total Complexity 6
Complexity/F 1

Size

Lines of Code 53
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 18
mnd 0
bc 0
fnc 6
dl 0
loc 53
bpm 0
cpm 1
noi 0
c 0
b 0
f 0
rs 10

1 Function

Rating   Name   Duplication   Size   Complexity  
A index.ts ➔ fontColorContrast 0 9 1
1
import { CssColor } from './CssNamedColorsType'
2
import { FontColorContrast } from './FontColorContrast'
3
4
/**
5
 * Analyses the color (normally used in the background) and retrieves what color (black or white) has a better contrast.
6
 * @param cssColor The CSS named color string. The list of colors is defined as a TypeScript type to help the usage.
7
 * @param threshold Contrast threshold to control the resulting font color, float values from 0 to 1. Default is 0.5.
8
 * @example fontColorContrast('beige')
9
 * @example fontColorContrast('darkcyan', 0.3)
10
 */
11
function fontColorContrast (cssColor: CssColor, threshold?: number): '#ffffff'|'#000000'
12
13
/**
14
 * Analyses the color (normally used in the background) and retrieves what color (black or white) has a better contrast.
15
 * @param hex The hex color string must be a valid hexadecimal color number to work correctly. Works with or without '#', with 3 or 6 color chars. Any other length or an invalid hex character will be ignored. A space is allowed between the hash symbol and the number.
16
 * @param threshold Contrast threshold to control the resulting font color, float values from 0 to 1. Default is 0.5.
17
 * @example fontColorContrast('00FFDD') === fontColorContrast('0FD') === fontColorContrast('#00FFDD') === fontColorContrast('#0FD') === fontColorContrast('# 00FFDD') === fontColorContrast('# 0FD')
18
 */
19
function fontColorContrast (hex: string, threshold?: number): '#ffffff'|'#000000'
20
21
/**
22
 * Analyses the color (normally used in the background) and retrieves what color (black or white) has a better contrast.
23
 * @param hex The hex color number must be an integer between 0 and 0xffffff (16777215).
24
 * @param threshold Contrast threshold to control the resulting font color, float values from 0 to 1. Default is 0.5.
25
 * @example fontColorContrast(0XF3DC56) === fontColorContrast(15981654)
26
 */
27
function fontColorContrast (hex: number, threshold?: number): '#ffffff'|'#000000'
28
29
/**
30
 * Analyses the color (normally used in the background) and retrieves what color (black or white) has a better contrast.
31
 * @param red The red portion of the color. Must be an integer between 0 and 255.
32
 * @param green The green portion of the color. Must be an integer between 0 and 255.
33
 * @param blue The blue portion of the color. Must be an integer between 0 and 255.
34
 * @param threshold Contrast threshold to control the resulting font color, float values from 0 to 1. Default is 0.5.
35
 * @example fontColorContrast(0, 243, 216) === fontColorContrast(0x0, 0xF3, 0xd8).
36
 */
37
function fontColorContrast (red: number, green: number, blue: number, threshold?: number): '#ffffff'|'#000000'
38
39
/**
40
 * Analyses the color (normally used in the background) and retrieves what color (black or white) has a better contrast.
41
 * @param rgbArray Array with red, green and blue. Each value must be an integer between 0 and 255.
42
 * @param threshold Contrast threshold to control the resulting font color, float values from 0 to 1. Default is 0.5.
43
 * @example fontColorContrast(fontColorContrast([0, 243, 216]) === fontColorContrast([0x0, 0xF3, 0xd8])
44
 */
45
function fontColorContrast(rgbArray: number[], threshold?: number): '#ffffff'|'#000000'
46
47
function fontColorContrast (hexColorOrRedOrArray: string | number | number[], greenOrThreshold?: number, blue?: number, threshold?: number) {
48
  const fcc = new FontColorContrast(hexColorOrRedOrArray, greenOrThreshold, blue, threshold)
49
  return fcc.getColor()
50
}
51
52
export default fontColorContrast
53