colorizr 2.1.1 → 3.0.0-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.
Files changed (291) hide show
  1. package/README.md +487 -153
  2. package/dist/index.d.mts +450 -0
  3. package/dist/index.d.ts +450 -0
  4. package/dist/index.js +1627 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/index.mjs +1551 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/package.json +56 -38
  9. package/src/brightness-difference.ts +18 -11
  10. package/src/chroma.ts +8 -5
  11. package/src/color-difference.ts +9 -7
  12. package/src/colorizr.ts +214 -0
  13. package/src/compare.ts +10 -7
  14. package/src/contrast.ts +10 -7
  15. package/src/convert.ts +12 -0
  16. package/src/converters/hex2hsl.ts +14 -0
  17. package/src/converters/hex2oklab.ts +14 -0
  18. package/src/converters/hex2oklch.ts +14 -0
  19. package/src/converters/hex2rgb.ts +19 -0
  20. package/src/converters/hsl2hex.ts +12 -0
  21. package/src/converters/hsl2oklab.ts +12 -0
  22. package/src/converters/hsl2oklch.ts +12 -0
  23. package/src/{hsl2rgb.ts → converters/hsl2rgb.ts} +9 -12
  24. package/src/converters/index.ts +24 -0
  25. package/src/converters/oklab2hex.ts +12 -0
  26. package/src/converters/oklab2hsl.ts +12 -0
  27. package/src/converters/oklab2oklch.ts +20 -0
  28. package/src/converters/oklab2rgb.ts +36 -0
  29. package/src/converters/oklch2hex.ts +12 -0
  30. package/src/converters/oklch2hsl.ts +12 -0
  31. package/src/converters/oklch2oklab.ts +26 -0
  32. package/src/converters/oklch2rgb.ts +12 -0
  33. package/src/converters/rgb2hex.ts +12 -0
  34. package/src/{rgb2hsl.ts → converters/rgb2hsl.ts} +9 -15
  35. package/src/converters/rgb2oklab.ts +34 -0
  36. package/src/converters/rgb2oklch.ts +12 -0
  37. package/src/darken.ts +5 -3
  38. package/src/desaturate.ts +5 -3
  39. package/src/extract-color-parts.ts +57 -0
  40. package/src/format-css.ts +83 -21
  41. package/src/format-hex.ts +15 -11
  42. package/src/index.ts +35 -191
  43. package/src/invert.ts +20 -0
  44. package/src/is-valid-color.ts +2 -2
  45. package/src/lighten.ts +5 -3
  46. package/src/luminance.ts +8 -5
  47. package/src/modules/constants.ts +46 -0
  48. package/src/modules/css-colors.ts +8 -5
  49. package/src/modules/hex-utils.ts +69 -0
  50. package/src/modules/hue2rgb.ts +3 -1
  51. package/src/modules/invariant.ts +22 -0
  52. package/src/modules/parse-color.ts +58 -38
  53. package/src/modules/updater.ts +24 -12
  54. package/src/modules/utils.ts +137 -187
  55. package/src/modules/validators.ts +169 -0
  56. package/src/name.ts +13 -6
  57. package/src/opacify.ts +21 -0
  58. package/src/opacity.ts +25 -0
  59. package/src/palette.ts +32 -14
  60. package/src/parse-css.ts +118 -62
  61. package/src/random.ts +4 -3
  62. package/src/rotate.ts +21 -11
  63. package/src/saturate.ts +5 -3
  64. package/src/scheme.ts +42 -15
  65. package/src/swatch.ts +106 -0
  66. package/src/text-color.ts +32 -7
  67. package/src/transparentize.ts +25 -0
  68. package/src/types/index.ts +59 -41
  69. package/esm/brightness-difference.d.ts +0 -4
  70. package/esm/brightness-difference.js +0 -16
  71. package/esm/brightness-difference.js.map +0 -1
  72. package/esm/chroma.d.ts +0 -4
  73. package/esm/chroma.js +0 -14
  74. package/esm/chroma.js.map +0 -1
  75. package/esm/color-difference.d.ts +0 -4
  76. package/esm/color-difference.js +0 -17
  77. package/esm/color-difference.js.map +0 -1
  78. package/esm/compare.d.ts +0 -5
  79. package/esm/compare.js +0 -36
  80. package/esm/compare.js.map +0 -1
  81. package/esm/contrast.d.ts +0 -4
  82. package/esm/contrast.js +0 -16
  83. package/esm/contrast.js.map +0 -1
  84. package/esm/darken.d.ts +0 -4
  85. package/esm/darken.js +0 -8
  86. package/esm/darken.js.map +0 -1
  87. package/esm/desaturate.d.ts +0 -4
  88. package/esm/desaturate.js +0 -8
  89. package/esm/desaturate.js.map +0 -1
  90. package/esm/fade.d.ts +0 -5
  91. package/esm/fade.js +0 -23
  92. package/esm/fade.js.map +0 -1
  93. package/esm/format-css.d.ts +0 -2
  94. package/esm/format-css.js +0 -27
  95. package/esm/format-css.js.map +0 -1
  96. package/esm/format-hex.d.ts +0 -1
  97. package/esm/format-hex.js +0 -17
  98. package/esm/format-hex.js.map +0 -1
  99. package/esm/hex2hsl.d.ts +0 -2
  100. package/esm/hex2hsl.js +0 -8
  101. package/esm/hex2hsl.js.map +0 -1
  102. package/esm/hex2rgb.d.ts +0 -2
  103. package/esm/hex2rgb.js +0 -12
  104. package/esm/hex2rgb.js.map +0 -1
  105. package/esm/hsl2hex.d.ts +0 -5
  106. package/esm/hsl2hex.js +0 -11
  107. package/esm/hsl2hex.js.map +0 -1
  108. package/esm/hsl2rgb.d.ts +0 -5
  109. package/esm/hsl2rgb.js +0 -35
  110. package/esm/hsl2rgb.js.map +0 -1
  111. package/esm/index.d.ts +0 -110
  112. package/esm/index.js +0 -167
  113. package/esm/index.js.map +0 -1
  114. package/esm/is-valid-color.d.ts +0 -1
  115. package/esm/is-valid-color.js +0 -11
  116. package/esm/is-valid-color.js.map +0 -1
  117. package/esm/is-valid-hex.d.ts +0 -1
  118. package/esm/is-valid-hex.js +0 -11
  119. package/esm/is-valid-hex.js.map +0 -1
  120. package/esm/lighten.d.ts +0 -4
  121. package/esm/lighten.js +0 -8
  122. package/esm/lighten.js.map +0 -1
  123. package/esm/luminance.d.ts +0 -4
  124. package/esm/luminance.js +0 -21
  125. package/esm/luminance.js.map +0 -1
  126. package/esm/modules/css-colors.d.ts +0 -152
  127. package/esm/modules/css-colors.js +0 -153
  128. package/esm/modules/css-colors.js.map +0 -1
  129. package/esm/modules/hue2rgb.d.ts +0 -4
  130. package/esm/modules/hue2rgb.js +0 -25
  131. package/esm/modules/hue2rgb.js.map +0 -1
  132. package/esm/modules/parse-color.d.ts +0 -2
  133. package/esm/modules/parse-color.js +0 -56
  134. package/esm/modules/parse-color.js.map +0 -1
  135. package/esm/modules/updater.d.ts +0 -4
  136. package/esm/modules/updater.js +0 -19
  137. package/esm/modules/updater.js.map +0 -1
  138. package/esm/modules/utils.d.ts +0 -61
  139. package/esm/modules/utils.js +0 -199
  140. package/esm/modules/utils.js.map +0 -1
  141. package/esm/name.d.ts +0 -1
  142. package/esm/name.js +0 -10
  143. package/esm/name.js.map +0 -1
  144. package/esm/palette.d.ts +0 -2
  145. package/esm/palette.js +0 -32
  146. package/esm/palette.js.map +0 -1
  147. package/esm/parse-css.d.ts +0 -5
  148. package/esm/parse-css.js +0 -78
  149. package/esm/parse-css.js.map +0 -1
  150. package/esm/random.d.ts +0 -4
  151. package/esm/random.js +0 -13
  152. package/esm/random.js.map +0 -1
  153. package/esm/rgb2hex.d.ts +0 -5
  154. package/esm/rgb2hex.js +0 -20
  155. package/esm/rgb2hex.js.map +0 -1
  156. package/esm/rgb2hsl.d.ts +0 -2
  157. package/esm/rgb2hsl.js +0 -51
  158. package/esm/rgb2hsl.js.map +0 -1
  159. package/esm/rotate.d.ts +0 -4
  160. package/esm/rotate.js +0 -17
  161. package/esm/rotate.js.map +0 -1
  162. package/esm/saturate.d.ts +0 -4
  163. package/esm/saturate.js +0 -8
  164. package/esm/saturate.js.map +0 -1
  165. package/esm/scheme.d.ts +0 -5
  166. package/esm/scheme.js +0 -44
  167. package/esm/scheme.js.map +0 -1
  168. package/esm/shift.d.ts +0 -5
  169. package/esm/shift.js +0 -13
  170. package/esm/shift.js.map +0 -1
  171. package/esm/text-color.d.ts +0 -4
  172. package/esm/text-color.js +0 -13
  173. package/esm/text-color.js.map +0 -1
  174. package/esm/types/index.d.ts +0 -46
  175. package/esm/types/index.js +0 -2
  176. package/esm/types/index.js.map +0 -1
  177. package/lib/brightness-difference.d.ts +0 -4
  178. package/lib/brightness-difference.js +0 -19
  179. package/lib/brightness-difference.js.map +0 -1
  180. package/lib/chroma.d.ts +0 -4
  181. package/lib/chroma.js +0 -17
  182. package/lib/chroma.js.map +0 -1
  183. package/lib/color-difference.d.ts +0 -4
  184. package/lib/color-difference.js +0 -20
  185. package/lib/color-difference.js.map +0 -1
  186. package/lib/compare.d.ts +0 -5
  187. package/lib/compare.js +0 -39
  188. package/lib/compare.js.map +0 -1
  189. package/lib/contrast.d.ts +0 -4
  190. package/lib/contrast.js +0 -19
  191. package/lib/contrast.js.map +0 -1
  192. package/lib/darken.d.ts +0 -4
  193. package/lib/darken.js +0 -11
  194. package/lib/darken.js.map +0 -1
  195. package/lib/desaturate.d.ts +0 -4
  196. package/lib/desaturate.js +0 -11
  197. package/lib/desaturate.js.map +0 -1
  198. package/lib/fade.d.ts +0 -5
  199. package/lib/fade.js +0 -26
  200. package/lib/fade.js.map +0 -1
  201. package/lib/format-css.d.ts +0 -2
  202. package/lib/format-css.js +0 -30
  203. package/lib/format-css.js.map +0 -1
  204. package/lib/format-hex.d.ts +0 -1
  205. package/lib/format-hex.js +0 -20
  206. package/lib/format-hex.js.map +0 -1
  207. package/lib/hex2hsl.d.ts +0 -2
  208. package/lib/hex2hsl.js +0 -11
  209. package/lib/hex2hsl.js.map +0 -1
  210. package/lib/hex2rgb.d.ts +0 -2
  211. package/lib/hex2rgb.js +0 -15
  212. package/lib/hex2rgb.js.map +0 -1
  213. package/lib/hsl2hex.d.ts +0 -5
  214. package/lib/hsl2hex.js +0 -14
  215. package/lib/hsl2hex.js.map +0 -1
  216. package/lib/hsl2rgb.d.ts +0 -5
  217. package/lib/hsl2rgb.js +0 -38
  218. package/lib/hsl2rgb.js.map +0 -1
  219. package/lib/index.d.ts +0 -110
  220. package/lib/index.js +0 -212
  221. package/lib/index.js.map +0 -1
  222. package/lib/is-valid-color.d.ts +0 -1
  223. package/lib/is-valid-color.js +0 -14
  224. package/lib/is-valid-color.js.map +0 -1
  225. package/lib/is-valid-hex.d.ts +0 -1
  226. package/lib/is-valid-hex.js +0 -14
  227. package/lib/is-valid-hex.js.map +0 -1
  228. package/lib/lighten.d.ts +0 -4
  229. package/lib/lighten.js +0 -11
  230. package/lib/lighten.js.map +0 -1
  231. package/lib/luminance.d.ts +0 -4
  232. package/lib/luminance.js +0 -24
  233. package/lib/luminance.js.map +0 -1
  234. package/lib/modules/css-colors.d.ts +0 -152
  235. package/lib/modules/css-colors.js +0 -156
  236. package/lib/modules/css-colors.js.map +0 -1
  237. package/lib/modules/hue2rgb.d.ts +0 -4
  238. package/lib/modules/hue2rgb.js +0 -28
  239. package/lib/modules/hue2rgb.js.map +0 -1
  240. package/lib/modules/parse-color.d.ts +0 -2
  241. package/lib/modules/parse-color.js +0 -59
  242. package/lib/modules/parse-color.js.map +0 -1
  243. package/lib/modules/updater.d.ts +0 -4
  244. package/lib/modules/updater.js +0 -22
  245. package/lib/modules/updater.js.map +0 -1
  246. package/lib/modules/utils.d.ts +0 -61
  247. package/lib/modules/utils.js +0 -215
  248. package/lib/modules/utils.js.map +0 -1
  249. package/lib/name.d.ts +0 -1
  250. package/lib/name.js +0 -13
  251. package/lib/name.js.map +0 -1
  252. package/lib/palette.d.ts +0 -2
  253. package/lib/palette.js +0 -35
  254. package/lib/palette.js.map +0 -1
  255. package/lib/parse-css.d.ts +0 -5
  256. package/lib/parse-css.js +0 -81
  257. package/lib/parse-css.js.map +0 -1
  258. package/lib/random.d.ts +0 -4
  259. package/lib/random.js +0 -16
  260. package/lib/random.js.map +0 -1
  261. package/lib/rgb2hex.d.ts +0 -5
  262. package/lib/rgb2hex.js +0 -23
  263. package/lib/rgb2hex.js.map +0 -1
  264. package/lib/rgb2hsl.d.ts +0 -2
  265. package/lib/rgb2hsl.js +0 -54
  266. package/lib/rgb2hsl.js.map +0 -1
  267. package/lib/rotate.d.ts +0 -4
  268. package/lib/rotate.js +0 -20
  269. package/lib/rotate.js.map +0 -1
  270. package/lib/saturate.d.ts +0 -4
  271. package/lib/saturate.js +0 -11
  272. package/lib/saturate.js.map +0 -1
  273. package/lib/scheme.d.ts +0 -5
  274. package/lib/scheme.js +0 -47
  275. package/lib/scheme.js.map +0 -1
  276. package/lib/shift.d.ts +0 -5
  277. package/lib/shift.js +0 -17
  278. package/lib/shift.js.map +0 -1
  279. package/lib/text-color.d.ts +0 -4
  280. package/lib/text-color.js +0 -16
  281. package/lib/text-color.js.map +0 -1
  282. package/lib/types/index.d.ts +0 -46
  283. package/lib/types/index.js +0 -3
  284. package/lib/types/index.js.map +0 -1
  285. package/src/fade.ts +0 -30
  286. package/src/hex2hsl.ts +0 -10
  287. package/src/hex2rgb.ts +0 -15
  288. package/src/hsl2hex.ts +0 -13
  289. package/src/is-valid-hex.ts +0 -13
  290. package/src/rgb2hex.ts +0 -24
  291. package/src/shift.ts +0 -15
package/README.md CHANGED
@@ -1,14 +1,14 @@
1
1
  # Colorizr
2
2
 
3
- [![NPM version](https://badge.fury.io/js/colorizr.svg)](https://www.npmjs.com/package/colorizr) [![npm bundle size](https://img.shields.io/bundlephobia/minzip/colorizr)](https://bundlephobia.com/result?p=colorizr) [![CI](https://github.com/gilbarbara/colorizr/actions/workflows/main.yml/badge.svg)](https://github.com/gilbarbara/colorizr/actions/workflows/main.yml) [![Maintainability](https://api.codeclimate.com/v1/badges/6d686ce2a9f2a1a47d98/maintainability)](https://codeclimate.com/github/gilbarbara/colorizr/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/6d686ce2a9f2a1a47d98/test_coverage)](https://codeclimate.com/github/gilbarbara/colorizr/test_coverage)
3
+ [![NPM version](https://badge.fury.io/js/colorizr.svg)](https://www.npmjs.com/package/colorizr) [![npm bundle size](https://img.shields.io/bundlephobia/minzip/colorizr)](https://bundlephobia.com/result?p=colorizr) [![CI](https://github.com/gilbarbara/colorizr/actions/workflows/main.yml/badge.svg)](https://github.com/gilbarbara/colorizr/actions/workflows/main.yml) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=gilbarbara_colorizr&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=gilbarbara_colorizr) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=gilbarbara_colorizr&metric=coverage)](https://sonarcloud.io/summary/new_code?id=gilbarbara_colorizr)
4
4
 
5
- Color conversion, manipulation, comparison, and analysis.
5
+ Color conversion, generation, manipulation, comparison, and analysis.
6
6
 
7
7
  ## Highlights
8
8
 
9
- - 🏖 **Easy to use**: Works with HSL and RGB, including CSS strings
9
+ - 🏖 **Easy to use**: Works with Hex, HSL, OkLab, OkLCH, and RGB.
10
10
  - ♿️ **Accessibility:** WCAG analysis and comparison.
11
- - 🛠 **Small:** Less than 6k (gzipped) and zero dependencies.
11
+ - 🛠 **Small:** Less than 7k (gzipped) and tree-shakable.
12
12
  - 🟦 **Modern:** Written in Typescript.
13
13
 
14
14
  ## Setup
@@ -16,40 +16,47 @@ Color conversion, manipulation, comparison, and analysis.
16
16
  **Install**
17
17
 
18
18
  ```bash
19
- npm install --save colorizr
19
+ npm i colorizr
20
20
  ```
21
21
 
22
22
  ## Usage
23
23
 
24
+ You can use all the functions standalone:
25
+
24
26
  ```typescript
25
27
  import { luminance } from 'colorizr';
26
28
 
27
29
  const lux = luminance('#ff0044'); // 0.2168
28
30
  ```
29
31
 
30
- Or you can create an instance to access all methods:
32
+ Or you can create an instance to use all the methods for the same color:
31
33
 
32
34
  ```typescript
33
35
  import Colorizr from 'Colorizr';
34
36
 
35
- const colorizr = new Colorizr('#ff0044');
37
+ const colorInstance = new Colorizr('#ff0044');
38
+ colorInstance.luminance; // 0.2168
39
+ colorInstance.chroma; // 1
40
+ colorInstance.opacity; // 1
36
41
  ```
37
42
 
38
- ## Methods
43
+ ## API
39
44
 
40
- > String inputs accept css values: hex, rgb(a), hsl(a) and named colors.
45
+ > String inputs accept css values: hex, hsl, oklab, oklch, rgb, and named colors.
41
46
 
42
- **brightnessDifference(left: string, right: string): number**
43
- _get the brightness difference between 2 colors_
47
+ - [Info](#Info)
48
+ - [Manipulators](#Manipulators)
49
+ - [Converters](#Converters)
50
+ - [Generators](#Generators)
51
+ - [Comparison](#Comparison)
52
+ - [Utilities](#Utilities)
53
+ - [Validators](#Validators)
54
+ - [Class](#Class)
44
55
 
45
- ```typescript
46
- import { brightnessDifference } from 'colorizr';
47
-
48
- brightnessDifference('#fff', 'rgb(255, 0, 68)'); // 171.003
49
- ```
56
+ ### Info
50
57
 
51
58
  **chroma(input: string): number**
52
- _get the chroma of a color_
59
+ Get the chroma of a color.
53
60
 
54
61
  ```typescript
55
62
  import { chroma } from 'colorizr';
@@ -58,24 +65,148 @@ chroma('#ff0044'); // 1
58
65
  chroma('#ffc0cb'); // 0.2471
59
66
  ```
60
67
 
68
+ **luminance(input: string): number**
69
+ Get the relative brightness according to the [WCAG definition](https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef).
70
+ Normalized to `0` for black and `1` for white.
71
+
72
+ ```typescript
73
+ import { luminance } from 'colorizr';
74
+
75
+ luminance('#ff0044'); // 0.2168
76
+ ```
77
+
78
+ **name(input: string): string**
79
+ Get the name of a color. Return the hex code if it can't be named.
80
+
81
+ ```typescript
82
+ import { name } from 'colorizr';
83
+
84
+ name('#ffc0cb'); // pink
85
+ name('rgb(176 224 230)'); // 'powderblue'
86
+ name('hsl(344 100 50)'); // #ff0044
87
+ ```
88
+
89
+ **opacity(input: string): string**
90
+ Get the opacity of a color.
91
+
92
+ ```typescript
93
+ import { opacity } from 'colorizr';
94
+
95
+ opacity('#ff0044'); // 1
96
+ opacity('rgb(255 0 68 / 90%)'); // 0.9
97
+ opacity('hsl(344 100 50 / 60%)'); // 0.6
98
+ ```
99
+
100
+ ### Manipulators
101
+
102
+ **lighten(input: string, amount: number): string**
103
+ Get a color with increased lightness.
104
+
105
+ ```typescript
106
+ import { lighten } from 'colorizr';
107
+
108
+ lighten('#ff0044', 10); // #ff3369
109
+ lighten('hsl(136 100% 50%)', 10); // hsl(136 100% 60%)
110
+ ```
111
+
112
+ **darken(input: string, amount: number): string**
113
+ Get a color with decreased lightness.
114
+
115
+ ```typescript
116
+ import { darken } from 'colorizr';
117
+
118
+ darken('#ff0044', 10); // #cc0036
119
+ darken('oklch(47.642% 0.29956 274.93693)', 10); // oklch(40.377% 0.25281 275.46794)
120
+ ```
121
+
122
+ **saturate(input: string, amount: number): string**
123
+ Get a color with increased saturation.
124
+
125
+ ```typescript
126
+ import { saturate } from 'colorizr';
127
+
128
+ saturate('#ff0044', 10); // #ff0044 (already at the maximum)
129
+ saturate('pink', 10); // #ffc0cb
130
+ ```
131
+
132
+ **desaturate(input: string, alpha: number): string**
133
+ Get a color with decreased saturation.
134
+
135
+ ```typescript
136
+ import { desaturate } from 'colorizr';
137
+
138
+ desaturate('#ff0044', 10); // #f20d4a
139
+ desaturate('oklab(70.622% 0.1374 0.14283)', 10); // oklab(69.021% 0.12176 0.13721)
140
+ ```
141
+
142
+ **invert(input: string): string**
143
+ Invert the color.
144
+
145
+ ```typescript
146
+ import { invert } from 'colorizr';
147
+
148
+ invert('#07e'); // '#0077ee'
149
+ invert('#f058'); // '#ff005588'
150
+ ```
151
+
152
+ **rotate(input: string, degrees: number): string**
153
+ Get a color with a hue rotated by the specified degrees.
154
+
155
+ ```typescript
156
+ import { rotate } from 'colorizr';
157
+
158
+ rotate('#ff0044', 30); // #ff3b00
159
+ ```
160
+
161
+ **opacify(input: string, alpha: number, format?: ColorType): string**
162
+ Add opacity to a color
163
+
164
+ ```typescript
165
+ import { opacify } from 'colorizr';
166
+
167
+ opacify('hsl(344, 100, 50)', 0.9); // hsl(344 100 50 / 90%)
168
+ opacify('#ff0044', 0.8); // #ff0044cc
169
+ ```
170
+
171
+ **transparentize(input: string, alpha: number, format?: ColorType): string**
172
+ Increase/decrease the color opacity.
173
+
174
+ ```typescript
175
+ import { transparentize } from 'colorizr';
176
+
177
+ transparentize('hsl(344, 100, 50)', 10); // hsl(344 100 50 / 90%)
178
+ transparentize('#ff0044', 50, 'hsl'); // #ff004480
179
+ ```
180
+
181
+ ### Comparison
182
+
183
+ **brightnessDifference(left: string, right: string): number**
184
+ Get the brightness difference between the two colors.
185
+
186
+ ```typescript
187
+ import { brightnessDifference } from 'colorizr';
188
+
189
+ brightnessDifference('#fff', 'rgb(255, 0, 68)'); // 171.003
190
+ ```
191
+
61
192
  **colorDifference(left: string, right: string): number**
62
- _get the color difference between 2 colors_
193
+ Get the color difference between the two colors.
63
194
 
64
195
  ```typescript
65
196
  import { colorDifference } from 'colorizr';
66
197
 
67
- colorDifference('hsl(0, 0%, 100%)', '#f04'); // 442
198
+ colorDifference('hsl(0 0% 100%)', '#f04'); // 442
68
199
  ```
69
200
 
70
201
  **compare(left: string, right: string): Analysis**
71
- _get the WCAG analysis for two colors_
202
+ Get the WCAG analysis between two colors.
72
203
 
73
204
  ```typescript
74
205
  import { compare } from 'colorizr';
75
206
 
76
207
  compare('#ff0044', '#fff');
77
208
 
78
- {
209
+ ({
79
210
  "brightnessDifference": 171.003,
80
211
  "colorDifference": 442,
81
212
  "compliant": 1,
@@ -84,77 +215,105 @@ compare('#ff0044', '#fff');
84
215
  "largeAAA": false,
85
216
  "normalAA": false,
86
217
  "normalAAA": false,
87
- }
218
+ })
88
219
  ```
89
220
 
90
221
  **contrast(left: string, right: string): number**
91
- _get the WCAG contrast ratio between 2 colors_
222
+ Get the WCAG contrast ratio between two colors.
92
223
 
93
224
  ```typescript
94
225
  import { contrast } from 'colorizr';
95
226
 
96
- contrast('hsl(0, 0%, 100%)', 'rgb(255, 0, 68)'); // 3.94
227
+ contrast('hsl(0 0% 100%)', 'rgb(255 0 68)'); // 3.94
97
228
  ```
229
+ ### Generators
98
230
 
99
- **darken(input: string, amount = 10): string**
100
- _get a color with decreased lightness_
231
+ **palette(input: string, options?: PaletteOptions): string[]**
232
+ Generate a palette of colors.
101
233
 
102
234
  ```typescript
103
- import { darken } from 'colorizr';
235
+ import { palette } from 'colorizr';
104
236
 
105
- darken('#ff0044', 10); // #cc0036
237
+ palette('#ff0044');
238
+ // ['#ff0044', '#ff7700', '#88ff00', '#00ff77', '#0088ff', '#7700ff'];
239
+
240
+ palette('#ff0044', { type: 'monochromatic' });
241
+ // ['#ff99b4', '#ff5582', '#ff1150', '#cc0036', '#880024', '#440012']
106
242
  ```
107
243
 
108
- **desaturate(input: string, amount: number): string**
109
- _get a color with decreased saturation_
244
+ **scheme(input: string, type: Scheme): string[]**
245
+ Get a color scheme.
110
246
 
111
247
  ```typescript
112
- import { desaturate } from 'colorizr';
248
+ import { scheme } from 'colorizr';
113
249
 
114
- desaturate('#ff0044', 10); // #f20d4a
250
+ const complementary = scheme('rgb(255 0 68)'); // ['#ff0044', '#00ffbb']
251
+ const triadic = scheme('#ff0044', 'triadic'); // ['#ff0044', '#44ff00', '#0044ff']
115
252
  ```
116
253
 
117
- **fade(input: string, amount: number = 10, output?: ColorTypes = 'rgb'): string**
118
- _get a transparent color_
254
+ **swatch(input: string, variant?: 'up' | 'down'): string[]**
255
+ Generate a color swatch with ten shades.
256
+ The `variant` can be used to generate a lighter or darker swatch.
119
257
 
120
258
  ```typescript
121
- import { fade } from 'colorizr';
259
+ import { swatch } from 'colorizr';
122
260
 
123
- fade('hsl(344, 100, 50)', 10); // rgba(255, 0, 68, 0.9)
124
- fade('#ff0044', 50, 'hsl'); // hsla(344, 100%, 50%, 0.5)
261
+ const colors = swatch('#ff0044');
262
+ /* [
263
+ "#ffccda",
264
+ "#ff99b4",
265
+ "#ff668f",
266
+ "#ff3369",
267
+ "#ff0044",
268
+ "#cc0036",
269
+ "#990029",
270
+ "#66001b",
271
+ "#33000e",
272
+ "#1a0007",
273
+ ] */
125
274
  ```
126
275
 
127
- **formatCSS(input: HSL | RGB, options?: FormatOptions): string**
128
- _get the css string for a color model object_
276
+ ### Converters
277
+
278
+ **convert(input: string, format: ColorType): string**
279
+ Convert a color string to another format.
129
280
 
130
281
  ```typescript
131
- import { formatCSS } from 'colorizr';
282
+ import { convert } from 'colorizr';
132
283
 
133
- formatCSS({ h: 344, s: 100, l: 50 }, { model: 'rgb' }); // 'rgb(255, 0, 68)'
134
- formatCSS({ r: 255, g: 0, b: 68 }, { alpha: 0.5, model: 'hsl' }); // 'hsla(344, 100%, 50%, 0.5)'
284
+ convert('#ff0044', 'hsl') // hsl(344 100% 50%)
285
+ convert('rgb(255 0 68)', 'oklch') // oklch(63.269% 0.25404 19.90218)
135
286
  ```
136
287
 
137
- **formatHex(input: string): string**
138
- _format a short hex string of 3 (or 4) digits into 6 (or 8) digits._
288
+ **hex2hsl(input: string): HSL**
289
+ Convert HEX to HSL.
139
290
 
140
291
  ```typescript
141
- import { formatHex } from 'colorizr';
292
+ import { hex2hsl } from 'colorizr';
142
293
 
143
- formatHex('#07e'); // '#0077ee'
144
- formatHex('#f058'); // '#ff005588'
294
+ hex2hsl('#ff0044'); // { h: 344, s: 100, l: 50 }
145
295
  ```
146
296
 
147
- **hex2hsl(input: string): HSL**
148
- _convert a hex string into an HSL object_
297
+ **hex2oklab(input: string, precision?: number): LAB**
298
+ Convert HEX to OKLAB.
149
299
 
150
300
  ```typescript
151
- import { hex2hsl } from 'colorizr';
301
+ import { hex2oklab } from 'colorizr';
152
302
 
153
- hex2hsl('#ff0044'); // { h: 344, s: 100, l: 50 }
303
+ hex2oklab('#ff0044'); // { l: 0.63269, a: 0.23887, b: 0.08648 }
304
+ ```
305
+
306
+ **hex2oklch(input: string, precision?: number): LCH**
307
+ Convert HEX to OKLCH.
308
+
309
+ ```typescript
310
+ import { hex2oklch } from 'colorizr';
311
+
312
+ hex2oklch('#ff0044'); // { l: 0.63269, c: 0.25404, h: 19.90218 }
154
313
  ```
155
314
 
156
315
  **hex2rgb(input: string): RGB**
157
- _convert a hex string into an RGB object_
316
+ Convert HEX to RGB.
158
317
 
159
318
  ```typescript
160
319
  import { hex2rgb } from 'colorizr';
@@ -162,161 +321,261 @@ import { hex2rgb } from 'colorizr';
162
321
  hex2rgb('#ff0044'); // { r: 255, g: 0, b: 68 }
163
322
  ```
164
323
 
165
- **hsl2hex(input: HSL): string**
166
- _convert an HSL object into a hex string_
324
+ **hsl2hex(input: HSL | ColorTuple): string**
325
+ Convert HSL to HEX.
167
326
 
168
327
  ```typescript
169
328
  import { hsl2hex } from 'colorizr';
170
329
 
171
330
  hsl2hex({ h: 344, s: 100, l: 50 }); // '#ff0044'
331
+ hsl2hex([344, 100, 50]); // '#ff0044'
332
+ ```
333
+
334
+ **hsl2oklab(input: HSL | ColorTuple, precision?: number): LAB**
335
+ Convert HSL to OKLAB.
336
+
337
+ ```typescript
338
+ import { hsl2oklab } from 'colorizr';
339
+
340
+ hsl2oklab({ h: 344, s: 100, l: 50 }); // { l: 0.63269, a: 0.23887, b: 0.08648 }
341
+ hsl2oklab([344, 100, 50]); // { l: 0.63269, a: 0.23887, b: 0.08648 }
342
+ ```
343
+
344
+ **hsl2oklch(input: HSL | ColorTuple, precision?: number): LCH**
345
+ Convert HSL to OKLCH.
346
+
347
+ ```typescript
348
+ import { hsl2oklch } from 'colorizr';
349
+
350
+ hsl2oklch({ h: 344, s: 100, l: 50 }); // { l: 0.63269, c: 0.25404, h: 19.90218 }
351
+ hsl2oklch([344, 100, 50]); // { l: 0.63269, c: 0.25404, h: 19.90218 }
172
352
  ```
173
353
 
174
- **hsl2rgb(input: HSL): RGB**
175
- _convert an HSL object into an RGB object_
354
+ **hsl2rgb(input: HSL | ColorTuple): RGB**
355
+ Convert HSL to RGB.
176
356
 
177
357
  ```typescript
178
358
  import { hsl2rgb } from 'colorizr';
179
359
 
180
360
  hsl2rgb({ h: 344, s: 100, l: 50 }); // { r: 255, g: 0, b: 68 }
361
+ hsl2rgb([344, 100, 50]); // { r: 255, g: 0, b: 68 }
181
362
  ```
182
363
 
183
- **isValidColor(input: any): boolean**
184
- _check if the input can be parsed correctly_
364
+ **oklab2hex(input: LAB | ColorTuple): string**
365
+ Convert OKLAB to HEX.
185
366
 
186
367
  ```typescript
187
- import { isValidColor } from 'colorizr';
368
+ import { oklab2hex } from 'colorizr';
188
369
 
189
- isValidColor('#f04'); // true
190
- isValidColor('#ff0044'); // true
191
- isValidColor('#ff004400'); // true
192
- isValidColor('rgb(100, 255, 0)'); // true
193
- isValidColor('hsla(344, 100%, 50%)'); // true
194
- isValidColor('blue'); // true
195
- isValidColor('aliceblue'); // true
196
- isValidColor('#mmff00'); // false
197
- isValidColor('blue-ish'); // false
370
+ oklab2hex({ l: 0.63269, a: 0.23887, b: 0.08648 }); // '#ff0044'
371
+ oklab2hex([0.63269, 0.23887, 0.08648]); // '#ff0044'
198
372
  ```
199
373
 
200
- **isValidHex(input: any): boolean**
201
- _check if the input is a valid hex_
374
+ **oklab2hsl(input: LAB | ColorTuple): HSL**
375
+ Convert OKLAB to HSL.
202
376
 
203
377
  ```typescript
204
- import { isValidHex } from 'colorizr';
378
+ import { oklab2hsl } from 'colorizr';
205
379
 
206
- isValidHex('#f04'); // true
380
+ oklab2hsl({ l: 0.63269, a: 0.23887, b: 0.08648 }); // { h: 344, s: 100, l: 50 }
381
+ oklab2hsl([0.63269, 0.23887, 0.08648]); // { h: 344, s: 100, l: 50 }
207
382
  ```
208
383
 
209
- **lighten(input: string, amount: number): string**
210
- _get a color with increased lightness_
384
+ **oklab2oklch(input: LAB | ColorTuple, precision?: number): LCH**
385
+ Convert OKLAB to OKLCH.
211
386
 
212
387
  ```typescript
213
- import { lighten } from 'colorizr';
388
+ import { oklab2oklch } from 'colorizr';
214
389
 
215
- lighten('#ff0044', 10); // #ff3369
390
+ oklab2oklch({ l: 0.63269, a: 0.23887, b: 0.08648 }); // { l: 0.63269, c: 0.25404, h: 19.90218 }
391
+ oklab2oklch([0.63269, 0.23887, 0.08648]); // { l: 0.63269, c: 0.25404, h: 19.90218 }
216
392
  ```
217
393
 
218
- **luminance(input: string): number**
219
- _get the relative brightness according to the [WCAG definition](https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef). Normalized to `0` for black and `1` for white._
394
+ **oklab2rgb(input: LAB | ColorTuple, precision: number = 0): RGB**
395
+ Convert OKLAB to RGB.
220
396
 
221
397
  ```typescript
222
- import { luminance } from 'colorizr';
398
+ import { oklab2rgb } from 'colorizr';
223
399
 
224
- luminance('#ff0044'); // 0.2168
400
+ oklab2rgb({ l: 0.63269, a: 0.23887, b: 0.08648 }); // { r: 255, g: 0, b: 68 }
401
+ oklab2rgb([0.63269, 0.23887, 0.08648]); // { r: 255, g: 0, b: 68 }
225
402
  ```
226
403
 
227
- **name(input: string): string**
228
- _get the named color. return the hex code if it can't be named_
404
+ **oklch2hex(input: LCH | ColorTuple): string**
405
+ Convert OKLCH to HEX.
229
406
 
230
407
  ```typescript
231
- import { name } from 'colorizr';
408
+ import { oklch2hex } from 'colorizr';
232
409
 
233
- name('#ffc0cb', 10); // pink
234
- name('rgb(176, 224, 230)'); // 'powderblue'
235
- name('hsl(344, 100, 50)'); // #ff0044
410
+ oklch2hex({ l: 0.63269, c: 0.25404, h: 19.90218 }); // '#ff0044'
411
+ oklch2hex([0.63269, 0.25404, 19.90218]); // '#ff0044'
236
412
  ```
237
413
 
238
- **palette(input: string, options?: PaletteOptions): string[]**
239
- _get a palette for a color_
414
+ **oklch2hsl(input: LCH | ColorTuple): HSL**
415
+ Convert OKLCH to HSL.
240
416
 
241
417
  ```typescript
242
- import { palette } from 'colorizr';
418
+ import { oklch2hsl } from 'colorizr';
243
419
 
244
- palette('#ff0044');
245
- // ['#ff0044', '#ff7700', '#88ff00', '#00ff77', '#0088ff', '#7700ff'];
246
-
247
- palette('#ff0044', { type: 'monochromatic' });
248
- // ['#ff99b4', '#ff5582', '#ff1150', '#cc0036', '#880024', '#440012']
420
+ oklch2hsl({ l: 0.63269, c: 0.25404, h: 19.90218 }); // { h: 344, s: 100, l: 50 }
421
+ oklch2hsl([0.63269, 0.25404, 19.90218]); // { h: 344, s: 100, l: 50 }
249
422
  ```
250
423
 
251
- **parseCSS(input: string, output: ColorTypes = 'hex'): string | HSL | RGB**
252
- _parse a css string to hex, hsl, or RGB_
424
+ **oklch2oklab(input: LCH | ColorTuple, precision?: number): LAB**
425
+ Convert OKLCH to OKLAB.
253
426
 
254
427
  ```typescript
255
- import { parseCSS } from 'colorizr';
428
+ import { oklch2oklab } from 'colorizr';
256
429
 
257
- parseCSS('hsl(270 60% 70%)'); // '#b385e0'
258
- parseCSS('#ff0044', 'hsl'); // { h: 344, l: 50, s: 100 }
430
+ oklch2oklab({ l: 0.63269, c: 0.25404, h: 19.90218 }); // { l: 0.63269, a: 0.23887, b: 0.08648 }
431
+ oklch2oklab([0.63269, 0.25404, 19.90218]); // { l: 0.63269, a: 0.23887, b: 0.08648 }
259
432
  ```
260
433
 
261
- **random(): string**
262
- _get a random color_
434
+ **oklch2rgb(input: LCH | ColorTuple, precision: number = 0): RGB**
435
+ Convert OKLCH to RGB.
263
436
 
264
437
  ```typescript
265
- import { random } from 'colorizr';
438
+ import { oklch2rgb } from 'colorizr';
266
439
 
267
- random(); // '#b385e0'
440
+ oklch2rgb({ l: 0.63269, c: 0.25404, h: 19.90218 }); // { r: 255, g: 0, b: 68 }
441
+ oklch2rgb([0.63269, 0.25404, 19.90218]); // { r: 255, g: 0, b: 68 }
268
442
  ```
269
443
 
270
- **rgb2hex(input: RGB | RGBArray): string**
271
- _convert an RGB object into a hex string_
444
+ **rgb2hex(input: RGB | ColorTuple): string**
445
+ Convert RGB to HEX.
272
446
 
273
447
  ```typescript
274
448
  import { rgb2hex } from 'colorizr';
275
449
 
276
- rgb2hex({ r: 255, g: 55, b: 75 }); // '#ff374b'
450
+ rgb2hex({ r: 255, g: 0, b: 68 }); // '#ff0044'
277
451
  rgb2hex([255, 0, 68]); // '#ff0044'
278
452
  ```
279
453
 
280
- **rgb2hsl(input: RGB | RGBArray): HSL**
281
- _convert an RGB object into an HSL object_
454
+ **rgb2hsl(input: RGB | ColorTuple): HSL**
455
+ Convert RGB to HSL.
282
456
 
283
457
  ```typescript
284
458
  import { rgb2hsl } from 'colorizr';
285
459
 
286
- rgb2hsl({ r: 255, g: 55, b: 75 }); // { h: 354, s: 100, l: 60.78 }
460
+ rgb2hsl({ r: 255, g: 0, b: 68 }); // { h: 344, s: 100, l: 50 }
287
461
  rgb2hsl([255, 0, 68]); // { h: 344, s: 100, l: 50 }
288
462
  ```
289
463
 
290
- **rotate(input: string, degrees = 15): string** _get a color with changed hue_
464
+ **rgb2oklab(input: RGB | ColorTuple, precision: number): LAB**
465
+ Convert RGB to OKLAB.
291
466
 
292
467
  ```typescript
293
- import { rotate } from 'colorizr';
468
+ import { rgb2oklab } from 'colorizr';
294
469
 
295
- rotate('#ff0044', 30); // #ff3b00
470
+ rgb2oklab({ r: 255, g: 0, b: 68 }); // { l: 0.63269, a: 0.23887, b: 0.08648 }
471
+ rgb2oklab([255, 0, 68]); // { l: 0.63269, a: 0.23887, b: 0.08648 }
296
472
  ```
297
473
 
298
- **saturate(input: string, amount: number): string**
299
- _get a color with increased saturation_
474
+ **rgb2oklch(input: RGB | ColorTuple, precision: number): LCH**
475
+ Convert RGB to OKLCH.
300
476
 
301
477
  ```typescript
302
- import { saturate } from 'colorizr';
478
+ import { rgb2oklch } from 'colorizr';
303
479
 
304
- saturate('#ff0044', 10); // #ff0044 (already at the maximum)
305
- saturate('pink', 10); // #ffc0cb
480
+ rgb2oklch({ r: 255, g: 0, b: 68 }); // { l: 0.63269, c: 0.25404, h: 19.90218 }
481
+ rgb2oklch([255, 0, 68]); // { l: 0.63269, c: 0.25404, h: 19.90218 }
306
482
  ```
307
483
 
308
- **scheme(input: string, type: Scheme): string[]**
309
- _get the scheme for a color_
484
+ ### Utilities
485
+
486
+ **addAlphaToHex(input: string, alpha: number): string**
487
+ Add an alpha value to a hex string
310
488
 
311
489
  ```typescript
312
- import { scheme } from 'colorizr';
490
+ import { addAlphaToHex } from 'colorizr';
313
491
 
314
- const complementary = scheme('rgb(255, 0, 68)'); // ['#ff0044', '#00ffbb']
315
- const triadic = scheme('#ff0044', 'triadic'); // ['#ff0044', '#44ff00', '#0044ff']
492
+ addAlphaToHex('#ff0044', 0.9); // '#ff0044e6'
493
+ addAlphaToHex('#ff0044cc', 0.9); // '#ff0044e6'
494
+ ```
495
+
496
+ **convertAlphaToHex(input: number): string**
497
+ Convert an alpha value to a hex value.
498
+
499
+ ```typescript
500
+ import { convertAlphaToHex } from 'colorizr';
501
+
502
+ convertAlphaToHex(0.5); // '80'
503
+ ```
504
+
505
+ **extractAlphaFromHex(input: string): number**
506
+ Extract the alpha value from a hex string
507
+
508
+ ```typescript
509
+ import { extractAlphaFromHex } from 'colorizr';
510
+
511
+ convertAlphaToHex('#ff004480'); // 0.5
512
+ ```
513
+
514
+ **extractColorParts(input: string): ExtractColorPartsReturn**
515
+ Extract the color parts from a CSS color string.
516
+ Hex colors are not supported.
517
+
518
+ ```typescript
519
+ type ExtractColorPartsReturn = {
520
+ alpha?: number;
521
+ model: 'hsl' | 'oklab' | 'oklch' | 'rgb';
522
+ } & Record<string, number>;
523
+
524
+ extractColorParts('rgb(255 0 68)') // { model: 'rgb', r: 255, g: 0, b: 68 }
525
+ extractColorParts('hsl(344 100% 50% / 90%)') // { alpha: 0.9, model: 'hsl', h: 344, g: 100, l: 50 }
526
+ ```
527
+
528
+ **formatCSS(input: HSL | RGB, options?: FormatOptions): string**
529
+ Get a css string from a color object.
530
+
531
+ ```typescript
532
+ import { formatCSS } from 'colorizr';
533
+
534
+ formatCSS({ h: 344, s: 100, l: 50 }, { format: 'rgb' }); // 'rgb(255, 0, 68)'
535
+ formatCSS({ r: 255, g: 0, b: 68 }, { alpha: 0.5, format: 'hsl' }); // 'hsla(344, 100%, 50%, 0.5)'
536
+ ```
537
+
538
+ **formatHex(input: string): string**
539
+ Format a short hex string of 3 (or 4) digits into 6 (or 8) digits.
540
+
541
+ ```typescript
542
+ import { formatHex } from 'colorizr';
543
+
544
+ formatHex('#07e'); // '#0077ee'
545
+ formatHex('#f058'); // '#ff005588'
546
+ ```
547
+ **parseCSS(input: string, format?: ColorType): string | HSL | RGB**
548
+ Parse a css string to hex, HSL, OKLAB, OKLCH, or RGB.
549
+ If the format isn't set, it will return the same format as the input.
550
+
551
+ ```typescript
552
+ import { parseCSS } from 'colorizr';
553
+
554
+ parseCSS('hsl(344 100% 50%)'); // { h: 344, l: 50, s: 100 }
555
+ parseCSS('#ff0044', 'hsl'); // { h: 344, l: 50, s: 100 }
556
+ ```
557
+
558
+ **random(type: ColorType = 'hex'): string**
559
+ Get a random color.
560
+
561
+ ```typescript
562
+ import { random } from 'colorizr';
563
+
564
+ random(); // '#b385e0'
565
+ random('oklch') // oklab(86.876% -0.22518 0.1597)
566
+ ```
567
+
568
+ **removeAlphaFromHex(input: string): string**
569
+ Remove the alpha value from a hex string
570
+
571
+ ```typescript
572
+ import { removeAlphaFromHex } from 'colorizr';
573
+
574
+ removeAlphaFromHex('#ff0044cc'); // '#ff0044'
316
575
  ```
317
576
 
318
577
  **textColor(input: string): string**
319
- _get a contrasting color to use with the text_
578
+ Get a contrasting color (black or white) for the input color.
320
579
 
321
580
  ```typescript
322
581
  import { textColor } from 'colorizr';
@@ -325,7 +584,75 @@ textColor('#ff0044'); // #ffffff
325
584
  textColor('#fff800'); // #000000
326
585
  ```
327
586
 
328
- ## Instance API
587
+ ### Validators
588
+
589
+ **isValidColor(input: any): boolean**
590
+ Check if the input is a valid color.
591
+
592
+ ```typescript
593
+ import { isValidColor } from 'colorizr';
594
+
595
+ isValidColor('#ff0044'); // true
596
+ isValidColor('#ff004400'); // true
597
+ isValidColor('hsl(136 100% 50%)'); // true
598
+ isValidColor('hsla(344, 100%, 50%, 0.4)'); // true
599
+ isValidColor('oklab(70.622% 0.1374 0.14283)'); // true
600
+ isValidColor('oklch(47.642% 0.29956 274.93693)'); // true
601
+ isValidColor('rgb(255 230 109)'); // true
602
+ isValidColor('blue'); // true
603
+ isValidColor('aliceblue'); // true
604
+ isValidColor('#mmff00'); // false
605
+ isValidColor('blue-ish'); // false
606
+ ```
607
+
608
+ **isHex(input: unknown): boolean**
609
+ Check if the input is a valid hex color.
610
+
611
+ ```typescript
612
+ import { isHex } from 'colorizr';
613
+
614
+ isHex('#f04'); // true
615
+ isHex('#ff0044'); // true
616
+ isHex('#ff0044cc'); // true
617
+ ```
618
+
619
+ **isHSL(input: unknown): boolean**
620
+ Check if the input is a valid HSL object.
621
+
622
+ ```typescript
623
+ import { isHSL } from 'colorizr';
624
+
625
+ isHSL({ h: 344, s: 100, l: 50 }); // true
626
+ ```
627
+
628
+ **isLAB(input: unknown): boolean**
629
+ Check if the input is a valid LAB color.
630
+
631
+ ```typescript
632
+ import { isLAB } from 'colorizr';
633
+
634
+ isLAB({ l: 0.63269, a: 0.23887, b: 0.08648 }); // true
635
+ ```
636
+
637
+ **isLHC(input: unknown): boolean**
638
+ Check if the input is a valid LCH color.
639
+
640
+ ```typescript
641
+ import { isLHC } from 'colorizr';
642
+
643
+ isLHC({ l: 0.63269, c: 0.25404, h: 19.90218 }); // true
644
+ ```
645
+
646
+ **isRGB(input: unknown): boolean**
647
+ Check if the input is a valid RGB color.
648
+
649
+ ```typescript
650
+ import { isRGB } from 'colorizr';
651
+
652
+ isRGB({ r: 255, g: 0, b: 68 }); // true
653
+ ```
654
+
655
+ ### Class
329
656
 
330
657
  ```typescript
331
658
  import Colorizr from 'Colorizr';
@@ -337,65 +664,72 @@ colorizr.hsl; // { h: 344, s: 100, l: 50 };
337
664
  colorizr.rgb; // { r: 255, g: 0, b: 68 };
338
665
  ```
339
666
 
340
- ### Getters
667
+ #### Getters
341
668
 
342
669
  **colorizr.hex**
343
- _returns the hex_
670
+ Get the hex code.
344
671
 
345
672
  **colorizr.hsl**
346
- _returns the HSL object_
673
+ Get the HSL object.
674
+
675
+ **colorizr.oklab**
676
+ Get the OKLAB object.
677
+
678
+ **colorizr.oklch**
679
+ Get the OKLCH object.
347
680
 
348
681
  **colorizr.rgb**
349
- _returns the RGB object_
682
+ Get the RGB object.
350
683
 
351
684
  **colorizr.hue**
352
- _returns the color hue, between 0 and 360_
685
+ Get the hue (0-360).
353
686
 
354
687
  **colorizr.saturation**
355
- _returns the color saturation, between 0 and 100_
688
+ Get the saturation (0-100).
356
689
 
357
690
  **colorizr.lightness**
358
- _returns the color lightness, between 0 and 100_
691
+ Get the lightness (0-100).
359
692
 
360
693
  **colorizr.red**
361
- _returns the color red level, between 0 and 255_
694
+ Get the red level (0-255).
362
695
 
363
696
  **colorizr.green**
364
- _returns the color green level, between 0 and 255_
697
+ Get the green level (0-255).
365
698
 
366
699
  **colorizr.blue**
367
- _returns the color blue level, between 0 and 255_
368
-
369
- **colorizr.luminance**
700
+ Get the blue level (0-255).
370
701
 
371
702
  **colorizr.chroma**
703
+ Get the chroma (0-1).
372
704
 
373
- **colorizr.textColor**
374
-
375
- ### Manipulation
376
-
377
- **colorizr.lighten(percentage = 10)**
705
+ **colorizr.luminance**
706
+ Get the luminance (0-1).
378
707
 
379
- **colorizr.darken(percentage = 10)**
708
+ **colorizr.opacity**
709
+ Get the opacity (0-1).
380
710
 
381
- **colorizr.saturate(percentage = 10)**
711
+ **colorizr.css**
712
+ Get the css string of the same type as the input.
382
713
 
383
- **colorizr.saturate(percentage = 10)**
384
-
385
- **colorizr.rotate(degrees = 15)**
714
+ **colorizr.textColor**
715
+ Get a contrasting color (black or white).
386
716
 
387
- **colorizr.invert()**
717
+ #### Methods
388
718
 
389
- **colorizr.fade(percentage = 10)**
719
+ **colorizr.format(type: ColorType, precision?: number)**
720
+ Returns the formatted color with the type
390
721
 
391
- ### Comparison
722
+ ...
392
723
 
393
- **colorizr.compare(color: string)**
394
- _returns an object with the analysis (check the compare output above)_
724
+ Also, all the [manipulators](#Manipulators) and [comparison](#Comparison) utilities.
395
725
 
396
- ## References
726
+ ## Credits / References
397
727
 
728
+ [color.js](https://github.com/color-js/color.js)
729
+ [chroma-js](https://gka.github.io/chroma.js/)
398
730
  [calculating-color-contrast](https://24ways.org/2010/calculating-color-contrast/)
399
731
  [Colour Contrast Check](https://snook.ca/technical/colour_contrast/colour.html)
400
732
  [Contrast Checker](https://webaim.org/resources/contrastchecker/)
401
- [Converting Color Spaces in typescript](https://css-tricks.com/converting-color-spaces-in-typescript/)
733
+ [Converting Color Spaces in typescript](https://css-tricks.com/converting-color-spaces-in-typescript/)
734
+ [A perceptual color space for image processing](https://bottosson.github.io/posts/oklab/)
735
+