Skip to content

Commit

Permalink
Apply update also to commonjs file
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Petersen committed Jul 16, 2021
1 parent 7cd6cd5 commit 22c92af
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
'use strict'

var parse = require('color-parse')
var rgb = require('color-space/rgb')
var hsl = require('color-space/hsl')

module.exports = function rgba (color) {
Expand All @@ -16,13 +17,16 @@ module.exports = function rgba (color) {

if (!parsed.space) return []

var minLimits = parsed.space[0] === 'h' ? hsl.min : rgb.min
var maxLimits = parsed.space[0] === 'h' ? hsl.max : rgb.max

values = Array(3)
values[0] = Math.min(Math.max(parsed.values[0], 0), 255)
values[1] = Math.min(Math.max(parsed.values[1], 0), 255)
values[2] = Math.min(Math.max(parsed.values[2], 0), 255)
values[0] = Math.min(Math.max(parsed.values[0], minLimits[0]), maxLimits[0])
values[1] = Math.min(Math.max(parsed.values[1], minLimits[1]), maxLimits[1])
values[2] = Math.min(Math.max(parsed.values[2], minLimits[2]), maxLimits[2])

if (parsed.space[0] === 'h') {
values = hsl.rgb(values)
values = hsl.rgb(values).map(Math.round)
}

values.push(Math.min(Math.max(parsed.alpha, 0), 1))
Expand Down

0 comments on commit 22c92af

Please sign in to comment.