Socket
Socket
Sign inDemoInstall

colord

Package Overview
Dependencies
0
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.7.2 to 2.0.0

4

CHANGELOG.md

@@ -0,1 +1,5 @@

### 2.0.0
- Strict string color parsing conforming to the CSS Color Level specifications
### 1.7.2

@@ -2,0 +6,0 @@

2

index.js

@@ -1,1 +0,1 @@

Object.defineProperty(exports,"__esModule",{value:!0});var r=function(r){return"string"==typeof r?r.length>0:"number"==typeof r},t=function(r,t,n){return void 0===t&&(t=0),void 0===n&&(n=Math.pow(10,t)),Math.round(n*r)/n+0},n=function(r,t,n){return void 0===t&&(t=0),void 0===n&&(n=1),r>n?n:r>t?r:t},e=function(r){return(r=isFinite(r)?r%360:0)>0?r:r+360},u={grad:.9,turn:360,rad:360/(2*Math.PI)},o=function(r){return{r:n(r.r,0,255),g:n(r.g,0,255),b:n(r.b,0,255),a:n(r.a)}},a=function(r){return{r:t(r.r),g:t(r.g),b:t(r.b),a:t(r.a,2)}},i=/^\s*#?([0-9a-f]{3,8})\s*$/i,s=function(r){var t=r.toString(16);return t.length<2?"0"+t:t},b=function(r){var t=r.r,n=r.g,e=r.b,u=r.a,o=Math.max(t,n,e),a=o-Math.min(t,n,e),i=a?o===t?(n-e)/a:o===n?2+(e-t)/a:4+(t-n)/a:0;return{h:60*(i<0?i+6:i),s:o?a/o*100:0,v:o/255*100,a:u}},h=function(r){var t=r.h,n=r.s,e=r.v,u=r.a;t=t/360*6,n/=100,e/=100;var o=Math.floor(t),a=e*(1-n),i=e*(1-(t-o)*n),s=e*(1-(1-t+o)*n),b=o%6;return{r:255*[e,i,a,a,s,e][b],g:255*[s,e,e,i,a,a][b],b:255*[a,a,s,e,e,i][b],a:u}},g=function(r){return{h:e(r.h),s:n(r.s,0,100),l:n(r.l,0,100),a:n(r.a)}},f=function(r){return{h:t(r.h),s:t(r.s),l:t(r.l),a:t(r.a,2)}},c=function(r){return h((n=(t=r).s,{h:t.h,s:(n*=((e=t.l)<50?e:100-e)/100)>0?2*n/(e+n)*100:0,v:e+n,a:t.a}));var t,n,e},l=function(r){return{h:(t=b(r)).h,s:(u=(200-(n=t.s))*(e=t.v)/100)>0&&u<200?n*e/100/(u<=100?u:200-u)*100:0,l:u/2,a:t.a};var t,n,e,u},p=/hsla?\(?\s*(-?\d*\.?\d+)(deg|rad|grad|turn)?[,\s]+(-?\d*\.?\d+)%?[,\s]+(-?\d*\.?\d+)%?,?\s*[/\s]*(-?\d*\.?\d+)?(%)?\s*\)?/i,v=/rgba?\(?\s*(-?\d*\.?\d+)(%)?[,\s]+(-?\d*\.?\d+)(%)?[,\s]+(-?\d*\.?\d+)(%)?,?\s*[/\s]*(-?\d*\.?\d+)?(%)?\s*\)?/i,d={string:[[function(r){var t=i.exec(r);return t?(r=t[1]).length<=4?{r:parseInt(r[0]+r[0],16),g:parseInt(r[1]+r[1],16),b:parseInt(r[2]+r[2],16),a:4===r.length?parseInt(r[3]+r[3],16)/255:1}:6===r.length||8===r.length?{r:parseInt(r.substr(0,2),16),g:parseInt(r.substr(2,2),16),b:parseInt(r.substr(4,2),16),a:8===r.length?parseInt(r.substr(6,2),16)/255:1}:null:null},"hex"],[function(r){var t=v.exec(r);return t?o({r:Number(t[1])/(t[2]?100/255:1),g:Number(t[3])/(t[4]?100/255:1),b:Number(t[5])/(t[6]?100/255:1),a:void 0===t[7]?1:Number(t[7])/(t[8]?100:1)}):null},"rgb"],[function(r){var t=p.exec(r);if(!t)return null;var n,e,o=g({h:(n=t[1],e=t[2],void 0===e&&(e="deg"),Number(n)*(u[e]||1)),s:Number(t[3]),l:Number(t[4]),a:void 0===t[5]?1:Number(t[5])/(t[6]?100:1)});return c(o)},"hsl"]],object:[[function(t){var n=t.r,e=t.g,u=t.b,a=t.a,i=void 0===a?1:a;return r(n)&&r(e)&&r(u)?o({r:Number(n),g:Number(e),b:Number(u),a:Number(i)}):null},"rgb"],[function(t){var n=t.h,e=t.s,u=t.l,o=t.a,a=void 0===o?1:o;if(!r(n)||!r(e)||!r(u))return null;var i=g({h:Number(n),s:Number(e),l:Number(u),a:Number(a)});return c(i)},"hsl"],[function(t){var u=t.h,o=t.s,a=t.v,i=t.a,s=void 0===i?1:i;if(!r(u)||!r(o)||!r(a))return null;var b=function(r){return{h:e(r.h),s:n(r.s,0,100),v:n(r.v,0,100),a:n(r.a)}}({h:Number(u),s:Number(o),v:Number(a),a:Number(s)});return h(b)},"hsv"]]},m=function(r,t){for(var n=0;n<t.length;n++){var e=t[n][0](r);if(e)return[e,t[n][1]]}return[null,void 0]},y=function(r){return"string"==typeof r?m(r,d.string):"object"==typeof r&&null!==r?m(r,d.object):[null,void 0]},N=function(r,t){var e=l(r);return{h:e.h,s:n(e.s+100*t,0,100),l:e.l,a:e.a}},x=function(r){return(299*r.r+587*r.g+114*r.b)/1e3/255},M=function(r,t){var e=l(r);return{h:e.h,s:e.s,l:n(e.l+100*t,0,100),a:e.a}},I=function(){function r(r){this.parsed=y(r)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return r.prototype.isValid=function(){return null!==this.parsed},r.prototype.brightness=function(){return t(x(this.rgba),2)},r.prototype.isDark=function(){return x(this.rgba)<.5},r.prototype.isLight=function(){return x(this.rgba)>=.5},r.prototype.toHex=function(){return r=a(this.rgba),n=r.r,e=r.g,u=r.b,i=(o=r.a)<1?s(t(255*o)):"","#"+s(n)+s(e)+s(u)+i;var r,n,e,u,o,i},r.prototype.toRgb=function(){return a(this.rgba)},r.prototype.toRgbString=function(){return r=a(this.rgba),t=r.r,n=r.g,e=r.b,(u=r.a)<1?"rgba("+t+", "+n+", "+e+", "+u+")":"rgb("+t+", "+n+", "+e+")";var r,t,n,e,u},r.prototype.toHsl=function(){return f(l(this.rgba))},r.prototype.toHslString=function(){return r=f(l(this.rgba)),t=r.h,n=r.s,e=r.l,(u=r.a)<1?"hsla("+t+", "+n+"%, "+e+"%, "+u+")":"hsl("+t+", "+n+"%, "+e+"%)";var r,t,n,e,u},r.prototype.toHsv=function(){return r=b(this.rgba),{h:t(r.h),s:t(r.s),v:t(r.v),a:t(r.a,2)};var r},r.prototype.invert=function(){return j({r:255-(r=this.rgba).r,g:255-r.g,b:255-r.b,a:r.a});var r},r.prototype.saturate=function(r){return void 0===r&&(r=.1),j(N(this.rgba,r))},r.prototype.desaturate=function(r){return void 0===r&&(r=.1),j(N(this.rgba,-r))},r.prototype.grayscale=function(){return j(N(this.rgba,-1))},r.prototype.lighten=function(r){return void 0===r&&(r=.1),j(M(this.rgba,r))},r.prototype.darken=function(r){return void 0===r&&(r=.1),j(M(this.rgba,-r))},r.prototype.alpha=function(r){return"number"==typeof r?j({r:(n=this.rgba).r,g:n.g,b:n.b,a:r}):t(this.rgba.a,2);var n},r}(),j=function(r){return r instanceof I?r:new I(r)},H=[];exports.Colord=I,exports.colord=j,exports.extend=function(r){r.forEach(function(r){H.indexOf(r)<0&&(r(I,d),H.push(r))})},exports.getFormat=function(r){return y(r)[1]},exports.random=function(){return new I({r:255*Math.random(),g:255*Math.random(),b:255*Math.random()})};
Object.defineProperty(exports,"__esModule",{value:!0});var r=function(r){return"string"==typeof r?r.length>0:"number"==typeof r},t=function(r,t,n){return void 0===t&&(t=0),void 0===n&&(n=Math.pow(10,t)),Math.round(n*r)/n+0},n=function(r,t,n){return void 0===t&&(t=0),void 0===n&&(n=1),r>n?n:r>t?r:t},e=function(r){return(r=isFinite(r)?r%360:0)>0?r:r+360},u={grad:.9,turn:360,rad:360/(2*Math.PI)},a=function(r){return{r:n(r.r,0,255),g:n(r.g,0,255),b:n(r.b,0,255),a:n(r.a)}},o=function(r){return{r:t(r.r),g:t(r.g),b:t(r.b),a:t(r.a,2)}},s=/^#([0-9a-f]{3,8})$/i,i=function(r){var t=r.toString(16);return t.length<2?"0"+t:t},b=function(r){var t=r.r,n=r.g,e=r.b,u=r.a,a=Math.max(t,n,e),o=a-Math.min(t,n,e),s=o?a===t?(n-e)/o:a===n?2+(e-t)/o:4+(t-n)/o:0;return{h:60*(s<0?s+6:s),s:a?o/a*100:0,v:a/255*100,a:u}},h=function(r){var t=r.h,n=r.s,e=r.v,u=r.a;t=t/360*6,n/=100,e/=100;var a=Math.floor(t),o=e*(1-n),s=e*(1-(t-a)*n),i=e*(1-(1-t+a)*n),b=a%6;return{r:255*[e,s,o,o,i,e][b],g:255*[i,e,e,s,o,o][b],b:255*[o,o,i,e,e,s][b],a:u}},d=function(r){return{h:e(r.h),s:n(r.s,0,100),l:n(r.l,0,100),a:n(r.a)}},g=function(r){return{h:t(r.h),s:t(r.s),l:t(r.l),a:t(r.a,2)}},f=function(r){return h((n=(t=r).s,{h:t.h,s:(n*=((e=t.l)<50?e:100-e)/100)>0?2*n/(e+n)*100:0,v:e+n,a:t.a}));var t,n,e},l=function(r){return{h:(t=b(r)).h,s:(u=(200-(n=t.s))*(e=t.v)/100)>0&&u<200?n*e/100/(u<=100?u:200-u)*100:0,l:u/2,a:t.a};var t,n,e,u},c=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,p=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,v=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,m=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,y={string:[[function(r){var t=s.exec(r);return t?(r=t[1]).length<=4?{r:parseInt(r[0]+r[0],16),g:parseInt(r[1]+r[1],16),b:parseInt(r[2]+r[2],16),a:4===r.length?parseInt(r[3]+r[3],16)/255:1}:6===r.length||8===r.length?{r:parseInt(r.substr(0,2),16),g:parseInt(r.substr(2,2),16),b:parseInt(r.substr(4,2),16),a:8===r.length?parseInt(r.substr(6,2),16)/255:1}:null:null},"hex"],[function(r){var t=v.exec(r)||m.exec(r);return t?t[2]!==t[4]||t[4]!==t[6]?null:a({r:Number(t[1])/(t[2]?100/255:1),g:Number(t[3])/(t[4]?100/255:1),b:Number(t[5])/(t[6]?100/255:1),a:void 0===t[7]?1:Number(t[7])/(t[8]?100:1)}):null},"rgb"],[function(r){var t=c.exec(r)||p.exec(r);if(!t)return null;var n,e,a=d({h:(n=t[1],e=t[2],void 0===e&&(e="deg"),Number(n)*(u[e]||1)),s:Number(t[3]),l:Number(t[4]),a:void 0===t[5]?1:Number(t[5])/(t[6]?100:1)});return f(a)},"hsl"]],object:[[function(t){var n=t.r,e=t.g,u=t.b,o=t.a,s=void 0===o?1:o;return r(n)&&r(e)&&r(u)?a({r:Number(n),g:Number(e),b:Number(u),a:Number(s)}):null},"rgb"],[function(t){var n=t.h,e=t.s,u=t.l,a=t.a,o=void 0===a?1:a;if(!r(n)||!r(e)||!r(u))return null;var s=d({h:Number(n),s:Number(e),l:Number(u),a:Number(o)});return f(s)},"hsl"],[function(t){var u=t.h,a=t.s,o=t.v,s=t.a,i=void 0===s?1:s;if(!r(u)||!r(a)||!r(o))return null;var b=function(r){return{h:e(r.h),s:n(r.s,0,100),v:n(r.v,0,100),a:n(r.a)}}({h:Number(u),s:Number(a),v:Number(o),a:Number(i)});return h(b)},"hsv"]]},N=function(r,t){for(var n=0;n<t.length;n++){var e=t[n][0](r);if(e)return[e,t[n][1]]}return[null,void 0]},x=function(r){return"string"==typeof r?N(r.trim(),y.string):"object"==typeof r&&null!==r?N(r,y.object):[null,void 0]},M=function(r,t){var e=l(r);return{h:e.h,s:n(e.s+100*t,0,100),l:e.l,a:e.a}},I=function(r){return(299*r.r+587*r.g+114*r.b)/1e3/255},$=function(r,t){var e=l(r);return{h:e.h,s:e.s,l:n(e.l+100*t,0,100),a:e.a}},j=function(){function r(r){this.parsed=x(r)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return r.prototype.isValid=function(){return null!==this.parsed},r.prototype.brightness=function(){return t(I(this.rgba),2)},r.prototype.isDark=function(){return I(this.rgba)<.5},r.prototype.isLight=function(){return I(this.rgba)>=.5},r.prototype.toHex=function(){return r=o(this.rgba),n=r.r,e=r.g,u=r.b,s=(a=r.a)<1?i(t(255*a)):"","#"+i(n)+i(e)+i(u)+s;var r,n,e,u,a,s},r.prototype.toRgb=function(){return o(this.rgba)},r.prototype.toRgbString=function(){return r=o(this.rgba),t=r.r,n=r.g,e=r.b,(u=r.a)<1?"rgba("+t+", "+n+", "+e+", "+u+")":"rgb("+t+", "+n+", "+e+")";var r,t,n,e,u},r.prototype.toHsl=function(){return g(l(this.rgba))},r.prototype.toHslString=function(){return r=g(l(this.rgba)),t=r.h,n=r.s,e=r.l,(u=r.a)<1?"hsla("+t+", "+n+"%, "+e+"%, "+u+")":"hsl("+t+", "+n+"%, "+e+"%)";var r,t,n,e,u},r.prototype.toHsv=function(){return r=b(this.rgba),{h:t(r.h),s:t(r.s),v:t(r.v),a:t(r.a,2)};var r},r.prototype.invert=function(){return H({r:255-(r=this.rgba).r,g:255-r.g,b:255-r.b,a:r.a});var r},r.prototype.saturate=function(r){return void 0===r&&(r=.1),H(M(this.rgba,r))},r.prototype.desaturate=function(r){return void 0===r&&(r=.1),H(M(this.rgba,-r))},r.prototype.grayscale=function(){return H(M(this.rgba,-1))},r.prototype.lighten=function(r){return void 0===r&&(r=.1),H($(this.rgba,r))},r.prototype.darken=function(r){return void 0===r&&(r=.1),H($(this.rgba,-r))},r.prototype.alpha=function(r){return"number"==typeof r?H({r:(n=this.rgba).r,g:n.g,b:n.b,a:r}):t(this.rgba.a,2);var n},r}(),H=function(r){return r instanceof j?r:new j(r)},w=[];exports.Colord=j,exports.colord=H,exports.extend=function(r){r.forEach(function(r){w.indexOf(r)<0&&(r(j,y),w.push(r))})},exports.getFormat=function(r){return x(r)[1]},exports.random=function(){return new j({r:255*Math.random(),g:255*Math.random(),b:255*Math.random()})};
{
"name": "colord",
"version": "1.7.2",
"version": "2.0.0",
"description": "👑 A tiny yet powerful tool for high-performance color manipulations and conversions",

@@ -5,0 +5,0 @@ "keywords": [

@@ -1,1 +0,1 @@

var r=function(r){return"string"==typeof r?r.length>0:"number"==typeof r},n=function(r,n,t){return void 0===n&&(n=0),void 0===t&&(t=Math.pow(10,n)),Math.round(t*r)/t+0},t=function(r,n,t){return void 0===n&&(n=0),void 0===t&&(t=1),r>t?t:r>n?r:n},u={grad:.9,turn:360,rad:360/(2*Math.PI)},a=function(r){return{h:(n=r.h,(n=isFinite(n)?n%360:0)>0?n:n+360),w:t(r.w,0,100),b:t(r.b,0,100),a:t(r.a)};var n},e=function(r){return{h:n(r.h),w:n(r.w),b:n(r.b),a:n(r.a,2)}},o=function(r){return{h:function(r){var n=r.r,t=r.g,u=r.b,a=r.a,e=Math.max(n,t,u),o=e-Math.min(n,t,u),b=o?e===n?(t-u)/o:e===t?2+(u-n)/o:4+(n-t)/o:0;return{h:60*(b<0?b+6:b),s:e?o/e*100:0,v:e/255*100,a:a}}(r).h,w:Math.min(r.r,r.g,r.b)/255*100,b:100-Math.max(r.r,r.g,r.b)/255*100,a:r.a}},b=function(r){return function(r){var n=r.h,t=r.s,u=r.v,a=r.a;n=n/360*6,t/=100,u/=100;var e=Math.floor(n),o=u*(1-t),b=u*(1-(n-e)*t),i=u*(1-(1-n+e)*t),h=e%6;return{r:255*[u,b,o,o,i,u][h],g:255*[i,u,u,b,o,o][h],b:255*[o,o,i,u,u,b][h],a:a}}({h:r.h,s:100===r.b?0:100-r.w/(100-r.b)*100,v:100-r.b,a:r.a})},i=function(n){var t=n.h,u=n.w,e=n.b,o=n.a,i=void 0===o?1:o;if(!r(t)||!r(u)||!r(e))return null;var h=a({h:Number(t),w:Number(u),b:Number(e),a:Number(i)});return b(h)},h=/hwba?\(?\s*(-?\d*\.?\d+)(deg|rad|grad|turn)?[,\s]+(-?\d*\.?\d+)%?[,\s]+(-?\d*\.?\d+)%?,?\s*[/\s]*(-?\d*\.?\d+)?(%)?\s*\)?/i,d=function(r){var n=h.exec(r);if(!n)return null;var t,e,o=a({h:(t=n[1],e=n[2],void 0===e&&(e="deg"),Number(t)*(u[e]||1)),w:Number(n[3]),b:Number(n[4]),a:void 0===n[5]?1:Number(n[5])/(n[6]?100:1)});return b(o)};module.exports=function(r,n){r.prototype.toHwb=function(){return e(o(this.rgba))},r.prototype.toHwbString=function(){return r=e(o(this.rgba)),n=r.h,t=r.w,u=r.b,(a=r.a)<1?"hwb("+n+", "+t+"%, "+u+"%, "+a+")":"hwb("+n+", "+t+"%, "+u+"%)";var r,n,t,u,a},n.string.push([d,"hwb"]),n.object.push([i,"hwb"])};
var r=function(r){return"string"==typeof r?r.length>0:"number"==typeof r},n=function(r,n,t){return void 0===n&&(n=0),void 0===t&&(t=Math.pow(10,n)),Math.round(t*r)/t+0},t=function(r,n,t){return void 0===n&&(n=0),void 0===t&&(t=1),r>t?t:r>n?r:n},u={grad:.9,turn:360,rad:360/(2*Math.PI)},a=function(r){return{h:(n=r.h,(n=isFinite(n)?n%360:0)>0?n:n+360),w:t(r.w,0,100),b:t(r.b,0,100),a:t(r.a)};var n},e=function(r){return{h:n(r.h),w:n(r.w),b:n(r.b),a:n(r.a,2)}},o=function(r){return{h:function(r){var n=r.r,t=r.g,u=r.b,a=r.a,e=Math.max(n,t,u),o=e-Math.min(n,t,u),b=o?e===n?(t-u)/o:e===t?2+(u-n)/o:4+(n-t)/o:0;return{h:60*(b<0?b+6:b),s:e?o/e*100:0,v:e/255*100,a:a}}(r).h,w:Math.min(r.r,r.g,r.b)/255*100,b:100-Math.max(r.r,r.g,r.b)/255*100,a:r.a}},b=function(r){return function(r){var n=r.h,t=r.s,u=r.v,a=r.a;n=n/360*6,t/=100,u/=100;var e=Math.floor(n),o=u*(1-t),b=u*(1-(n-e)*t),i=u*(1-(1-n+e)*t),h=e%6;return{r:255*[u,b,o,o,i,u][h],g:255*[i,u,u,b,o,o][h],b:255*[o,o,i,u,u,b][h],a:a}}({h:r.h,s:100===r.b?0:100-r.w/(100-r.b)*100,v:100-r.b,a:r.a})},i=function(n){var t=n.h,u=n.w,e=n.b,o=n.a,i=void 0===o?1:o;if(!r(t)||!r(u)||!r(e))return null;var h=a({h:Number(t),w:Number(u),b:Number(e),a:Number(i)});return b(h)},h=/^hwb\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,d=function(r){var n=h.exec(r);if(!n)return null;var t,e,o=a({h:(t=n[1],e=n[2],void 0===e&&(e="deg"),Number(t)*(u[e]||1)),w:Number(n[3]),b:Number(n[4]),a:void 0===n[5]?1:Number(n[5])/(n[6]?100:1)});return b(o)};module.exports=function(r,n){r.prototype.toHwb=function(){return e(o(this.rgba))},r.prototype.toHwbString=function(){return r=e(o(this.rgba)),n=r.h,t=r.w,u=r.b,(a=r.a)<1?"hwb("+n+" "+t+"% "+u+"% / "+a+")":"hwb("+n+" "+t+"% "+u+"%)";var r,n,t,u,a},n.string.push([d,"hwb"]),n.object.push([i,"hwb"])};

@@ -1,1 +0,1 @@

var r=function(r){return"string"==typeof r?r.length>0:"number"==typeof r},t=function(r,t,a){return void 0===t&&(t=0),void 0===a&&(a=Math.pow(10,t)),Math.round(a*r)/a+0},a=function(r,t,a){return void 0===t&&(t=0),void 0===a&&(a=1),r>a?a:r>t?r:t},n={grad:.9,turn:360,rad:360/(2*Math.PI)},u=function(r){var t=r/255;return t<.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)},h=function(r){return 255*(r>.0031308?1.055*Math.pow(r,1/2.4)-.055:12.92*r)},o=96.422,e=100,c=82.521,i=function(r){var t,n,u={x:.9555766*(t=r).x+-.0230393*t.y+.0631636*t.z,y:-.0282895*t.x+1.0099416*t.y+.0210077*t.z,z:.0122982*t.x+-.020483*t.y+1.3299098*t.z};return n={r:h(.032404542*u.x-.015371385*u.y-.004985314*u.z),g:h(-.00969266*u.x+.018760108*u.y+41556e-8*u.z),b:h(556434e-9*u.x-.002040259*u.y+.010572252*u.z),a:r.a},{r:a(n.r,0,255),g:a(n.g,0,255),b:a(n.b,0,255),a:a(n.a)}},l=function(r){var t=u(r.r),n=u(r.g),h=u(r.b);return function(r){return{x:a(r.x,0,o),y:a(r.y,0,e),z:a(r.z,0,c),a:a(r.a)}}(function(r){return{x:1.0478112*r.x+.0228866*r.y+-.050127*r.z,y:.0295424*r.x+.9904844*r.y+-.0170491*r.z,z:-.0092345*r.x+.0150436*r.y+.7521316*r.z,a:r.a}}({x:100*(.4124564*t+.3575761*n+.1804375*h),y:100*(.2126729*t+.7151522*n+.072175*h),z:100*(.0193339*t+.119192*n+.9503041*h),a:r.a}))},b=216/24389,d=24389/27,f=function(r){return{l:a(r.l,0,100),c:r.c,h:(t=r.h,(t=isFinite(t)?t%360:0)>0?t:t+360),a:r.a};var t},p=function(r){return{l:t(r.l,2),c:t(r.c,2),h:t(r.h,2),a:t(r.a,2)}},v=function(t){var a=t.l,n=t.c,u=t.h,h=t.a,o=void 0===h?1:h;if(!r(a)||!r(n)||!r(u))return null;var e=f({l:Number(a),c:Number(n),h:Number(u),a:Number(o)});return M(e)},y=function(r){var a=function(r){var t=l(r),a=t.x/o,n=t.y/e,u=t.z/c;return a=a>b?Math.cbrt(a):(d*a+16)/116,{l:116*(n=n>b?Math.cbrt(n):(d*n+16)/116)-16,a:500*(a-n),b:200*(n-(u=u>b?Math.cbrt(u):(d*u+16)/116)),alpha:t.a}}(r),n=t(a.a,3),u=t(a.b,3),h=Math.atan2(u,n)/Math.PI*180;return{l:a.l,c:Math.sqrt(n*n+u*u),h:h<0?h+360:h,a:a.alpha}},M=function(r){return t={l:r.l,a:r.c*Math.cos(r.h*Math.PI/180),b:r.c*Math.sin(r.h*Math.PI/180),alpha:r.a},n=t.a/500+(a=(t.l+16)/116),u=a-t.b/200,i({x:(Math.pow(n,3)>b?Math.pow(n,3):(116*n-16)/d)*o,y:(t.l>8?Math.pow((t.l+16)/116,3):t.l/d)*e,z:(Math.pow(u,3)>b?Math.pow(u,3):(116*u-16)/d)*c,a:t.alpha});var t,a,n,u},x=/lcha?\(?\s*(-?\d*\.?\d+)%?[,\s]+(-?\d*\.?\d+)[,\s]+(-?\d*\.?\d+)(deg|rad|grad|turn)?,?\s*[/\s]*(-?\d*\.?\d+)?(%)?\s*\)?/i,s=function(r){var t=x.exec(r);if(!t)return null;var a,u,h=f({l:Number(t[1]),c:Number(t[2]),h:(a=t[3],u=t[4],void 0===u&&(u="deg"),Number(a)*(n[u]||1)),a:void 0===t[5]?1:Number(t[5])/(t[6]?100:1)});return M(h)};module.exports=function(r,t){r.prototype.toLch=function(){return p(y(this.rgba))},r.prototype.toLchString=function(){return r=p(y(this.rgba)),t=r.l,a=r.c,n=r.h,(u=r.a)<1?"lch("+t+"% "+a+" "+n+" / "+u+")":"lch("+t+"% "+a+" "+n+")";var r,t,a,n,u},t.string.push([s,"lch"]),t.object.push([v,"lch"])};
var r=function(r){return"string"==typeof r?r.length>0:"number"==typeof r},t=function(r,t,a){return void 0===t&&(t=0),void 0===a&&(a=Math.pow(10,t)),Math.round(a*r)/a+0},a=function(r,t,a){return void 0===t&&(t=0),void 0===a&&(a=1),r>a?a:r>t?r:t},n={grad:.9,turn:360,rad:360/(2*Math.PI)},u=function(r){var t=r/255;return t<.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)},h=function(r){return 255*(r>.0031308?1.055*Math.pow(r,1/2.4)-.055:12.92*r)},o=96.422,e=100,c=82.521,i=function(r){var t,n,u={x:.9555766*(t=r).x+-.0230393*t.y+.0631636*t.z,y:-.0282895*t.x+1.0099416*t.y+.0210077*t.z,z:.0122982*t.x+-.020483*t.y+1.3299098*t.z};return n={r:h(.032404542*u.x-.015371385*u.y-.004985314*u.z),g:h(-.00969266*u.x+.018760108*u.y+41556e-8*u.z),b:h(556434e-9*u.x-.002040259*u.y+.010572252*u.z),a:r.a},{r:a(n.r,0,255),g:a(n.g,0,255),b:a(n.b,0,255),a:a(n.a)}},l=function(r){var t=u(r.r),n=u(r.g),h=u(r.b);return function(r){return{x:a(r.x,0,o),y:a(r.y,0,e),z:a(r.z,0,c),a:a(r.a)}}(function(r){return{x:1.0478112*r.x+.0228866*r.y+-.050127*r.z,y:.0295424*r.x+.9904844*r.y+-.0170491*r.z,z:-.0092345*r.x+.0150436*r.y+.7521316*r.z,a:r.a}}({x:100*(.4124564*t+.3575761*n+.1804375*h),y:100*(.2126729*t+.7151522*n+.072175*h),z:100*(.0193339*t+.119192*n+.9503041*h),a:r.a}))},b=216/24389,d=24389/27,f=function(r){return{l:a(r.l,0,100),c:r.c,h:(t=r.h,(t=isFinite(t)?t%360:0)>0?t:t+360),a:r.a};var t},p=function(r){return{l:t(r.l,2),c:t(r.c,2),h:t(r.h,2),a:t(r.a,2)}},v=function(t){var a=t.l,n=t.c,u=t.h,h=t.a,o=void 0===h?1:h;if(!r(a)||!r(n)||!r(u))return null;var e=f({l:Number(a),c:Number(n),h:Number(u),a:Number(o)});return M(e)},y=function(r){var a=function(r){var t=l(r),a=t.x/o,n=t.y/e,u=t.z/c;return a=a>b?Math.cbrt(a):(d*a+16)/116,{l:116*(n=n>b?Math.cbrt(n):(d*n+16)/116)-16,a:500*(a-n),b:200*(n-(u=u>b?Math.cbrt(u):(d*u+16)/116)),alpha:t.a}}(r),n=t(a.a,3),u=t(a.b,3),h=Math.atan2(u,n)/Math.PI*180;return{l:a.l,c:Math.sqrt(n*n+u*u),h:h<0?h+360:h,a:a.alpha}},M=function(r){return t={l:r.l,a:r.c*Math.cos(r.h*Math.PI/180),b:r.c*Math.sin(r.h*Math.PI/180),alpha:r.a},n=t.a/500+(a=(t.l+16)/116),u=a-t.b/200,i({x:(Math.pow(n,3)>b?Math.pow(n,3):(116*n-16)/d)*o,y:(t.l>8?Math.pow((t.l+16)/116,3):t.l/d)*e,z:(Math.pow(u,3)>b?Math.pow(u,3):(116*u-16)/d)*c,a:t.alpha});var t,a,n,u},x=/^lch\(\s*([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)\s+([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,s=function(r){var t=x.exec(r);if(!t)return null;var a,u,h=f({l:Number(t[1]),c:Number(t[2]),h:(a=t[3],u=t[4],void 0===u&&(u="deg"),Number(a)*(n[u]||1)),a:void 0===t[5]?1:Number(t[5])/(t[6]?100:1)});return M(h)};module.exports=function(r,t){r.prototype.toLch=function(){return p(y(this.rgba))},r.prototype.toLchString=function(){return r=p(y(this.rgba)),t=r.l,a=r.c,n=r.h,(u=r.a)<1?"lch("+t+"% "+a+" "+n+" / "+u+")":"lch("+t+"% "+a+" "+n+")";var r,t,a,n,u},t.string.push([s,"lch"]),t.object.push([v,"lch"])};

@@ -1,1 +0,1 @@

module.exports=function(e,f){var a={white:"#ffffff",bisque:"#ffe4c4",blue:"#0000ff",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",antiquewhite:"#faebd7",aqua:"#00ffff",azure:"#f0ffff",whitesmoke:"#f5f5f5",papayawhip:"#ffefd5",plum:"#dda0dd",blanchedalmond:"#ffebcd",black:"#000000",gold:"#ffd700",goldenrod:"#daa520",gainsboro:"#dcdcdc",cornsilk:"#fff8dc",cornflowerblue:"#6495ed",burlywood:"#deb887",aquamarine:"#7fffd4",beige:"#f5f5dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkkhaki:"#bdb76b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",peachpuff:"#ffdab9",darkmagenta:"#8b008b",darkred:"#8b0000",darkorchid:"#9932cc",darkorange:"#ff8c00",darkslateblue:"#483d8b",gray:"#808080",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",deeppink:"#ff1493",deepskyblue:"#00bfff",wheat:"#f5deb3",firebrick:"#b22222",floralwhite:"#fffaf0",ghostwhite:"#f8f8ff",darkviolet:"#9400d3",magenta:"#ff00ff",green:"#008000",dodgerblue:"#1e90ff",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",blueviolet:"#8a2be2",forestgreen:"#228b22",lawngreen:"#7cfc00",indianred:"#cd5c5c",indigo:"#4b0082",fuchsia:"#ff00ff",brown:"#a52a2a",maroon:"#800000",mediumblue:"#0000cd",lightcoral:"#f08080",darkturquoise:"#00ced1",lightcyan:"#e0ffff",ivory:"#fffff0",lightyellow:"#ffffe0",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",linen:"#faf0e6",mediumaquamarine:"#66cdaa",lemonchiffon:"#fffacd",lime:"#00ff00",khaki:"#f0e68c",mediumseagreen:"#3cb371",limegreen:"#32cd32",mediumspringgreen:"#00fa9a",lightskyblue:"#87cefa",lightblue:"#add8e6",midnightblue:"#191970",lightpink:"#ffb6c1",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",mintcream:"#f5fffa",lightslategray:"#778899",lightslategrey:"#778899",navajowhite:"#ffdead",navy:"#000080",mediumvioletred:"#c71585",powderblue:"#b0e0e6",palegoldenrod:"#eee8aa",oldlace:"#fdf5e6",paleturquoise:"#afeeee",mediumturquoise:"#48d1cc",mediumorchid:"#ba55d3",rebeccapurple:"#663399",lightsteelblue:"#b0c4de",mediumslateblue:"#7b68ee",thistle:"#d8bfd8",tan:"#d2b48c",orchid:"#da70d6",mediumpurple:"#9370db",purple:"#800080",pink:"#ffc0cb",skyblue:"#87ceeb",springgreen:"#00ff7f",palegreen:"#98fb98",red:"#ff0000",yellow:"#ffff00",slateblue:"#6a5acd",lavenderblush:"#fff0f5",peru:"#cd853f",palevioletred:"#db7093",violet:"#ee82ee",teal:"#008080",slategray:"#708090",slategrey:"#708090",aliceblue:"#f0f8ff",darkseagreen:"#8fbc8f",darkolivegreen:"#556b2f",greenyellow:"#adff2f",seagreen:"#2e8b57",seashell:"#fff5ee",tomato:"#ff6347",silver:"#c0c0c0",sienna:"#a0522d",lavender:"#e6e6fa",lightgreen:"#90ee90",orange:"#ffa500",orangered:"#ff4500",steelblue:"#4682b4",royalblue:"#4169e1",turquoise:"#40e0d0",yellowgreen:"#9acd32",salmon:"#fa8072",saddlebrown:"#8b4513",sandybrown:"#f4a460",rosybrown:"#bc8f8f",darksalmon:"#e9967a",lightgoldenrodyellow:"#fafad2",snow:"#fffafa",lightgrey:"#d3d3d3",lightgray:"#d3d3d3",dimgray:"#696969",dimgrey:"#696969",olivedrab:"#6b8e23",olive:"#808000"},d={};for(var r in a)d[a[r]]=r;e.prototype.toName=function(){return 0===this.rgba.a?"transparent":d[this.toHex()]||void 0};f.string.push([function(f){var d=f.trim().toLowerCase(),r="transparent"===d?"#0000":a[d];return r?new e(r).toRgb():null},"name"])};
module.exports=function(e,f){var a={white:"#ffffff",bisque:"#ffe4c4",blue:"#0000ff",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",antiquewhite:"#faebd7",aqua:"#00ffff",azure:"#f0ffff",whitesmoke:"#f5f5f5",papayawhip:"#ffefd5",plum:"#dda0dd",blanchedalmond:"#ffebcd",black:"#000000",gold:"#ffd700",goldenrod:"#daa520",gainsboro:"#dcdcdc",cornsilk:"#fff8dc",cornflowerblue:"#6495ed",burlywood:"#deb887",aquamarine:"#7fffd4",beige:"#f5f5dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkkhaki:"#bdb76b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",peachpuff:"#ffdab9",darkmagenta:"#8b008b",darkred:"#8b0000",darkorchid:"#9932cc",darkorange:"#ff8c00",darkslateblue:"#483d8b",gray:"#808080",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",deeppink:"#ff1493",deepskyblue:"#00bfff",wheat:"#f5deb3",firebrick:"#b22222",floralwhite:"#fffaf0",ghostwhite:"#f8f8ff",darkviolet:"#9400d3",magenta:"#ff00ff",green:"#008000",dodgerblue:"#1e90ff",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",blueviolet:"#8a2be2",forestgreen:"#228b22",lawngreen:"#7cfc00",indianred:"#cd5c5c",indigo:"#4b0082",fuchsia:"#ff00ff",brown:"#a52a2a",maroon:"#800000",mediumblue:"#0000cd",lightcoral:"#f08080",darkturquoise:"#00ced1",lightcyan:"#e0ffff",ivory:"#fffff0",lightyellow:"#ffffe0",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",linen:"#faf0e6",mediumaquamarine:"#66cdaa",lemonchiffon:"#fffacd",lime:"#00ff00",khaki:"#f0e68c",mediumseagreen:"#3cb371",limegreen:"#32cd32",mediumspringgreen:"#00fa9a",lightskyblue:"#87cefa",lightblue:"#add8e6",midnightblue:"#191970",lightpink:"#ffb6c1",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",mintcream:"#f5fffa",lightslategray:"#778899",lightslategrey:"#778899",navajowhite:"#ffdead",navy:"#000080",mediumvioletred:"#c71585",powderblue:"#b0e0e6",palegoldenrod:"#eee8aa",oldlace:"#fdf5e6",paleturquoise:"#afeeee",mediumturquoise:"#48d1cc",mediumorchid:"#ba55d3",rebeccapurple:"#663399",lightsteelblue:"#b0c4de",mediumslateblue:"#7b68ee",thistle:"#d8bfd8",tan:"#d2b48c",orchid:"#da70d6",mediumpurple:"#9370db",purple:"#800080",pink:"#ffc0cb",skyblue:"#87ceeb",springgreen:"#00ff7f",palegreen:"#98fb98",red:"#ff0000",yellow:"#ffff00",slateblue:"#6a5acd",lavenderblush:"#fff0f5",peru:"#cd853f",palevioletred:"#db7093",violet:"#ee82ee",teal:"#008080",slategray:"#708090",slategrey:"#708090",aliceblue:"#f0f8ff",darkseagreen:"#8fbc8f",darkolivegreen:"#556b2f",greenyellow:"#adff2f",seagreen:"#2e8b57",seashell:"#fff5ee",tomato:"#ff6347",silver:"#c0c0c0",sienna:"#a0522d",lavender:"#e6e6fa",lightgreen:"#90ee90",orange:"#ffa500",orangered:"#ff4500",steelblue:"#4682b4",royalblue:"#4169e1",turquoise:"#40e0d0",yellowgreen:"#9acd32",salmon:"#fa8072",saddlebrown:"#8b4513",sandybrown:"#f4a460",rosybrown:"#bc8f8f",darksalmon:"#e9967a",lightgoldenrodyellow:"#fafad2",snow:"#fffafa",lightgrey:"#d3d3d3",lightgray:"#d3d3d3",dimgray:"#696969",dimgrey:"#696969",olivedrab:"#6b8e23",olive:"#808000"},r={};for(var d in a)r[a[d]]=d;e.prototype.toName=function(){return this.rgba.a||this.rgba.r||this.rgba.g||this.rgba.b?r[this.toHex()]||void 0:"transparent"};f.string.push([function(f){var r=f.toLowerCase(),d="transparent"===r?"#0000":a[r];return d?new e(d).toRgb():null},"name"])};

@@ -31,3 +31,3 @@ <div align="center">

- 📦 **Small**: Just **1.5 KB** gzipped ([3x+ lighter](#benchmarks) than **color** and **tinycolor2**)
- 📦 **Small**: Just **1.6 KB** gzipped ([3x+ lighter](#benchmarks) than **color** and **tinycolor2**)
- 🚀 **Fast**: [3x+ faster](#benchmarks) than **color** and **tinycolor2**

@@ -95,3 +95,3 @@ - 😍 **Simple**: Chainable API and familiar patterns

Parses the given input and creates a new Colord instance.
Parses the given input and creates a new Colord instance. String parsing strictly conforms to [CSS Color Level Specifications](https://www.w3.org/TR/css-color-4/#color-type).

@@ -106,5 +106,7 @@ ```js

colord("rgb(255, 255, 255)");
colord("rgba(255, 255, 255, 1)");
colord("hsl(0, 100%, 100%)");
colord("hsla(0, 100%, 100%, 1)");
colord("rgba(255, 255, 255, 0.5)");
colord("rgba(100% 100% 100% / 50%)");
colord("hsl(90, 100%, 100%)");
colord("hsla(90, 100%, 100%, 0.5)");
colord("hsla(90deg 100% 100% / 50%)");
colord("tomato"); // requires "names" plugin

@@ -123,13 +125,2 @@

#### Permissive parser
The parser of the library is user-friendly: it trims unnecessary whitespaces, clamps numbers, disregards character case, punctuation, brackets, etc. Here are some examples:
```js
colord(" aBc ").toHex(); // "#aabbcc"
colord("__rGbA 10 20,, 999...").toRgbString(); // "rgb(10, 20, 255)"
colord(" hsL( -10, 200% 30 .5!!!").toHslString(); // "hsla(350, 100%, 30%, 0.5)"
colord({ r: NaN, g: -Infinity, b: +Infinity, a: 100500 }).toRgb(); // { r: 0, g: 0, b: 255, a: 1 }
```
</details>

@@ -271,5 +262,5 @@

colord("#999966").toHwbString(); // "hwb(60, 40%, 40%)"
colord("#99ffff").toHwbString(); // "hwb(180, 60%, 0%)"
colord("#003366").alpha(0.5).toHwbString(); // "hwb(210, 0%, 60%, 0.5)"
colord("#999966").toHwbString(); // "hwb(60 40% 40%)"
colord("#99ffff").toHwbString(); // "hwb(180 60% 0%)"
colord("#003366").alpha(0.5).toHwbString(); // "hwb(210 0% 60% / 0.5)"
```

@@ -276,0 +267,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc