color-2-name 1.2.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +12 -0
- package/.gitignore +1 -0
- package/babel.config.json +6 -0
- package/jest.config.json +21 -0
- package/lib/@types/color-utils.d.ts +8 -3
- package/lib/@types/common.d.ts +52 -20
- package/lib/@types/hex-utils.d.ts +8 -1
- package/lib/@types/hsl-utils.d.ts +15 -0
- package/lib/@types/index.d.ts +14 -13
- package/lib/@types/rgb-utils.d.ts +2 -1
- package/lib/@types/types.d.ts +1 -1
- package/lib/browser/color-2-name.js +509 -1
- package/lib/browser/color-2-name.js.map +4 -4
- package/lib/browser/color-2-name.min.js +2 -0
- package/lib/browser/color-2-name.min.js.map +7 -0
- package/lib/cjs/_virtual/_tslib.cjs +35 -0
- package/lib/cjs/_virtual/_tslib.cjs.map +1 -0
- package/lib/cjs/color-utils.cjs +38 -0
- package/lib/cjs/color-utils.cjs.map +1 -0
- package/lib/cjs/{@types/color-utils.d.ts → color-utils.d.ts} +8 -3
- package/lib/cjs/common.cjs +200 -0
- package/lib/cjs/common.cjs.map +1 -0
- package/lib/cjs/common.d.ts +93 -0
- package/lib/cjs/data/colorSet.cjs +148 -0
- package/lib/cjs/data/colorSet.cjs.map +1 -0
- package/lib/cjs/hex-utils.cjs +105 -0
- package/lib/cjs/hex-utils.cjs.map +1 -0
- package/lib/cjs/{@types/hex-utils.d.ts → hex-utils.d.ts} +8 -1
- package/lib/cjs/hsl-utils.cjs +140 -0
- package/lib/cjs/hsl-utils.cjs.map +1 -0
- package/lib/cjs/{@types/hsl-utils.d.ts → hsl-utils.d.ts} +15 -0
- package/lib/cjs/index.cjs +165 -0
- package/lib/cjs/index.cjs.map +1 -0
- package/lib/cjs/{@types/index.d.ts → index.d.ts} +14 -13
- package/lib/cjs/rgb-utils.cjs +58 -0
- package/lib/cjs/rgb-utils.cjs.map +1 -0
- package/lib/cjs/{@types/rgb-utils.d.ts → rgb-utils.d.ts} +2 -1
- package/lib/cjs/{@types/types.d.ts → types.d.ts} +1 -1
- package/lib/esm/_virtual/_tslib.mjs +35 -0
- package/lib/esm/_virtual/_tslib.mjs.map +1 -0
- package/lib/esm/color-utils.d.ts +18 -0
- package/lib/esm/color-utils.mjs +35 -0
- package/lib/esm/color-utils.mjs.map +1 -0
- package/lib/esm/common.d.ts +93 -0
- package/lib/esm/common.mjs +184 -0
- package/lib/esm/common.mjs.map +1 -0
- package/lib/esm/data/colorSet.d.ts +2 -0
- package/lib/esm/data/colorSet.mjs +146 -0
- package/lib/esm/data/colorSet.mjs.map +1 -0
- package/lib/esm/hex-utils.d.ts +47 -0
- package/lib/esm/hex-utils.mjs +98 -0
- package/lib/esm/hex-utils.mjs.map +1 -0
- package/lib/esm/hsl-utils.d.ts +47 -0
- package/lib/esm/hsl-utils.mjs +133 -0
- package/lib/esm/hsl-utils.mjs.map +1 -0
- package/lib/esm/index.d.ts +87 -0
- package/lib/esm/index.mjs +156 -0
- package/lib/esm/index.mjs.map +1 -0
- package/lib/esm/rgb-utils.d.ts +26 -0
- package/lib/esm/rgb-utils.mjs +53 -0
- package/lib/esm/rgb-utils.mjs.map +1 -0
- package/lib/esm/types.d.ts +37 -0
- package/lib/umd/color-2-name.js +820 -0
- package/lib/umd/color-2-name.min.js +1 -0
- package/lib/umd/color-utils.d.ts +18 -0
- package/lib/umd/common.d.ts +93 -0
- package/lib/umd/data/colorSet.d.ts +2 -0
- package/lib/umd/hex-utils.d.ts +47 -0
- package/lib/umd/hsl-utils.d.ts +47 -0
- package/lib/umd/index.d.ts +87 -0
- package/lib/umd/rgb-utils.d.ts +26 -0
- package/lib/umd/types.d.ts +37 -0
- package/package.json +37 -38
- package/readme.md +24 -36
- package/tests/colors_hex.test.ts +78 -0
- package/tests/colors_hsl.test.ts +57 -0
- package/tests/colors_rgb.test.ts +44 -0
- package/tests/{index.test.ts → core.test.ts} +54 -40
- package/tsconfig.json +3 -3
- package/.eslintrc.js +0 -11
- package/lib/cjs/@types/common.d.ts +0 -61
- package/lib/cjs/color-utils.js +0 -75
- package/lib/cjs/color-utils.js.map +0 -1
- package/lib/cjs/common.js +0 -134
- package/lib/cjs/common.js.map +0 -1
- package/lib/cjs/data/colorSet.js +0 -859
- package/lib/cjs/data/colorSet.js.map +0 -1
- package/lib/cjs/hex-utils.js +0 -59
- package/lib/cjs/hex-utils.js.map +0 -1
- package/lib/cjs/hsl-utils.js +0 -60
- package/lib/cjs/hsl-utils.js.map +0 -1
- package/lib/cjs/index.js +0 -129
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/rgb-utils.js +0 -45
- package/lib/cjs/rgb-utils.js.map +0 -1
- package/lib/cjs/types.js +0 -6
- package/lib/cjs/types.js.map +0 -1
- package/lib/esm/color-utils.js +0 -28
- package/lib/esm/common.js +0 -80
- package/lib/esm/data/colorSet.js +0 -848
- package/lib/esm/hex-utils.js +0 -32
- package/lib/esm/hsl-utils.js +0 -37
- package/lib/esm/index.js +0 -58
- package/lib/esm/rgb-utils.js +0 -24
- package/lib/esm/types.js +0 -1
- package/lib/umd/isoToLanguage.js +0 -1
- package/lib/umd/isoToLanguage.js.map +0 -1
- package/tests/benchmark.ts +0 -36
- package/tests/colors.test.ts +0 -204
- /package/lib/cjs/{@types/data → data}/colorSet.d.ts +0 -0
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"env": {
|
|
3
|
+
"browser": true,
|
|
4
|
+
"node": true,
|
|
5
|
+
"commonjs": true,
|
|
6
|
+
"es2021": true
|
|
7
|
+
},
|
|
8
|
+
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
|
|
9
|
+
"parser": "@typescript-eslint/parser",
|
|
10
|
+
"plugins": ["@typescript-eslint"],
|
|
11
|
+
"root": true
|
|
12
|
+
}
|
package/.gitignore
CHANGED
package/jest.config.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"testRegex": "(/tests/.*(test|spec))\\.tsx?$",
|
|
3
|
+
"globals": {
|
|
4
|
+
"ts-jest": {}
|
|
5
|
+
},
|
|
6
|
+
"transformIgnorePatterns": ["/node_modules/"],
|
|
7
|
+
"coverageThreshold": {
|
|
8
|
+
"global": {
|
|
9
|
+
"branches": 10,
|
|
10
|
+
"functions": 10,
|
|
11
|
+
"lines": 10,
|
|
12
|
+
"statements": 10
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"coverageReporters": ["text", "lcov"],
|
|
16
|
+
"coverageDirectory": "./tests/coverage",
|
|
17
|
+
"collectCoverageFrom": [
|
|
18
|
+
"./src/**/*.{js,jsx,ts,tsx}",
|
|
19
|
+
"!**/tests/**"
|
|
20
|
+
]
|
|
21
|
+
}
|
|
@@ -5,9 +5,14 @@ import { RGBCOLORDEF } from "./types";
|
|
|
5
5
|
* @param {string} searchedColor -the name of the color to search for
|
|
6
6
|
* @param {Array} set - the colorSet to search in
|
|
7
7
|
*/
|
|
8
|
-
declare function getColor(searchedColor: string, set?: RGBCOLORDEF[] | undefined): {
|
|
9
|
-
hex:
|
|
8
|
+
export declare function getColor(searchedColor: string, set?: RGBCOLORDEF[] | undefined): {
|
|
9
|
+
hex: string;
|
|
10
10
|
rgb: string;
|
|
11
11
|
hsl: string;
|
|
12
12
|
};
|
|
13
|
-
export
|
|
13
|
+
export declare function getColors(): {
|
|
14
|
+
hex: string;
|
|
15
|
+
rgb: string;
|
|
16
|
+
hsl: string;
|
|
17
|
+
name: string | number;
|
|
18
|
+
}[];
|
package/lib/@types/common.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RGBCOLORDEF
|
|
1
|
+
import { RGBCOLORDEF } from "./types";
|
|
2
2
|
/** The maximum distance possible between colors */
|
|
3
3
|
export declare const MAXDISTANCE = 441.6729559300637;
|
|
4
4
|
/** A regex to match hex colors */
|
|
@@ -7,16 +7,18 @@ export declare const hexRegex: RegExp;
|
|
|
7
7
|
export declare const rgbRegex: RegExp;
|
|
8
8
|
/** A regex to match hsl colors */
|
|
9
9
|
export declare const hslRegex: RegExp;
|
|
10
|
-
/** A regex to match strings that are only
|
|
10
|
+
/** A regex to match strings that are only valid numbers with and without decimals and the number can be negative and without the 0 in the beginning */
|
|
11
11
|
export declare const isNumeric: RegExp;
|
|
12
|
+
/** Remove comments from string */
|
|
13
|
+
export declare const stripComments: RegExp;
|
|
12
14
|
/**
|
|
13
|
-
* This set is used
|
|
15
|
+
* This set is used to detect if the color is bright or dark
|
|
14
16
|
*
|
|
15
17
|
* @note the set has been corrected to get pure RGB values (eg. pure red, pure green) in the "bright" area
|
|
16
18
|
*/
|
|
17
19
|
export declare const BLACKANDWHITE: RGBCOLORDEF[];
|
|
18
20
|
/**
|
|
19
|
-
* This set is used
|
|
21
|
+
* This set is used to detect the nearest rgb color
|
|
20
22
|
*/
|
|
21
23
|
export declare const RGBSET: RGBCOLORDEF[];
|
|
22
24
|
/**
|
|
@@ -26,36 +28,66 @@ export declare const RGBSET: RGBCOLORDEF[];
|
|
|
26
28
|
*
|
|
27
29
|
* @param {string} rawValues - the value inside the rgb(.*) css color definition
|
|
28
30
|
*
|
|
29
|
-
* @return {Array} the array of rgb values
|
|
31
|
+
* @return {Array} the array of rgb values found inside the passed string
|
|
30
32
|
*/
|
|
31
33
|
export declare function splitValues(rawValues: string): string[];
|
|
32
34
|
/**
|
|
33
35
|
* If the value is an angle in degrees, convert it to the 0-360 range
|
|
34
36
|
*
|
|
35
|
-
* @param {string}
|
|
36
|
-
* @param {number} multiplier - the number that represent the maximum - default is 100
|
|
37
|
+
* @param {string} angle - the degrees to convert into a number
|
|
37
38
|
*
|
|
38
39
|
* @return {number} the converted value
|
|
39
40
|
*/
|
|
40
|
-
export declare function
|
|
41
|
+
export declare function normalizeDegrees(angle: string): number;
|
|
41
42
|
/**
|
|
42
|
-
*
|
|
43
|
+
* Returns a value that is limited between a minimum and maximum value.
|
|
43
44
|
*
|
|
44
|
-
* @param {
|
|
45
|
-
* @param {
|
|
45
|
+
* @param {number} value - The value to be limited.
|
|
46
|
+
* @param {number} min - The minimum allowed value (default is 0).
|
|
47
|
+
* @param {number} max - The maximum allowed value (default is 0).
|
|
48
|
+
* @return {number} The limited value.
|
|
49
|
+
*/
|
|
50
|
+
export declare function limitValue(value: number, min?: number, max?: number): number;
|
|
51
|
+
/**
|
|
52
|
+
* Calculates the value based on a given string and multiplier.
|
|
46
53
|
*
|
|
47
|
-
* @
|
|
54
|
+
* @param {string} valueString - The string representing the value to be calculated.
|
|
55
|
+
* @param {number} multiplier - The multiplier to be applied to the calculated value.
|
|
56
|
+
* @return {number} The calculated value.
|
|
57
|
+
*/
|
|
58
|
+
export declare function calculateValue(valueString: string, multiplier: number): number;
|
|
59
|
+
/**
|
|
60
|
+
* Removes comments from the input string and extracts the content between the first opening parenthesis
|
|
61
|
+
* and the last closing parenthesis.
|
|
48
62
|
*
|
|
49
|
-
* @
|
|
63
|
+
* @param {string} string - The input string.
|
|
64
|
+
* @return {string} The content between the first opening parenthesis and the last closing parenthesis.
|
|
50
65
|
*/
|
|
51
|
-
export declare function
|
|
66
|
+
export declare function cleanDefinition(string: string): string;
|
|
52
67
|
/**
|
|
53
|
-
*
|
|
54
|
-
* If the color string matches one of these formats, the function returns an object with the type of color and the value of the color.
|
|
55
|
-
* If the color string does not match any of the formats, the function throws an error.
|
|
68
|
+
* Normalizes a percentage value by dividing it by 100 and multiplying it by a given multiplier.
|
|
56
69
|
*
|
|
57
|
-
* @param {string}
|
|
70
|
+
* @param {string} value - The percentage value to be normalized.
|
|
71
|
+
* @param {number} multiplier - The number to multiply the normalized percentage by.
|
|
72
|
+
* @return {number} The normalized percentage value.
|
|
73
|
+
*/
|
|
74
|
+
export declare function normalizePercentage(value: string, multiplier: number): number;
|
|
75
|
+
/**
|
|
76
|
+
* Calculates the color value fallbacks for a given value.
|
|
58
77
|
*
|
|
59
|
-
* @
|
|
78
|
+
* @param {string} value - The color value to calculate fallbacks for.
|
|
79
|
+
* @param {string} [err] - An optional error message to display.
|
|
80
|
+
* @return {number} - The calculated color value fallbacks.
|
|
60
81
|
*/
|
|
61
|
-
export declare function
|
|
82
|
+
export declare function colorValueFallbacks(value: string, err?: string): number;
|
|
83
|
+
/**
|
|
84
|
+
* Takes a string with a css value that could be a number or percentage or an angle in degrees and returns the corresponding 8bit value
|
|
85
|
+
*
|
|
86
|
+
* @param {string} value - a valid value for the css color definition (like 255, "100%", "324deg", etc.) *
|
|
87
|
+
* @param multiplier - the number that represent the maximum - default is 255 decimal - 100 hex
|
|
88
|
+
*
|
|
89
|
+
* @example convertToInt8('100%'); // 255
|
|
90
|
+
*
|
|
91
|
+
* @return {string} the corresponding value in 8-bit format
|
|
92
|
+
*/
|
|
93
|
+
export declare function convertToInt8(value: string, multiplier?: number): number;
|
|
@@ -6,6 +6,13 @@ import { COLORSTRING, HEX, RGBVALUE } from "./types";
|
|
|
6
6
|
* @return {string[]} 6 digit hex
|
|
7
7
|
*/
|
|
8
8
|
export declare function shortHexToLongHex(value: string): string[];
|
|
9
|
+
/**
|
|
10
|
+
* Checks if a given string represents a hexadecimal number.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} num - The string to be checked.
|
|
13
|
+
* @return {boolean} Returns true if the string is a valid hexadecimal number, false otherwise.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isHex(num: string): boolean;
|
|
9
16
|
/**
|
|
10
17
|
* Get the hex value of the color and convert it to an Object of R G And B values (still in hex format)
|
|
11
18
|
*
|
|
@@ -17,7 +24,7 @@ export declare function parseHex(value: COLORSTRING): string[];
|
|
|
17
24
|
/**
|
|
18
25
|
* Converts a Hex color to rgb
|
|
19
26
|
*
|
|
20
|
-
* @param {string} hex
|
|
27
|
+
* @param {string} hex a tuple of hex values
|
|
21
28
|
*
|
|
22
29
|
* @return {string} the rgb color values for the given hex color
|
|
23
30
|
*/
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { HSLVALUE, RGBVALUE } from "./types";
|
|
2
|
+
export declare function fallbackHSL(hsl: string[], err?: string): string[];
|
|
2
3
|
/**
|
|
3
4
|
* Get the values of the hsl string
|
|
4
5
|
*
|
|
@@ -30,3 +31,17 @@ export declare function hslToRgb(hslColor: string[]): RGBVALUE;
|
|
|
30
31
|
* @return {Object} hsl value
|
|
31
32
|
*/
|
|
32
33
|
export declare function valuesToHsl({ r, g, b }: RGBVALUE): string;
|
|
34
|
+
/**
|
|
35
|
+
* Converts an HSL color object to a string representation.
|
|
36
|
+
*
|
|
37
|
+
* @param {Object} hsl - Object containing the HSL color values.
|
|
38
|
+
* @param {number} hsl.h - The hue value of the color.
|
|
39
|
+
* @param {number} hsl.s - The saturation value of the color.
|
|
40
|
+
* @param {number} hsl.l - The lightness value of the color.
|
|
41
|
+
* @return {string} The HSL color as a string.
|
|
42
|
+
*/
|
|
43
|
+
export declare function HSL(hsl: {
|
|
44
|
+
h: number;
|
|
45
|
+
s: number;
|
|
46
|
+
l: number;
|
|
47
|
+
}): string;
|
package/lib/@types/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { COLORDEF, COLORSTRING, HEX, RGBCOLORDEF } from "./types";
|
|
1
|
+
import type { COLORDEF, COLORSTRING, HEX, RGBCOLORDEF, RGBVALUE } from "./types";
|
|
2
|
+
import { getColor, getColors } from "./color-utils";
|
|
2
3
|
/**
|
|
3
|
-
* Given a color string it returns the closest corresponding name of the color.
|
|
4
|
+
* Given a color string, it returns the closest corresponding name of the color.
|
|
4
5
|
* Uses the Euclidean distance formula to calculate the distance between colors in the RGB color space.
|
|
5
6
|
*
|
|
6
7
|
* @param {string} color - the color string you want to find the closest color name
|
|
@@ -38,16 +39,6 @@ declare function isLight(color: string): boolean;
|
|
|
38
39
|
* @example isDark('#333'); // true
|
|
39
40
|
*/
|
|
40
41
|
declare function isDark(color: string): boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Given a color returns if the color is light or dark (by dark is meant more mathematically closer to black)
|
|
43
|
-
*
|
|
44
|
-
* @param {string} color - The color to check
|
|
45
|
-
*
|
|
46
|
-
* @returns {string} light when the color is close to white, dark otherwise
|
|
47
|
-
*
|
|
48
|
-
* @example isLightOrDark('#fff'); // 'light'
|
|
49
|
-
*/
|
|
50
|
-
declare function isLightOrDark(color: string): string;
|
|
51
42
|
/**
|
|
52
43
|
* Given a color returns if the color is closer to "red", "green" or "blue".
|
|
53
44
|
*
|
|
@@ -83,4 +74,14 @@ declare function distance(rgb1: [number, number, number], rgb2: [number, number,
|
|
|
83
74
|
* @example rgbToHex("rgba(100% 0 0 / .5)"); // #FF0000
|
|
84
75
|
*/
|
|
85
76
|
declare function rgbToHex(rgbString: string): HEX | Error;
|
|
86
|
-
|
|
77
|
+
/**
|
|
78
|
+
* This function takes a string representing a color (color) and uses regular expressions to check if it matches any of the following formats: hex, hex+alpha, RGB, RGBA, HSL, or HSLA.
|
|
79
|
+
* If the color string matches one of these formats, the function returns an object with the type of color and the value of the color.
|
|
80
|
+
* If the color string does not match any of the formats, the function throws an error.
|
|
81
|
+
*
|
|
82
|
+
* @param {string} colorString - the color string to test and convert to rgb values
|
|
83
|
+
*
|
|
84
|
+
* @return {Object|Error} the object with rgb values of that color
|
|
85
|
+
*/
|
|
86
|
+
export declare function parseColor(colorString: string): RGBVALUE;
|
|
87
|
+
export { closest, rgbToHex, distance, isLight, isDark, closestRGB, getColor, getColors };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RGBVALUE } from "./types";
|
|
2
|
+
export declare function fallbackRGB(rgb: string[], err?: string): string[];
|
|
2
3
|
/**
|
|
3
4
|
* Get the values of the rgb string
|
|
4
5
|
*
|
|
@@ -22,4 +23,4 @@ export declare function getRgbValues(rgb: string[]): RGBVALUE;
|
|
|
22
23
|
*
|
|
23
24
|
* @return {string} a string representation of the rgb values
|
|
24
25
|
*/
|
|
25
|
-
export declare function
|
|
26
|
+
export declare function RGB(rgb: RGBVALUE): string;
|
package/lib/@types/types.d.ts
CHANGED