Skip to content

Commit

Permalink
another test
Browse files Browse the repository at this point in the history
  • Loading branch information
brettedw committed Dec 3, 2024
1 parent 4208e62 commit 373a936
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ describe('getColorForRasterValue', () => {
const colour = getColorForRasterValue(rasterValue)
expect(colour).toBe('rgb(209, 255, 115)')
})
it('should return undefined if no colour is found', () => {
const rasterValue = 1000
const colour = getColorForRasterValue(rasterValue)
expect(colour).toBe(undefined)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ export const getColorForRasterValue = (rasterValue: number): string | undefined
*/
export const setTransparency = (color: string | undefined, alpha: number): string => {
if (!color) return 'rgba(0, 0, 0, 0)'
const rgbMatch = color.match(/\d+/g)

const rgbMatch = color.match(/\d+/g)?.map(Number)
if (!rgbMatch || rgbMatch.length < 3) {
throw new Error(`Invalid color format: ${color}`)
throw new Error(`Invalid color format: "${color}"`)
}
const [r, g, b] = rgbMatch.map(Number)

const [r, g, b] = rgbMatch
return `rgba(${r}, ${g}, ${b}, ${alpha})`
}

Expand Down

0 comments on commit 373a936

Please sign in to comment.