Socket
Socket
Sign inDemoInstall

colord

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

colord - npm Package Compare versions

Comparing version 0.6.1 to 0.6.2

30

dist/colord.d.ts

@@ -6,17 +6,17 @@ import { AnyColor, RgbaColor, HslaColor, HsvaColor } from "./types";

/** Returns a color brightness ratio */
brightness: () => number;
isDark: () => boolean;
isLight: () => boolean;
toHex: () => string;
toRgba: () => RgbaColor;
toRgbaString: () => string;
toHsla: () => HslaColor;
toHslaString: () => string;
toHsva: () => HsvaColor;
invert: () => Colord;
saturate: (ratio?: number) => Colord;
desaturate: (ratio?: number) => Colord;
grayscale: () => Colord;
lighten: (ratio?: number) => Colord;
darken: (ratio?: number) => Colord;
brightness(): number;
isDark(): boolean;
isLight(): boolean;
toHex(): string;
toRgba(): RgbaColor;
toRgbaString(): string;
toHsla(): HslaColor;
toHslaString(): string;
toHsva(): HsvaColor;
invert(): Colord;
saturate(ratio?: number): Colord;
desaturate(ratio?: number): Colord;
grayscale(): Colord;
lighten(ratio?: number): Colord;
darken(ratio?: number): Colord;
/** Allows to get or change an alpha channel value */

@@ -23,0 +23,0 @@ alpha(): number;

@@ -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},t=function(r,n,t){return void 0===n&&(n=0),void 0===t&&(t=1),r>t?t:r<n?n:r},u=function(r){var n=r.g,u=r.b,a=r.a;return{r:t(r.r,0,255),g:t(n,0,255),b:t(u,0,255),a:t(a)}},a=function(r){return{r:n(r.r),g:n(r.g),b:n(r.b),a:n(r.a,2)}},e=/^\s*#?([0-9A-F]{3,4}){1,2}\s*$/i,i=function(r){var n=r.toString(16);return n.length<2?"0"+n:n},s=function(r){var t=r.r,u=r.g,a=r.b,e=r.a,i=Math.max(t,u,a),s=i-Math.min(t,u,a),o=s?i===t?(u-a)/s:i===u?2+(a-t)/s:4+(t-u)/s:0;return{h:n(60*(o<0?o+6:o)),s:n(i?s/i*100:0),v:n(i/255*100),a:e}},o=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),i=u*(1-t),s=u*(1-(n-e)*t),o=u*(1-(1-n+e)*t),b=e%6;return{r:255*[u,s,i,i,o,u][b],g:255*[o,u,u,s,i,i][b],b:255*[i,i,o,u,u,s][b],a:a}},b=function(r){var n=r.s,u=r.l,a=r.a;return{h:t(r.h,0,360),s:t(n,0,100),l:t(u,0,100),a:t(a)}},f=function(r){return o((t=(n=r).s,{h:n.h,s:(t*=((u=n.l)<50?u:100-u)/100)>0?2*t/(u+t)*100:0,v:u+t,a:n.a}));var n,t,u},g=function(r){return t=s(r),e=t.a,i=(200-(u=t.s))*(a=t.v)/100,{h:n(t.h),s:n(i>0&&i<200?u*a/100/(i<=100?i:200-i)*100:0),l:n(i/2),a:n(e,2)};var t,u,a,e,i},h=/hsla?\(?s*(-?\d+\.?\d*),?\s*(-?\d+\.?\d*)%?,?\s*(-?\d+\.?\d*)%?,?\s*(-?\d*\.?\d+)?s*\)?/i,c=/rgba?\(?\s*(-?\d+),?\s*(-?\d+),?\s*(-?\d+),?\s*(-?\d*\.?\d+)?\s*\)?/i,v={string:[function(r){return e.test(r)?(r=r.replace("#","").trim()).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}:{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},function(r){var n=c.exec(r);return n?u({r:Number(n[1]),g:Number(n[2]),b:Number(n[3]),a:void 0===n[4]?1:Number(n[4])}):null},function(r){var n=h.exec(r);if(!n)return null;var t=b({h:Number(n[1]),s:Number(n[2]),l:Number(n[3]),a:void 0===n[4]?1:Number(n[4])});return f(t)}],object:[function(n){var t=n.r,a=n.g,e=n.b,i=n.a,s=void 0===i?1:i;return r(t)&&r(a)&&r(e)?u({r:Number(t),g:Number(a),b:Number(e),a:Number(s)}):null},function(n){var t=n.h,u=n.s,a=n.l,e=n.a,i=void 0===e?1:e;if(!r(t)||!r(u)||!r(a))return null;var s=b({h:Number(t),s:Number(u),l:Number(a),a:Number(i)});return f(s)},function(n){var u=n.h,a=n.s,e=n.v,i=n.a,s=void 0===i?1:i;if(!r(u)||!r(a)||!r(e))return null;var b=function(r){var n=r.s,u=r.v,a=r.a;return{h:t(r.h,0,360),s:t(n,0,100),v:t(u,0,100),a:t(a)}}({h:Number(u),s:Number(a),v:Number(e),a:Number(s)});return o(b)}]},l=function(r,n){for(var t=0;t<n.length;t++){var u=n[t](r);if(u)return u}return null},d=function(r,n){var u=g(r),a=u.l,e=u.a;return{h:u.h,s:t(u.s+100*n,0,100),l:a,a:e}},m=function(r){return(299*r.r+587*r.g+114*r.b)/1e3/255},p=function(r,n){var u=g(r),a=u.a;return{h:u.h,s:u.s,l:t(u.l+100*n,0,100),a:a}},N=function(){function r(r){var t=this;this.brightness=function(){return n(m(t.rgba),2)},this.isDark=function(){return m(t.rgba)<.5},this.isLight=function(){return m(t.rgba)>=.5},this.toHex=function(){return r=a(t.rgba),u=r.r,e=r.g,s=r.b,b=(o=r.a)<1?i(n(255*o)):"","#"+i(u)+i(e)+i(s)+b;var r,u,e,s,o,b},this.toRgba=function(){return a(t.rgba)},this.toRgbaString=function(){return"rgba("+(r=a(t.rgba)).r+", "+r.g+", "+r.b+", "+r.a+")";var r},this.toHsla=function(){return g(t.rgba)},this.toHslaString=function(){return"hsla("+(r=g(t.rgba)).h+", "+r.s+"%, "+r.l+"%, "+r.a+")";var r},this.toHsva=function(){return s(t.rgba)},this.invert=function(){return I({r:255-(r=t.rgba).r,g:255-r.g,b:255-r.b,a:r.a});var r},this.saturate=function(r){return void 0===r&&(r=.1),I(d(t.rgba,r))},this.desaturate=function(r){return void 0===r&&(r=.1),I(d(t.rgba,-r))},this.grayscale=function(){return I(d(t.rgba,-1))},this.lighten=function(r){return void 0===r&&(r=.1),I(p(t.rgba,r))},this.darken=function(r){return void 0===r&&(r=.1),I(p(t.rgba,-r))},this.rgba=function(r){return"string"==typeof r?l(r,v.string):"object"==typeof r?l(r,v.object):null}(r)||{r:0,g:0,b:0,a:1}}return r.prototype.alpha=function(r){return"number"==typeof r?I({r:(t=this.rgba).r,g:t.g,b:t.b,a:r}):n(this.rgba.a,2);var t},r}(),I=function(r){return r instanceof N?r:new N(r)},y=[],x=function(r){r.forEach(function(r){y.indexOf(r)<0&&(r(N,v),y.push(r))})};export{N as Colord,I as colord,x as extend};
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},n=function(r,t,n){return void 0===t&&(t=0),void 0===n&&(n=1),r>n?n:r<t?t:r},u=function(r){var t=r.g,u=r.b,e=r.a;return{r:n(r.r,0,255),g:n(t,0,255),b:n(u,0,255),a:n(e)}},e=function(r){return{r:t(r.r),g:t(r.g),b:t(r.b),a:t(r.a,2)}},a=/^\s*#?([0-9A-F]{3,4}){1,2}\s*$/i,o=function(r){var t=r.toString(16);return t.length<2?"0"+t:t},i=function(r){var n=r.r,u=r.g,e=r.b,a=r.a,o=Math.max(n,u,e),i=o-Math.min(n,u,e),s=i?o===n?(u-e)/i:o===u?2+(e-n)/i:4+(n-u)/i:0;return{h:t(60*(s<0?s+6:s)),s:t(o?i/o*100:0),v:t(o/255*100),a:a}},s=function(r){var t=r.h,n=r.s,u=r.v,e=r.a;t=t/360*6,n/=100,u/=100;var a=Math.floor(t),o=u*(1-n),i=u*(1-(t-a)*n),s=u*(1-(1-t+a)*n),b=a%6;return{r:255*[u,i,o,o,s,u][b],g:255*[s,u,u,i,o,o][b],b:255*[o,o,s,u,u,i][b],a:e}},b=function(r){var t=r.s,u=r.l,e=r.a;return{h:n(r.h,0,360),s:n(t,0,100),l:n(u,0,100),a:n(e)}},f=function(r){return s((n=(t=r).s,{h:t.h,s:(n*=((u=t.l)<50?u:100-u)/100)>0?2*n/(u+n)*100:0,v:u+n,a:t.a}));var t,n,u},g=function(r){return n=i(r),a=n.a,o=(200-(u=n.s))*(e=n.v)/100,{h:t(n.h),s:t(o>0&&o<200?u*e/100/(o<=100?o:200-o)*100:0),l:t(o/2),a:t(a,2)};var n,u,e,a,o},h=/hsla?\(?s*(-?\d+\.?\d*),?\s*(-?\d+\.?\d*)%?,?\s*(-?\d+\.?\d*)%?,?\s*(-?\d*\.?\d+)?s*\)?/i,c=/rgba?\(?\s*(-?\d+),?\s*(-?\d+),?\s*(-?\d+),?\s*(-?\d*\.?\d+)?\s*\)?/i,p={string:[function(r){return a.test(r)?(r=r.replace("#","").trim()).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}:{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},function(r){var t=c.exec(r);return t?u({r:Number(t[1]),g:Number(t[2]),b:Number(t[3]),a:void 0===t[4]?1:Number(t[4])}):null},function(r){var t=h.exec(r);if(!t)return null;var n=b({h:Number(t[1]),s:Number(t[2]),l:Number(t[3]),a:void 0===t[4]?1:Number(t[4])});return f(n)}],object:[function(t){var n=t.r,e=t.g,a=t.b,o=t.a,i=void 0===o?1:o;return r(n)&&r(e)&&r(a)?u({r:Number(n),g:Number(e),b:Number(a),a:Number(i)}):null},function(t){var n=t.h,u=t.s,e=t.l,a=t.a,o=void 0===a?1:a;if(!r(n)||!r(u)||!r(e))return null;var i=b({h:Number(n),s:Number(u),l:Number(e),a:Number(o)});return f(i)},function(t){var u=t.h,e=t.s,a=t.v,o=t.a,i=void 0===o?1:o;if(!r(u)||!r(e)||!r(a))return null;var b=function(r){var t=r.s,u=r.v,e=r.a;return{h:n(r.h,0,360),s:n(t,0,100),v:n(u,0,100),a:n(e)}}({h:Number(u),s:Number(e),v:Number(a),a:Number(i)});return s(b)}]},v=function(r,t){for(var n=0;n<t.length;n++){var u=t[n](r);if(u)return u}return null},l=function(r,t){var u=g(r),e=u.l,a=u.a;return{h:u.h,s:n(u.s+100*t,0,100),l:e,a:a}},d=function(r){return(299*r.r+587*r.g+114*r.b)/1e3/255},m=function(r,t){var u=g(r),e=u.a;return{h:u.h,s:u.s,l:n(u.l+100*t,0,100),a:e}},y=function(){function r(r){this.rgba=function(r){return"string"==typeof r?v(r,p.string):"object"==typeof r?v(r,p.object):null}(r)||{r:0,g:0,b:0,a:1}}return r.prototype.brightness=function(){return t(d(this.rgba),2)},r.prototype.isDark=function(){return d(this.rgba)<.5},r.prototype.isLight=function(){return d(this.rgba)>=.5},r.prototype.toHex=function(){return r=e(this.rgba),n=r.r,u=r.g,a=r.b,s=(i=r.a)<1?o(t(255*i)):"","#"+o(n)+o(u)+o(a)+s;var r,n,u,a,i,s},r.prototype.toRgba=function(){return e(this.rgba)},r.prototype.toRgbaString=function(){return"rgba("+(r=e(this.rgba)).r+", "+r.g+", "+r.b+", "+r.a+")";var r},r.prototype.toHsla=function(){return g(this.rgba)},r.prototype.toHslaString=function(){return"hsla("+(r=g(this.rgba)).h+", "+r.s+"%, "+r.l+"%, "+r.a+")";var r},r.prototype.toHsva=function(){return i(this.rgba)},r.prototype.invert=function(){return N({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),N(l(this.rgba,r))},r.prototype.desaturate=function(r){return void 0===r&&(r=.1),N(l(this.rgba,-r))},r.prototype.grayscale=function(){return N(l(this.rgba,-1))},r.prototype.lighten=function(r){return void 0===r&&(r=.1),N(m(this.rgba,r))},r.prototype.darken=function(r){return void 0===r&&(r=.1),N(m(this.rgba,-r))},r.prototype.alpha=function(r){return"number"==typeof r?N({r:(n=this.rgba).r,g:n.g,b:n.b,a:r}):t(this.rgba.a,2);var n},r}(),N=function(r){return r instanceof y?r:new y(r)},I=[],x=function(r){r.forEach(function(r){I.indexOf(r)<0&&(r(y,p),I.push(r))})};export{y as Colord,N as colord,x as extend};
{
"name": "colord",
"version": "0.6.1",
"version": "0.6.2",
"description": "👑 A tiny yet powerful tool for high-performance color manipulations and conversions",

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

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

- 📦 **Small**: Just **1.4 KB** gzipped ([3+ times lighter](#benchmarks) than **color** and **tinycolor2**)
- 🚀 **Fast**: [~60% faster](#benchmarks) than **color** and **tinycolor2**
- 🚀 **Fast**: [2+ times faster](#benchmarks) than **color** and **tinycolor2**
- 😍 **Simple**: Chainable API and familiar patterns

@@ -46,9 +46,9 @@ - 💪 **Immutable**: No need to worry about data mutations

| Library | <nobr>Operations/sec</nobr> | Size | Size (gzip) | Dependencies | Types |
| ----------------------------- | ----------------------------- | -------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| <nobr><b>colord 👑</b></nobr> | <nobr><b>1 777 141</b></nobr> | [![](https://badgen.net/bundlephobia/min/colord?color=6ead0a&label=)](https://bundlephobia.com/result?p=colord) | [![](https://badgen.net/bundlephobia/minzip/colord?color=6ead0a&label=)](https://bundlephobia.com/result?p=colord) | [![](https://badgen.net/bundlephobia/dependency-count/colord?color=6ead0a&label=)](https://bundlephobia.com/result?p=colord) | [![](https://badgen.net/npm/types/colord?color=6ead0a&label=)](https://bundlephobia.com/result?p=colord) |
| color | 695 347 | [![](https://badgen.net/bundlephobia/min/color?color=red&label=)](https://bundlephobia.com/result?p=color) | [![](https://badgen.net/bundlephobia/minzip/color?color=red&label=)](https://bundlephobia.com/result?p=color) | [![](https://badgen.net/bundlephobia/dependency-count/color?color=red&label=)](https://bundlephobia.com/result?p=color) | [![](https://badgen.net/npm/types/color?color=red&label=)](https://bundlephobia.com/result?p=color) |
| tinycolor2 | 978 212 | [![](https://badgen.net/bundlephobia/min/tinycolor2?color=red&label=)](https://bundlephobia.com/result?p=tinycolor2) | [![](https://badgen.net/bundlephobia/minzip/tinycolor2?color=red&label=)](https://bundlephobia.com/result?p=tinycolor2) | [![](https://badgen.net/bundlephobia/dependency-count/tinycolor2?color=red&label=)](https://bundlephobia.com/result?p=tinycolor2) | [![](https://badgen.net/npm/types/tinycolor2?color=red&label=)](https://bundlephobia.com/result?p=tinycolor2) |
| ac-colors | 666 946 | [![](https://badgen.net/bundlephobia/min/ac-colors?color=red&label=)](https://bundlephobia.com/result?p=ac-colors) | [![](https://badgen.net/bundlephobia/minzip/ac-colors?color=red&label=)](https://bundlephobia.com/result?p=ac-colors) | [![](https://badgen.net/bundlephobia/dependency-count/ac-colors?color=red&label=)](https://bundlephobia.com/result?p=ac-colors) | [![](https://badgen.net/npm/types/ac-colors?color=red&label=)](https://bundlephobia.com/result?p=ac-colors) |
| chroma-js | 888 784 | [![](https://badgen.net/bundlephobia/min/chroma-js?color=red&label=)](https://bundlephobia.com/result?p=chroma-js) | [![](https://badgen.net/bundlephobia/minzip/chroma-js?color=red&label=)](https://bundlephobia.com/result?p=chroma-js) | [![](https://badgen.net/bundlephobia/dependency-count/chroma-js?color=red&label=)](https://bundlephobia.com/result?p=chroma-js) | [![](https://badgen.net/npm/types/chroma-js?color=red&label=)](https://bundlephobia.com/result?p=chroma-js) |
| Library | <nobr>Operations/sec</nobr> | Size | Size (gzip) | Dependencies | Types |
| ----------------------------- | ----------------------------- | --------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------- |
| <nobr><b>colord 👑</b></nobr> | <nobr><b>2 274 420</b></nobr> | [![](https://badgen.net/bundlephobia/min/colord?color=6ead0a&label=)](https://bundlephobia.com/result?p=colord) | [![](https://badgen.net/bundlephobia/minzip/colord?color=6ead0a&label=)](https://bundlephobia.com/result?p=colord) | [![](https://badgen.net/bundlephobia/dependency-count/colord?color=6ead0a&label=)](https://bundlephobia.com/result?p=colord) | [![](https://badgen.net/npm/types/colord?color=6ead0a&label=)](https://bundlephobia.com/result?p=colord) |
| color | 717 048 | [![](https://badgen.net/bundlephobia/min/color?color=red&label=)](https://bundlephobia.com/result?p=color) | [![](https://badgen.net/bundlephobia/minzip/color?color=red&label=)](https://bundlephobia.com/result?p=color) | [![](https://badgen.net/bundlephobia/dependency-count/color?color=red&label=)](https://bundlephobia.com/result?p=color) | [![](https://badgen.net/npm/types/color?color=e6591d&label=)](https://bundlephobia.com/result?p=color) |
| tinycolor2 | 956 285 | [![](https://badgen.net/bundlephobia/min/tinycolor2?color=red&label=)](https://bundlephobia.com/result?p=tinycolor2) | [![](https://badgen.net/bundlephobia/minzip/tinycolor2?color=red&label=)](https://bundlephobia.com/result?p=tinycolor2) | [![](https://badgen.net/bundlephobia/dependency-count/tinycolor2?color=6ead0a&label=)](https://bundlephobia.com/result?p=tinycolor2) | [![](https://badgen.net/npm/types/tinycolor2?color=e6591d&label=)](https://bundlephobia.com/result?p=tinycolor2) |
| ac-colors | 637 469 | [![](https://badgen.net/bundlephobia/min/ac-colors?color=e6591d&label=)](https://bundlephobia.com/result?p=ac-colors) | [![](https://badgen.net/bundlephobia/minzip/ac-colors?color=e6591d&label=)](https://bundlephobia.com/result?p=ac-colors) | [![](https://badgen.net/bundlephobia/dependency-count/ac-colors?color=6ead0a&label=)](https://bundlephobia.com/result?p=ac-colors) | [![](https://badgen.net/npm/types/ac-colors?color=red&label=)](https://bundlephobia.com/result?p=ac-colors) |
| chroma-js | 900 826 | [![](https://badgen.net/bundlephobia/min/chroma-js?color=red&label=)](https://bundlephobia.com/result?p=chroma-js) | [![](https://badgen.net/bundlephobia/minzip/chroma-js?color=red&label=)](https://bundlephobia.com/result?p=chroma-js) | [![](https://badgen.net/bundlephobia/dependency-count/chroma-js?color=red&label=)](https://bundlephobia.com/result?p=chroma-js) | [![](https://badgen.net/npm/types/chroma-js?color=e6591d&label=)](https://bundlephobia.com/result?p=chroma-js) |

@@ -198,4 +198,7 @@ The performance results were generated on a MBP 2019, 2,6 GHz Intel Core i7 via running `npm run benchmark` in the library folder. See [tests/benchmark.ts](https://github.com/omgovich/colord/blob/master/tests/benchmark.ts).

- [x] CSS color names (via plugin)
- [ ] 🚧 Mix colors (via plugin)
- [ ] A11y and contrast utils (via plugin)
- [ ] Mix colors (via plugin)
- [ ] [LCH](https://www.w3.org/TR/css-color-4/#specifying-lab-lch) color space (via plugin)
- [ ] CMYK color space (via plugin)
- [ ] XYZ color space (via plugin)
- [ ] [LAB](https://www.w3.org/TR/css-color-4/#resolving-lab-lch-values) color space (via plugin)
- [ ] [LCH](https://lea.verou.me/2020/04/lch-colors-in-css-what-why-and-how/) color space (via plugin)
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc