You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
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

Comparing version 1.4.1 to 1.5.0

random.d.ts

4

CHANGELOG.md

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

### 1.5.0
- New utility: Random color generation
### 1.4.1

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

export { colord, Colord } from "./colord";
export { extend, Plugin } from "./extend";
export { random } from "./random";
export { HslColor, HslaColor, HsvColor, HsvaColor, HwbColor, HwbaColor, LabColor, LabaColor, LchColor, LchaColor, RgbColor, RgbaColor, XyzColor, XyzaColor, AnyColor, } from "./types";

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},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:n(r.r,0,255),g:n(r.g,0,255),b:n(r.b,0,255),a:n(r.a)}},u=function(r){return{r:t(r.r),g:t(r.g),b:t(r.b),a:t(r.a,2)}},o=/^\s*#?([0-9a-f]{3,8})\s*$/i,a=function(r){var t=r.toString(16);return t.length<2?"0"+t:t},i=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}},s=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}},b=function(r){return{h:n(r.h,0,360),s:n(r.s,0,100),l:n(r.l,0,100),a:n(r.a)}},h=function(r){return{h:t(r.h),s:t(r.s),l:t(r.l),a:t(r.a,2)}},f=function(r){return s((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},g=function(r){return{h:(t=i(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},l=/hsla?\(?\s*(-?\d+\.?\d*)(deg)?[,\s]+(-?\d+\.?\d*)%?[,\s]+(-?\d+\.?\d*)%?,?\s*[/\s]*(-?\d*\.?\d+)?(%)?\s*\)?/i,p=/rgba?\(?\s*(-?\d+\.?\d*)(%)?[,\s]+(-?\d+\.?\d*)(%)?[,\s]+(-?\d+\.?\d*)(%)?,?\s*[/\s]*(-?\d*\.?\d+)?(%)?\s*\)?/i,c={string:[function(r){var t=o.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},function(r){var t=p.exec(r);return t?e({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},function(r){var t=l.exec(r);if(!t)return null;var n=b({h:Number(t[1]),s:Number(t[3]),l:Number(t[4]),a:void 0===t[5]?1:Number(t[5])/(t[6]?100:1)});return f(n)}],object:[function(t){var n=t.r,u=t.g,o=t.b,a=t.a,i=void 0===a?1:a;return r(n)&&r(u)&&r(o)?e({r:Number(n),g:Number(u),b:Number(o),a:Number(i)}):null},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=b({h:Number(n),s:Number(e),l:Number(u),a:Number(a)});return f(i)},function(t){var e=t.h,u=t.s,o=t.v,a=t.a,i=void 0===a?1:a;if(!r(e)||!r(u)||!r(o))return null;var b=function(r){return{h:n(r.h,0,360),s:n(r.s,0,100),v:n(r.v,0,100),a:n(r.a)}}({h:Number(e),s:Number(u),v:Number(o),a:Number(i)});return s(b)}]},v=function(r,t){for(var n=0;n<t.length;n++){var e=t[n](r);if(e)return e}return null},d=function(r,t){var e=g(r);return{h:e.h,s:n(e.s+100*t,0,100),l:e.l,a:e.a}},m=function(r){return(299*r.r+587*r.g+114*r.b)/1e3/255},y=function(r,t){var e=g(r);return{h:e.h,s:e.s,l:n(e.l+100*t,0,100),a:e.a}},N=function(){function r(r){this.parsed=function(r){return"string"==typeof r?v(r,c.string):"object"==typeof r&&null!==r?v(r,c.object):null}(r),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(m(this.rgba),2)},r.prototype.isDark=function(){return m(this.rgba)<.5},r.prototype.isLight=function(){return m(this.rgba)>=.5},r.prototype.toHex=function(){return r=u(this.rgba),n=r.r,e=r.g,o=r.b,s=(i=r.a)<1?a(t(255*i)):"","#"+a(n)+a(e)+a(o)+s;var r,n,e,o,i,s},r.prototype.toRgb=function(){return u(this.rgba)},r.prototype.toRgbString=function(){return r=u(this.rgba),t=r.r,n=r.g,e=r.b,(o=r.a)<1?"rgba("+t+", "+n+", "+e+", "+o+")":"rgb("+t+", "+n+", "+e+")";var r,t,n,e,o},r.prototype.toHsl=function(){return h(g(this.rgba))},r.prototype.toHslString=function(){return r=h(g(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=i(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 x({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),x(d(this.rgba,r))},r.prototype.desaturate=function(r){return void 0===r&&(r=.1),x(d(this.rgba,-r))},r.prototype.grayscale=function(){return x(d(this.rgba,-1))},r.prototype.lighten=function(r){return void 0===r&&(r=.1),x(y(this.rgba,r))},r.prototype.darken=function(r){return void 0===r&&(r=.1),x(y(this.rgba,-r))},r.prototype.alpha=function(r){return"number"==typeof r?x({r:(n=this.rgba).r,g:n.g,b:n.b,a:r}):t(this.rgba.a,2);var n},r}(),x=function(r){return r instanceof N?r:new N(r)},I=[];exports.Colord=N,exports.colord=x,exports.extend=function(r){r.forEach(function(r){I.indexOf(r)<0&&(r(N,c),I.push(r))})};
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},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:n(r.r,0,255),g:n(r.g,0,255),b:n(r.b,0,255),a:n(r.a)}},u=function(r){return{r:t(r.r),g:t(r.g),b:t(r.b),a:t(r.a,2)}},o=/^\s*#?([0-9a-f]{3,8})\s*$/i,a=function(r){var t=r.toString(16);return t.length<2?"0"+t:t},i=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}},s=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}},b=function(r){return{h:n(r.h,0,360),s:n(r.s,0,100),l:n(r.l,0,100),a:n(r.a)}},h=function(r){return{h:t(r.h),s:t(r.s),l:t(r.l),a:t(r.a,2)}},f=function(r){return s((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},g=function(r){return{h:(t=i(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)?[,\s]+(-?\d+\.?\d*)%?[,\s]+(-?\d+\.?\d*)%?,?\s*[/\s]*(-?\d*\.?\d+)?(%)?\s*\)?/i,c=/rgba?\(?\s*(-?\d+\.?\d*)(%)?[,\s]+(-?\d+\.?\d*)(%)?[,\s]+(-?\d+\.?\d*)(%)?,?\s*[/\s]*(-?\d*\.?\d+)?(%)?\s*\)?/i,l={string:[function(r){var t=o.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},function(r){var t=c.exec(r);return t?e({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},function(r){var t=p.exec(r);if(!t)return null;var n=b({h:Number(t[1]),s:Number(t[3]),l:Number(t[4]),a:void 0===t[5]?1:Number(t[5])/(t[6]?100:1)});return f(n)}],object:[function(t){var n=t.r,u=t.g,o=t.b,a=t.a,i=void 0===a?1:a;return r(n)&&r(u)&&r(o)?e({r:Number(n),g:Number(u),b:Number(o),a:Number(i)}):null},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=b({h:Number(n),s:Number(e),l:Number(u),a:Number(a)});return f(i)},function(t){var e=t.h,u=t.s,o=t.v,a=t.a,i=void 0===a?1:a;if(!r(e)||!r(u)||!r(o))return null;var b=function(r){return{h:n(r.h,0,360),s:n(r.s,0,100),v:n(r.v,0,100),a:n(r.a)}}({h:Number(e),s:Number(u),v:Number(o),a:Number(i)});return s(b)}]},v=function(r,t){for(var n=0;n<t.length;n++){var e=t[n](r);if(e)return e}return null},d=function(r,t){var e=g(r);return{h:e.h,s:n(e.s+100*t,0,100),l:e.l,a:e.a}},m=function(r){return(299*r.r+587*r.g+114*r.b)/1e3/255},y=function(r,t){var e=g(r);return{h:e.h,s:e.s,l:n(e.l+100*t,0,100),a:e.a}},N=function(){function r(r){this.parsed=function(r){return"string"==typeof r?v(r,l.string):"object"==typeof r&&null!==r?v(r,l.object):null}(r),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(m(this.rgba),2)},r.prototype.isDark=function(){return m(this.rgba)<.5},r.prototype.isLight=function(){return m(this.rgba)>=.5},r.prototype.toHex=function(){return r=u(this.rgba),n=r.r,e=r.g,o=r.b,s=(i=r.a)<1?a(t(255*i)):"","#"+a(n)+a(e)+a(o)+s;var r,n,e,o,i,s},r.prototype.toRgb=function(){return u(this.rgba)},r.prototype.toRgbString=function(){return r=u(this.rgba),t=r.r,n=r.g,e=r.b,(o=r.a)<1?"rgba("+t+", "+n+", "+e+", "+o+")":"rgb("+t+", "+n+", "+e+")";var r,t,n,e,o},r.prototype.toHsl=function(){return h(g(this.rgba))},r.prototype.toHslString=function(){return r=h(g(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=i(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 x({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),x(d(this.rgba,r))},r.prototype.desaturate=function(r){return void 0===r&&(r=.1),x(d(this.rgba,-r))},r.prototype.grayscale=function(){return x(d(this.rgba,-1))},r.prototype.lighten=function(r){return void 0===r&&(r=.1),x(y(this.rgba,r))},r.prototype.darken=function(r){return void 0===r&&(r=.1),x(y(this.rgba,-r))},r.prototype.alpha=function(r){return"number"==typeof r?x({r:(n=this.rgba).r,g:n.g,b:n.b,a:r}):t(this.rgba.a,2);var n},r}(),x=function(r){return r instanceof N?r:new N(r)},M=[];exports.Colord=N,exports.colord=x,exports.extend=function(r){r.forEach(function(r){M.indexOf(r)<0&&(r(N,l),M.push(r))})},exports.random=function(){return new N({r:255*Math.random(),g:255*Math.random(),b:255*Math.random()})};
{
"name": "colord",
"version": "1.4.1",
"version": "1.5.0",
"description": "👑 A tiny yet powerful tool for high-performance color manipulations and conversions",

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

@@ -388,2 +388,4 @@ <div align="center">

→ [Online demo](https://3cg7o.csb.app/)
```js

@@ -397,4 +399,4 @@ import { colord, extend } from "colord";

colord("#800080").mix("#dda0dd").toHex(); // "#af5cae"
colord("#cd853f").mix("#eee8aa", 0.6).toHex(); // "#dfc279"
colord("#008080").mix("#808000", 0.35).toHex(); // "#14865f"
colord("#cd853f").mix("#eee8aa", 0.6).toHex(); // "#e3c07e"
colord("#008080").mix("#808000", 0.35).toHex(); // "#50805d"
```

@@ -516,2 +518,18 @@

### Color utilities
<details>
<summary><b><code>random()</code></b></summary>
Returns a new Colord instance with a random color value inside.
```js
import { random } from "colord";
random().toHex(); // "#01c8ec"
random().alpha(0.5).toRgb(); // { r: 13, g: 237, b: 162, a: 0.5 }
```
</details>
<div><img src="assets/divider.png" width="838" alt="---" /></div>

@@ -616,2 +634,4 @@

→ [Online demo](https://3cg7o.csb.app/)
```js

@@ -625,4 +645,4 @@ import { colord, extend } from "colord";

colord("#800080").mix("#dda0dd").toHex(); // "#af5cae"
colord("#cd853f").mix("#eee8aa", 0.6).toHex(); // "#dfc279"
colord("#008080").mix("#808000", 0.35).toHex(); // "#14865f"
colord("#cd853f").mix("#eee8aa", 0.6).toHex(); // "#e3c07e"
colord("#008080").mix("#808000", 0.35).toHex(); // "#50805d"
```

@@ -629,0 +649,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc