color-rgba
Advanced tools
Comparing version 2.3.0 to 2.4.0
33
index.js
@@ -6,4 +6,2 @@ /** @module color-rgba */ | ||
var parse = require('color-parse') | ||
var rgb = require('color-space/rgb') | ||
var hsl = require('color-space/hsl') | ||
@@ -21,4 +19,3 @@ module.exports = function rgba (color) { | ||
var min = parsed.space[0] === 'h' ? hsl.min : rgb.min | ||
var max = parsed.space[0] === 'h' ? hsl.max : rgb.max | ||
var min = [0,0,0], max = parsed.space[0] === 'h' ? [360,100,100] : [255,255,255] | ||
@@ -30,5 +27,3 @@ values = Array(3) | ||
if (parsed.space[0] === 'h') { | ||
values = hsl.rgb(values) | ||
} | ||
if (parsed.space[0] === 'h') values = hsl2rgb(values) | ||
@@ -39,1 +34,25 @@ values.push(Math.min(Math.max(parsed.alpha, 0), 1)) | ||
} | ||
// excerpt from color-space/hsl | ||
function hsl2rgb(hsl) { | ||
var h = hsl[0]/360, s = hsl[1]/100, l = hsl[2]/100, t1, t2, t3, rgb, val, i=0; | ||
if (s === 0) return val = l * 255, [val, val, val]; | ||
t2 = l < 0.5 ? l * (1 + s) : l + s - l * s; | ||
t1 = 2 * l - t2; | ||
rgb = [0, 0, 0]; | ||
for (;i<3;) { | ||
t3 = h + 1 / 3 * - (i - 1); | ||
t3 < 0 ? t3++ : t3 > 1 && t3--; | ||
val = 6 * t3 < 1 ? t1 + (t2 - t1) * 6 * t3 : | ||
2 * t3 < 1 ? t2 : | ||
3 * t3 < 2 ? t1 + (t2 - t1) * (2 / 3 - t3) * 6 : | ||
t1; | ||
rgb[i++] = val * 255; | ||
} | ||
return rgb; | ||
} |
{ | ||
"name": "color-rgba", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"description": "Convert color string (or parseable argument) to RGBA array", | ||
@@ -9,3 +9,3 @@ "main": "index.js", | ||
"scripts": { | ||
"test": "node test.mjs" | ||
"test": "node test.mjs && node test.cjs" | ||
}, | ||
@@ -35,5 +35,5 @@ "exports": { | ||
"dependencies": { | ||
"color-parse": "^1.4.1", | ||
"color-space": "^1.14.6" | ||
"color-parse": "^1.4.2", | ||
"color-space": "^2.0.0" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6955
158498
7
100
1
+ Addedcolor-space@2.0.1(transitive)
- Removedalmost-equal@1.1.0(transitive)
- Removedcolor-space@1.16.0(transitive)
- Removedhsluv@0.0.3(transitive)
- Removedmumath@3.3.4(transitive)
Updatedcolor-parse@^1.4.2
Updatedcolor-space@^2.0.0