-
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.
feature(v5.0.0): hex to grb returns undefined instead of null (#21)
* feature: hex to grb returns undefined instead of null * chore: bump deps * ci: add CI * ci: add bin * chore: fix comments, add rabbit config
- Loading branch information
1 parent
a9cb6b6
commit dcebd34
Showing
14 changed files
with
2,195 additions
and
258 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,8 @@ | ||
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json | ||
language: "en-US" | ||
reviews: | ||
poem: false | ||
review_status: false | ||
auto_review: | ||
enabled: true | ||
drafts: false |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
This PR implements ... |
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,80 @@ | ||
name: pipeline | ||
on: [ push ] | ||
|
||
env: | ||
TAG_NAME: $(echo "${{ github.ref_name }}" | sed 's/[^a-zA-Z0-9._-]/_/g') | ||
NVM_NODE_VERSION: 18 | ||
PROJECT: colors | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
build-and-lint: | ||
runs-on: | ||
group: default-runners | ||
labels: self-hosted | ||
steps: | ||
- uses: actions/checkout@v4 | ||
env: | ||
CURRENT_RUNNER: ${{ runner.name }} | ||
|
||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ env.NVM_NODE_VERSION }} | ||
|
||
- name: build-and-lint | ||
shell: bash | ||
run: | | ||
./bin/node-version-manager.sh yarn install --production=false --frozen-lockfile | ||
./bin/node-version-manager.sh yarn build | ||
./bin/node-version-manager.sh yarn lint | ||
dry-run-publish: | ||
needs: [ build-and-lint ] | ||
runs-on: | ||
group: default-runners | ||
labels: self-hosted | ||
steps: | ||
- uses: actions/checkout@v4 | ||
env: | ||
CURRENT_RUNNER: ${{ runner.name }} | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} | ||
|
||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ env.NVM_NODE_VERSION }} | ||
|
||
- name: dry-run-publish | ||
shell: bash | ||
run: | | ||
./bin/node-version-manager.sh yarn install --production=false --frozen-lockfile | ||
./bin/node-version-manager.sh yarn build | ||
./bin/node-version-manager.sh npm publish --access public --tag latest --dry-run | ||
publish-npm: | ||
needs: [ dry-run-publish ] | ||
# TODO: not working yet | ||
if: false | ||
# if: github.ref == 'refs/heads/master' | ||
runs-on: | ||
group: default-runners | ||
labels: self-hosted | ||
steps: | ||
- uses: actions/checkout@v4 | ||
env: | ||
CURRENT_RUNNER: ${{ runner.name }} | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} | ||
|
||
# Setup .npmrc file to publish to npm | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ env.NVM_NODE_VERSION }} | ||
|
||
- name: publish-npm | ||
shell: bash | ||
run: | | ||
./bin/node-version-manager.sh yarn install --production=false --frozen-lockfile | ||
./bin/node-version-manager.sh yarn build | ||
./bin/node-version-manager.sh npm publish --access public --tag latest |
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 @@ | ||
#!/bin/bash | ||
# shellcheck disable=SC1090 | ||
source ~/.bashrc | ||
export NVM_DIR=~/.nvm | ||
source ~/.nvm/nvm.sh | ||
source ~/.nvm/bash_completion | ||
{ | ||
nvm install "v$NVM_NODE_VERSION" --lts | ||
nvm alias default "v$NVM_NODE_VERSION" | ||
nvm alias node "v$NVM_NODE_VERSION" | ||
nvm alias system "v$NVM_NODE_VERSION" | ||
nvm use "v$NVM_NODE_VERSION" | ||
npm install -g yarn | ||
|
||
"$@" | ||
} || { | ||
echo "An error occurred during execution." | ||
exit 1 | ||
} |
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,3 +1,4 @@ | ||
{ | ||
"extends": ["@allthings", ":preserveSemverRanges"] | ||
"$schema": "https://docs.renovatebot.com/renovate-schema.json", | ||
"extends": ["github>allthings/renovate-config", "docker:disable"] | ||
} |
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,39 +1,42 @@ | ||
import hexToRgb from './hexToRgb' | ||
import rgbToHex from './rgbToHex' | ||
|
||
export interface RGBColor { | ||
/* eslint-disable sort-keys, typescript-sort-keys/interface */ | ||
export interface IRGBColor { | ||
r: number | ||
g: number | ||
b: number | ||
} | ||
|
||
function calculateTransparentColor(color: RGBColor, alpha: number) { | ||
const calculateTransparentColor = (color: IRGBColor, alphaNumber: number) => { | ||
const blendingColor = { | ||
r: 255, | ||
g: 255, | ||
b: 255, | ||
} | ||
|
||
return rgbToHex( | ||
(1 - alpha) * blendingColor.r + alpha * color.r, | ||
(1 - alpha) * blendingColor.g + alpha * color.g, | ||
(1 - alpha) * blendingColor.b + alpha * color.b, | ||
(1 - alphaNumber) * blendingColor.r + alphaNumber * color.r, | ||
(1 - alphaNumber) * blendingColor.g + alphaNumber * color.g, | ||
(1 - alphaNumber) * blendingColor.b + alphaNumber * color.b, | ||
) | ||
} | ||
|
||
export default function alpha( | ||
const alpha = ( | ||
hex: string, | ||
alpha: number, | ||
alphaNumber: number, | ||
actualColor?: boolean, | ||
): string { | ||
): string => { | ||
const rgb = hexToRgb(hex) | ||
if (rgb === null) { | ||
if (rgb === undefined) { | ||
throw new Error( | ||
`\`hex\` value provided to \`alpha\` is not a HEX color, \`${hex}\` given.`, | ||
) | ||
} | ||
|
||
return actualColor | ||
? calculateTransparentColor(rgb, alpha) | ||
: `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, ${alpha})` | ||
? calculateTransparentColor(rgb, alphaNumber) | ||
: `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, ${alphaNumber})` | ||
} | ||
|
||
export default 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 |
---|---|---|
@@ -1,16 +1,23 @@ | ||
import { RGBColor } from './alpha' | ||
|
||
export default function hexToRgb(hex: string): RGBColor | null { | ||
/* eslint-disable sort-keys */ | ||
const hexToRgb = ( | ||
hex: string, | ||
): { b: number; g: number; r: number } | undefined => { | ||
// Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF") | ||
const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i | ||
hex = hex.replace(shorthandRegex, (_m, r, g, b) => r + r + g + g + b + b) | ||
const replacedHex = hex.replace( | ||
shorthandRegex, | ||
(_m, r, g, b) => r + r + g + g + b + b, | ||
) | ||
|
||
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(replacedHex) | ||
|
||
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex) | ||
return result | ||
? { | ||
r: parseInt(result[1], 16), | ||
g: parseInt(result[2], 16), | ||
b: parseInt(result[3], 16), | ||
r: Number.parseInt(result[1], 16), | ||
g: Number.parseInt(result[2], 16), | ||
b: Number.parseInt(result[3], 16), | ||
} | ||
: null | ||
: undefined | ||
} | ||
|
||
export default 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export { default as ColorPalette } from './ColorPalette' | ||
export { default as alpha } from './alpha' | ||
export { default as ColorPalette } from './ColorPalette' | ||
export { default as hexToRgb } from './hexToRgb' | ||
export { default as rgbToHex } from './rgbToHex' |
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,8 +1,8 @@ | ||
export default function rgbToHex( | ||
red: number, | ||
green: number, | ||
blue: number, | ||
): string { | ||
const rgbToHex = (red: number, green: number, blue: number): string => { | ||
// eslint-disable-next-line no-bitwise | ||
const rgb = blue | (green << 8) | (red << 16) | ||
return '#' + (0x1000000 + rgb).toString(16).slice(1) | ||
|
||
return `#${(0x1_00_00_00 + rgb).toString(16).slice(1)}` | ||
} | ||
|
||
export default rgbToHex |
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
Oops, something went wrong.