Installations
npm install @uiw/color-convert
Developer Guide
Typescript
Yes
Module System
CommonJS, ESM
Node Version
20.18.1
NPM Version
10.8.2
Score
99.8
Supply Chain
99.6
Quality
86.4
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (98.29%)
HTML (1.02%)
CSS (0.65%)
Less (0.04%)
Developer
Download Statistics
Total Downloads
3,010,355
Last Day
13,209
Last Week
54,526
Last Month
238,961
Last Year
2,137,319
GitHub Statistics
343 Stars
460 Commits
109 Forks
4 Watching
9 Branches
15 Contributors
Bundle Size
5.80 kB
Minified
2.12 kB
Minified + Gzipped
Sponsor this package
Package Meta Information
Latest Version
2.3.4
Package Id
@uiw/color-convert@2.3.4
Unpacked Size
53.93 kB
Size
10.18 kB
File Count
7
NPM Version
10.8.2
Node Version
20.18.1
Publised On
11 Dec 2024
Total Downloads
Cumulative downloads
Total Downloads
3,010,355
Last day
-2.5%
13,209
Compared to previous day
Last week
-17.6%
54,526
Compared to previous week
Last month
22.9%
238,961
Compared to previous month
Last year
244.4%
2,137,319
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
1
Dev Dependencies
1
Color Convert
Install
1npm i @uiw/color-convert
Usage
1import { hsvaToHsla } from '@uiw/color-convert'
API
rgbaToHsva
1rgbaToHsva({ r: 255, g: 255, b: 255, a: 1 }) //=> { h: 0, s: 0, v: 100, a: 1 }
hexToHsva
1hexToHsva("#ffffff") //=> { h: 0, s: 0, v: 100, a: 1 }
hsvaToHex
1hsvaToHex({ h: 0, s: 0, v: 100, a: 1 }) // => "#ffffff"
hsvaToHexa
1hsvaToHexa({ h: 0, s: 0, v: 30, a: 0.4875 }) // => '#4d4d4d7c' 2hsvaToHexa({ h: 0, s: 0, v: 100, a: 1 }) // => '#ffffffff' 3hsvaToHexa({ h: 60, s: 100, v: 100, a: 1 }) // => '#ffff00ff'
hsvaToHsla
1hsvaToHsla({ h: 0, s: 0, v: 100, a: 1 }) // => { h: 0, s: 0, l: 100, a: 1 }
hslaToHsva
1hslaToHsva({ h: 0, s: 100, l: 50, a: 1 }) // => { h: 0, s: 100, v: 100, a: 1 } 2hslaToHsva({ h: 0, s: 0, l: 0, a: 1 }) // => { h: 0, s: 0, v: 0, a: 1 } 3hslaToHsva({ h: 200, s: 25, l: 32, a: 1 }) // => { h: 200, s: 40, v: 40, a: 1 }
hslStringToHsla
1hslStringToHsla('') 2// => { h: undefined, s: undefined, l: undefined, a: undefined } 3hslStringToHsla('hsl(50, 10%, 10%)') 4// => { h: 50, s: 10, l: 10 } 5hslStringToHsla('hsl(49deg 90% 65% / 39%)') 6// => { h: 49, s: 90, l: 65, a: 39 }
hsvaToHslString
1hsvaToHslString({ h: 200, s: 40, v: 40, a: 1 }) // => 'hsl(200, 25%, 32%)' 2hsvaToHslString({ h: 0, s: 0, v: 0, a: 1 }) // => 'hsl(0, 0%, 0%)'
hslStringToHsva
1hslStringToHsva('hsl(0, 0%, 100%)') // => { h: 0, s: 0, v: 100, a: 1 }
hslaStringToHsva
1hslaStringToHsva('hsla(0deg, 0%, 0%, 0.5)') // => { h: 0, s: 0, v: 0, a: 0.5 } 2hslaStringToHsva('hsla(200, 25%, 32%, 1)') // => { h: 200, s: 40, v: 40, a: 1 } 3hslaStringToHsva('hsla(.5turn 25% 32% / 50%)') // => { h: 180, s: 40, v: 40, a: 0.5 }
hsvaToRgba
1hsvaToRgba({ h: 0, s: 0, v: 100, a: 1 }) //=> { r: 255, g: 255, b: 255, a: 1 } 2hsvaToRgba({ h: 128, s: 0, v: 100, a: 1 }) //=> { r: 255, g: 255, b: 255, a: 1 } 3hsvaToRgba({ h: 0, s: 100, v: 100, a: 0.567 }) //=> { r: 255, g: 0, b: 0, a: 0.567 }
rgbaToHsva
1rgbaToHsva({ r: 255, g: 255, b: 255, a: 1 }) // => { h: 0, s: 0, v: 100, a: 1 }
rgbStringToHsva
1rgbStringToHsva('rgb(255, 255, 255)') // => { h: 0, s: 0, v: 100, a: 1 }
hsvaToRgbString
1hsvaToRgbString({ h: 0, s: 0, v: 100, a: 1 }) // => rgb(255, 255, 255)
hsvaToRgbaString
1hsvaToRgbaString({ h: 200, s: 40, v: 40, a: 0.5 }) // => rgba(61, 88, 102, 0.5)
rgbaStringToHsva
1rgbaStringToHsva('rgba(61, 88, 102, 0.5)') // => { h: 200, s: 40, v: 40, a: 0.5 }
hsvaToHsvaString
1hsvaToHsvaString({ h: 0, s: 0, v: 100, a: 1 }) // => hsva(0, 0%, 100%, 1)
hsvaToHsvString
1hsvaToHsvString({ h: 0, s: 0, v: 100, a: 1 }) // => hsv(0, 0%, 100%)
hsvStringToHsva
1hsvStringToHsva('hsv(0, 11%, 0%)') //=> { h: 0, s: 11, v: 0, a: 1, } 2hsvStringToHsva('hsv(90deg 20% 10%)') //=> { h: 90, s: 20, v: 10, a: 1, } 3hsvStringToHsva('hsv(100grad 20% 10%)') //=> { h: 90, s: 20, v: 10, a: 1, }
rgbaToRgb
1rgbaToRgb({ r: 0, g: 0, b: 0, a: 1 }) //=> { r: 0, g: 0, b: 0 }
hslaToHsl
1hslaToHsl({ h: 0, s: 0, l: 0, a: 1 }) //=> { h: 0, s: 0, l: 0 }
hsvaToHsv
1hsvaToHsv({ h: 0, s: 0, v: 0, a: 1 }) //=> { h: 0, s: 0, v: 0 }
equalHex
1equalHex("#8c0dba", "#8c0dba") // => true
equalColorObjects
1equalColorObjects({ h: 0, s: 0, v: 5, a: 0.5 }, { h: 0, s: 0, v: 5, a: 0.5 }) // => true
equalColorString
1equalColorString("rgb(0,0,0)", "rgb(0, 0, 0)") //=> true
hsvaToHslaString
1hsvaToHslaString({ h: 200, s: 40, v: 40, a: 0.5 }) //=> hsla(200, 25%, 32%, 0.5)
validHex
1validHex("#8c0dba") //=> true
rgbaToHexa
1rgbaToHexa({ b: 26, g: 2, r: 209, a: 1 }) // => '#d1021aff'
hexToXY
1hexToXY('#4780f1') // => { x: 0.261, y: 0.231, bri: 0.863 }
xyToHex
1xyToHex({ x: 0.261, y: 0.231, bri: 0.863 }) // => #4780f1
rgbToXY
1rgbToXY({ r: 71, g: 128, b: 241 }) // => { x: 0.261, y: 0.231, bri: 0.863 }
xyToRgb
1xyToRgb({ x: 0.261, y: 0.231, bri: 0.863 }) // => { r: 71, g: 128, b: 241 }
color
1const { rgb, rgba, hsl, hsv, hsla, hsva } = color('#d1021a'); 2// rgb => { b: 26, g: 2, r: 209, } 3// rgba => { b: 26, g: 2, r: 209, a: 1 } 4// hsl => { h: 353.04347826086956, l: 41.37254901960784, s: 98.10426540284361 } 5// hsla => { h: 353.04347826086956, l: 41.37254901960784, s: 98.10426540284361, a: 1 } 6// hsv => { h: 353.04347826086956, s: 99.04306220095694, v: 81.96078431372548 } 7// hsva => { h: 353.04347826086956, s: 99.04306220095694, v: 81.96078431372548, a: 1 } 8// hex => '#d1021a' 9// hexa => '#d1021aff'
type
1export type ObjectColor = RgbColor | HslColor | HsvColor | RgbaColor | HslaColor | HsvaColor; 2export type ColorResult = { 3 rgb: RgbColor; 4 hsl: HslColor; 5 hsv: HsvColor; 6 rgba: RgbaColor; 7 hsla: HslaColor; 8 hsva: HsvaColor; 9 hex: string; 10 hexa: string; 11}; 12export interface HsvColor { 13 h: number; 14 s: number; 15 v: number; 16} 17export interface HsvaColor extends HsvColor { 18 a: number; 19} 20export interface RgbColor { 21 r: number; 22 g: number; 23 b: number; 24} 25export interface RgbaColor extends RgbColor { 26 a: number; 27} 28/** 29 * ```js 30 * rgbaToHsva({ r: 255, g: 255, b: 255, a: 1 }) //=> { h: 0, s: 0, v: 100, a: 1 } 31 * ``` 32 */ 33export declare const rgbaToHsva: ({ r, g, b, a }: RgbaColor) => HsvaColor; 34export declare const hsvaToHslString: (hsva: HsvaColor) => string; 35export declare const hsvaToHsvString: ({ h, s, v }: HsvaColor) => string; 36export declare const hsvaToHsvaString: ({ h, s, v, a }: HsvaColor) => string; 37export declare const hsvaToHslaString: (hsva: HsvaColor) => string; 38export declare const hslStringToHsla: (str: string) => HslaColor; 39export declare const hslaStringToHsva: (hslString: string) => HsvaColor; 40export declare const hslStringToHsva: (hslString: string) => HsvaColor; 41export declare const hslaToHsva: ({ h, s, l, a }: HslaColor) => HsvaColor; 42export interface HslColor { 43 h: number; 44 s: number; 45 l: number; 46} 47export interface HslaColor extends HslColor { 48 a: number; 49} 50export declare const hsvaToHsla: ({ h, s, v, a }: HsvaColor) => HslaColor; 51export declare const hsvaStringToHsva: (hsvString: string) => HsvaColor; 52export declare const parseHue: (value: string, unit?: string) => number; 53export declare const hsvStringToHsva: (hsvString: string) => HsvaColor; 54export declare const rgbaStringToHsva: (rgbaString: string) => HsvaColor; 55export declare const rgbStringToHsva: (rgbaString: string) => HsvaColor; 56/** Converts an RGBA color plus alpha transparency to hex */ 57export declare const rgbaToHex: ({ r, g, b }: RgbaColor) => string; 58export declare const rgbaToHexa: ({ r, g, b, a }: RgbaColor) => string; 59export type HexColor = `#${string}`; 60export declare const hexToHsva: (hex: string) => HsvaColor; 61export declare const hexToRgba: (hex: string) => RgbaColor; 62/** 63 * Converts HSVA to RGBA. Based on formula from https://en.wikipedia.org/wiki/HSL_and_HSV 64 * @param color HSVA color as an array [0-360, 0-1, 0-1, 0-1] 65 */ 66export declare const hsvaToRgba: ({ h, s, v, a }: HsvaColor) => RgbaColor; 67export declare const hsvaToRgbString: (hsva: HsvaColor) => string; 68export declare const hsvaToRgbaString: (hsva: HsvaColor) => string; 69export declare const rgbaToRgb: ({ r, g, b }: RgbaColor) => RgbColor; 70export declare const hslaToHsl: ({ h, s, l }: HslaColor) => HslColor; 71export declare const hsvaToHex: (hsva: HsvaColor) => string; 72export declare const hsvaToHexa: (hsva: HsvaColor) => string; 73export declare const hsvaToHsv: ({ h, s, v }: HsvaColor) => HsvColor; 74export declare const color: (str: string | HsvaColor) => ColorResult; 75export declare const getContrastingColor: (str: string | HsvaColor) => "#ffffff" | "#000000"; 76export declare const equalColorObjects: (first: ObjectColor, second: ObjectColor) => boolean; 77export declare const equalColorString: (first: string, second: string) => boolean; 78export declare const equalHex: (first: string, second: string) => boolean; 79export declare const validHex: (hex: string) => hex is HexColor;
Contributors
As always, thanks to our amazing contributors!
Made with contributors.
License
Licensed under the MIT License.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
0 existing vulnerabilities detected
Reason
packaging workflow detected
Details
- Info: Project packages its releases by way of GitHub Actions.: .github/workflows/ci.yml:8
Reason
8 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 7
Reason
Found 6/28 approved changesets -- score normalized to 2
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/uiwjs/react-color/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/uiwjs/react-color/ci.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:28: update your workflow using https://app.stepsecurity.io/secureworkflow/uiwjs/react-color/ci.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:30: update your workflow using https://app.stepsecurity.io/secureworkflow/uiwjs/react-color/ci.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:63: update your workflow using https://app.stepsecurity.io/secureworkflow/uiwjs/react-color/ci.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:69: update your workflow using https://app.stepsecurity.io/secureworkflow/uiwjs/react-color/ci.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:72: update your workflow using https://app.stepsecurity.io/secureworkflow/uiwjs/react-color/ci.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:80: update your workflow using https://app.stepsecurity.io/secureworkflow/uiwjs/react-color/ci.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:88: update your workflow using https://app.stepsecurity.io/secureworkflow/uiwjs/react-color/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/pr.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/uiwjs/react-color/pr.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/pr.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/uiwjs/react-color/pr.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:21
- Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:23
- Warn: npmCommand not pinned by hash: .github/workflows/pr.yml:16
- Warn: npmCommand not pinned by hash: .github/workflows/pr.yml:18
- Info: 0 out of 4 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 7 third-party GitHubAction dependencies pinned
- Info: 0 out of 4 npmCommand dependencies pinned
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Warn: no topLevel permission defined: .github/workflows/pr.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 8 are checked with a SAST tool
Score
5.1
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More