-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from heyjul3s/feat/hextorgba
hexToRGBA
- Loading branch information
Showing
11 changed files
with
110 additions
and
27 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 |
---|---|---|
@@ -1,11 +1,3 @@ | ||
# `@artifak/hextorgb` | ||
|
||
A utility function to convert hexadecimal colour values to RGB or RGBA string. | ||
|
||
## Usage | ||
|
||
``` | ||
const hextorgb = require('@artifak/hextorgb'); | ||
// TODO: DEMONSTRATE API | ||
``` | ||
A utility function to convert hexadecimal colour values to RGB string. |
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
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
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
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 { hexToRGB, hexToRGBA } from './hextorgb'; | ||
export { hexToRGB, getRGBvalues } from './hextorgb'; | ||
export { RGBColor } from './typings'; |
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,3 @@ | ||
# `@artifak/hextorgba` | ||
|
||
A utility function to convert hexadecimal colour values to RGBA string. |
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,17 @@ | ||
import { hexToRGBA } from '../src/hextorgba'; | ||
|
||
describe('@artifak/hextorgba', () => { | ||
it('returns a string RGBA value with valid hex and alpha values', () => { | ||
expect(hexToRGBA('#DF3EA1', 0.5)).toEqual('rgba(223, 62, 161, 0.5)'); | ||
expect(hexToRGBA('#df3ea1', 0.5)).toEqual('rgba(223, 62, 161, 0.5)'); | ||
}); | ||
|
||
it('returns a string RGBA value with valid hex and default alpha values', () => { | ||
expect(hexToRGBA('#DF3EA1')).toEqual('rgba(223, 62, 161, 1)'); | ||
expect(hexToRGBA('#df3ea1')).toEqual('rgba(223, 62, 161, 1)'); | ||
}); | ||
|
||
it('returns UNDEFINED with invalid non-hexadecimal color string value', () => { | ||
expect(hexToRGBA('Lorem Ipsum Dolor Sit Amet', 0.5)).toEqual(void 0); | ||
}); | ||
}); |
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,46 @@ | ||
{ | ||
"name": "@artifak/hextorgba", | ||
"version": "1.0.0", | ||
"description": "Utility function to convert style hex colour codes to RGBA string.", | ||
"keywords": [ | ||
"color", | ||
"RGBA", | ||
"hexadecimal", | ||
"utilities" | ||
], | ||
"author": "Julian Low", | ||
"license": "MIT", | ||
"sideEffects": false, | ||
"main": "dist/hextorgba.cjs.js", | ||
"module": "dist/hextorgba.esm.js", | ||
"src": "src/index.ts", | ||
"types": "dist/src/index.d.ts", | ||
"directories": { | ||
"lib": "src", | ||
"test": "__tests__" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/heyjul3s/artifak.git" | ||
}, | ||
"scripts": { | ||
"build": "rimraf dist && builder", | ||
"test": "echo \"Error: run tests from root\" && exit 1" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/heyjul3s/artifak/issues" | ||
}, | ||
"homepage": "https://github.com/heyjul3s/artifak#readme", | ||
"devDependencies": { | ||
"@artifak/bundler": "^1.1.3" | ||
}, | ||
"dependencies": { | ||
"@artifak/hextorgb": "^1.0.0" | ||
} | ||
} |
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,9 @@ | ||
import { getRGBvalues } from '@artifak/hextorgb'; | ||
|
||
export function hexToRGBA(hex: string, alpha = 1): string | void { | ||
const color = getRGBvalues(hex); | ||
|
||
if (!!color) { | ||
return `rgba(${color.r}, ${color.g}, ${color.b}, ${alpha})`; | ||
} | ||
} |
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,2 @@ | ||
export { hexToRGBA } from './hextorgba'; | ||
export { getRGBvalues } from '@artifak/hextorgb'; |
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,9 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "dist", | ||
"rootDir": "." | ||
}, | ||
"references": [], | ||
"include": ["src"] | ||
} |