Comparing version 4.2.1 to 4.2.2
53
index.js
const colorString = require('color-string'); | ||
const convert = require('color-convert'); | ||
const _slice = [].slice; | ||
const skippedModels = [ | ||
@@ -19,3 +17,3 @@ // To be honest, I don't really feel like keyword belongs in color convert, but eh. | ||
for (const model of Object.keys(convert)) { | ||
hashedModelKeys[_slice.call(convert[model].labels).sort().join('')] = model; | ||
hashedModelKeys[[...convert[model].labels].sort().join('')] = model; | ||
} | ||
@@ -47,3 +45,3 @@ | ||
this.model = object.model; | ||
this.color = object.color.slice(); | ||
this.color = [...object.color]; | ||
this.valpha = object.valpha; | ||
@@ -63,3 +61,3 @@ } else if (typeof object === 'string') { | ||
channels = convert[this.model].channels; | ||
const newArray = _slice.call(object, 0, channels); | ||
const newArray = Array.prototype.slice.call(object, 0, channels); | ||
this.color = zeroArray(newArray, channels); | ||
@@ -92,3 +90,3 @@ this.valpha = typeof object[channels] === 'number' ? object[channels] : 1; | ||
const labels = convert[this.model].labels; | ||
const {labels} = convert[this.model]; | ||
const color = []; | ||
@@ -132,3 +130,3 @@ for (i = 0; i < labels.length; i++) { | ||
self = self.round(typeof places === 'number' ? places : 1); | ||
const args = self.valpha === 1 ? self.color : self.color.concat(this.valpha); | ||
const args = self.valpha === 1 ? self.color : [...self.color, this.valpha]; | ||
return colorString.to[self.model](args); | ||
@@ -139,3 +137,3 @@ }, | ||
const self = this.rgb().round(typeof places === 'number' ? places : 1); | ||
const args = self.valpha === 1 ? self.color : self.color.concat(this.valpha); | ||
const args = self.valpha === 1 ? self.color : [...self.color, this.valpha]; | ||
return colorString.to.rgb.percent(args); | ||
@@ -145,3 +143,3 @@ }, | ||
array() { | ||
return this.valpha === 1 ? this.color.slice() : this.color.concat(this.valpha); | ||
return this.valpha === 1 ? [...this.color] : [...this.color, this.valpha]; | ||
}, | ||
@@ -151,4 +149,4 @@ | ||
const result = {}; | ||
const channels = convert[this.model].channels; | ||
const labels = convert[this.model].labels; | ||
const {channels} = convert[this.model]; | ||
const {labels} = convert[this.model]; | ||
@@ -194,8 +192,8 @@ for (let i = 0; i < channels; i++) { | ||
places = Math.max(places || 0, 0); | ||
return new Color(this.color.map(roundToPlace(places)).concat(this.valpha), this.model); | ||
return new Color([...this.color.map(roundToPlace(places)), this.valpha], this.model); | ||
}, | ||
alpha(value) { | ||
if (arguments.length > 0) { | ||
return new Color(this.color.concat(Math.max(0, Math.min(1, value))), this.model); | ||
if (value !== undefined) { | ||
return new Color([...this.color, Math.max(0, Math.min(1, value))], this.model); | ||
} | ||
@@ -239,3 +237,3 @@ | ||
keyword(value) { | ||
if (arguments.length > 0) { | ||
if (value !== undefined) { | ||
return new Color(value); | ||
@@ -248,3 +246,3 @@ } | ||
hex(value) { | ||
if (arguments.length > 0) { | ||
if (value !== undefined) { | ||
return new Color(value); | ||
@@ -257,3 +255,3 @@ } | ||
hexa(value) { | ||
if (arguments.length > 0) { | ||
if (value !== undefined) { | ||
return new Color(value); | ||
@@ -303,4 +301,5 @@ } | ||
level(color2) { | ||
// https://www.w3.org/TR/WCAG/#contrast-enhanced | ||
const contrastRatio = this.contrast(color2); | ||
if (contrastRatio >= 7.1) { | ||
if (contrastRatio >= 7) { | ||
return 'AAA'; | ||
@@ -423,6 +422,6 @@ } | ||
const channels = convert[model].channels; | ||
const {channels} = convert[model]; | ||
// Conversion methods | ||
Color.prototype[model] = function () { | ||
Color.prototype[model] = function (...args) { | ||
if (this.model === model) { | ||
@@ -432,14 +431,14 @@ return new Color(this); | ||
if (arguments.length > 0) { | ||
return new Color(arguments, model); | ||
if (args.length > 0) { | ||
return new Color(args, model); | ||
} | ||
const newAlpha = typeof arguments[channels] === 'number' ? channels : this.valpha; | ||
return new Color(assertArray(convert[this.model][model].raw(this.color)).concat(newAlpha), model); | ||
return new Color([...assertArray(convert[this.model][model].raw(this.color)), this.valpha], model); | ||
}; | ||
// 'static' construction methods | ||
Color[model] = function (color) { | ||
Color[model] = function (...args) { | ||
let color = args[0]; | ||
if (typeof color === 'number') { | ||
color = zeroArray(_slice.call(arguments), channels); | ||
color = zeroArray(args, channels); | ||
} | ||
@@ -473,3 +472,3 @@ | ||
if (arguments.length > 0) { | ||
if (value !== undefined) { | ||
if (modifier) { | ||
@@ -476,0 +475,0 @@ value = modifier(value); |
{ | ||
"name": "color", | ||
"version": "4.2.1", | ||
"version": "4.2.2", | ||
"description": "Color conversion and manipulation with CSS string support", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
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
16636