Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
33ad208
commit 25012c7
Showing
5 changed files
with
27 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "./src/cssHexColorToRGBA.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { default } from "./src/cssHexColorToRGB.js"; | ||
export { default } from "./src/cssHexColorToRGBA.js"; | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* Converts a colour from a CSS hex colour code to an RGBA array | ||
* @param {string} col CSS hex colour code | ||
* @returns {[number, number, number, number]} | ||
*/ | ||
export default function _default(col: string): [number, number, number, number]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// @ts-check | ||
|
||
import expandCSSHexColor from "@chriscodesthings/expand-css-hex-color"; | ||
import { roundToPrecision } from "more-rounding"; | ||
|
||
/** | ||
* Converts a colour from a CSS hex colour code to an RGBA array | ||
* @param {string} col CSS hex colour code | ||
* @returns {[number, number, number, number]} | ||
*/ | ||
export default function (col) { | ||
const hex = expandCSSHexColor(col).slice(1); | ||
const r = parseInt(hex.slice(0, 2), 16); | ||
const g = parseInt(hex.slice(2, 4), 16); | ||
const b = parseInt(hex.slice(4, 6), 16); | ||
const a = roundToPrecision(parseInt(hex.slice(6, 8), 16) / 255, 2); | ||
|
||
return [r, g, b, a]; | ||
} |