Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

colortranslator

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

colortranslator - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

CHANGELOG.md

4

dist/@types/index.d.ts

@@ -43,1 +43,5 @@ export declare type NumberOrString = number | string;

export declare type CMYKOutput = string | CMYKObject;
export declare type Omit<T, K> = Exclude<T, K>;
export interface ObjectProps<T> {
[key: string]: T;
}

1

dist/color/utils.d.ts

@@ -12,3 +12,2 @@ import { RGBObject, HSLObject, CMYKObject, RGBObjectFinal } from '../@types';

export declare const getRGBObjectFromObject: {
HEX(color: RGBObject): RGBObjectFinal;
RGB(color: RGBObject): RGBObjectFinal;

@@ -15,0 +14,0 @@ RGBA(color: RGBObject): RGBObjectFinal;

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

!function(t,r){for(var e in r)t[e]=r[e]}(window,function(t){var r={};function e(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,e),o.l=!0,o.exports}return e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:n})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,r){if(1&r&&(t=e(t)),8&r)return t;if(4&r&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&r&&"string"!=typeof t)for(var o in t)e.d(n,o,function(r){return t[r]}.bind(null,o));return n},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},e.p="",e(e.s=2)}([function(t,r,e){"use strict";var n;Object.defineProperty(r,"__esModule",{value:!0}),r.CONST={HEX:"HEX",RGB:"RGB",RGBA:"RGBA",HSL:"HSL",HSLA:"HSLA",CMYK:"CMYK"},r.COLORREGS=((n={})[r.CONST.HEX]=/^#([a-f\d]{1,2})([a-f\d]{1,2})([a-f\d]{1,2})([a-f\d]{1,2})?$/i,n[r.CONST.RGB]=/^rgb\s*\(\s*(?:(\d+%)\s*\,\s*(\d+%)\s*\,\s*(\d+%)|(\d+)\s*\,\s*(\d+)\s*\,\s*(\d+))\s*\)$/,n[r.CONST.RGBA]=/^rgba\s*\(\s*(?:(\d+%)\s*\,\s*(\d+%)\s*\,\s*(\d+%)|(\d+)\s*\,\s*(\d+)\s*\,\s*(\d+))\s*,\s*(\d\.?\d*)\s*\)$/,n[r.CONST.HSL]=/^hsl\s*\(\s*(\-?\d+)\s*\,\s*(\d+)%\s*\,\s*(\d+)%s*\)$/,n[r.CONST.HSLA]=/^hsla\s*\(\s*(\-?\d+)\s*\,\s*(\d+)%\s*\,\s*(\d+)%\s*\,\s*(\d\.?\d*)\s*\)$/,n[r.CONST.CMYK]=/^(?:device-cmyk|cmyk)\s*\(\s*(?:(\d+%)\s*\,\s*(\d+%)\s*\,\s*(\d+%)\s*\,\s*(\d+%)|(\d\.?\d*)\s*\,\s*(\d\.?\d*)\s*\,\s*(\d\.?\d*)\s*\,\s*(\d\.?\d*))\s*\)$/,n),r.PCENT=/^([\d\.]+)%$/,r.HEX=/^0x([a-f\d]{1,2})$/i,r.ERRORS={NOT_ACCEPTED_STRING_INPUT:"The provided string color doesn't have a correct format",NOT_ACCEPTED_OBJECT_INPUT:"The provided color object doesn't have the proper keys"}},function(t,r,e){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=e(0);r.getDEC=function(t){return 1===t.length&&(t+=t),parseInt(t,16)},r.getHEX=function(t){var r=parseInt(""+t).toString(16).toUpperCase();return 1===r.length?"0x0"+r:"0x"+r},r.toHEX=function(t){var r=parseInt(""+t).toString(16).toUpperCase();return 1===r.length&&(r="0"+r),r},r.getBase255Number=function(t){return n.PCENT.test(t)?Math.min(255*parseInt(t)/100,255):Math.min(parseInt(t),255)},r.getCMYKNumber=function(t){return Math.min(n.PCENT.test(t)?parseInt(t)/100:parseInt(t),1)},r.getOrderedArrayString=function(t){return t.sort().join().toUpperCase()}},function(t,r,e){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=e(0),o=e(3),a=e(5),u=function(t,r){return"string"==typeof t&&r||"object"==typeof t&&!r},s=function(t,r,e,n,a){var u=n("string"==typeof t?o.getRGBObjectFromString[r](t):o.getRGBObjectFromObject[r](t));return e?a(u):u};r.colortranslator={toRGB:function(t,r){void 0===r&&(r=!0);var e=o.getColorModel(t);return s(t,e,r,o.translateColor.RGB,a.CSS.RGB)},toRGBA:function(t,r){void 0===r&&(r=!0);var e=o.getColorModel(t);return s(t,e,r,o.translateColor.RGBA,a.CSS.RGB)},toHEX:function(t,r){void 0===r&&(r=!0);var e=o.getColorModel(t);return s(t,e,r,o.translateColor.HEX,a.CSS.HEX)},toHEXA:function(t,r){void 0===r&&(r=!0);var e=o.getColorModel(t);return s(t,e,r,o.translateColor.HEXA,a.CSS.HEX)},toHSL:function(t,r){void 0===r&&(r=!0);var e=o.getColorModel(t);return e===n.CONST.HSL&&u(t,r)?t:s(t,e,r,o.translateColor.HSL,a.CSS.HSL)},toHSLA:function(t,r){void 0===r&&(r=!0);var e=o.getColorModel(t);return e===n.CONST.HSLA&&u(t,r)?t:s(t,e,r,o.translateColor.HSLA,a.CSS.HSL)},toCMYK:function(t,r){void 0===r&&(r=!0);var e=o.getColorModel(t);return e===n.CONST.CMYK&&u(t,r)?t:s(t,e,r,o.translateColor.CMYK,a.CSS.CMYK)}}},function(t,r,e){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=e(0),o=e(1),a=e(4);r.getColorModel=function(t){return"string"==typeof t?function(t){var r;if(Object.keys(n.CONST).some(function(e){if(n.COLORREGS[e].test(t))return r=e,!0}),!r)throw new Error(n.ERRORS.NOT_ACCEPTED_STRING_INPUT);return r}(t):function(t){var r,e=o.getOrderedArrayString(Object.keys(t));if(Object.keys(n.CONST).some(function(t){if(o.getOrderedArrayString(t.split(""))===e)return r=t,!0}),!r)throw new Error(n.ERRORS.NOT_ACCEPTED_OBJECT_INPUT);return r}(t)},r.getRGBObjectFromString={HEX:function(t){var r=t.match(n.COLORREGS.HEX),e=r[1],a=r[2],u=r[3],s=r[4],i={r:o.getDEC(e),g:o.getDEC(a),b:o.getDEC(u)};return void 0!==s&&(i.a=o.getDEC(s)/255),i},RGB:function(t){var r=t.match(n.COLORREGS.RGB),e=o.getBase255Number(r[1]||r[4]),a=o.getBase255Number(r[2]||r[5]),u=o.getBase255Number(r[3]||r[6]);return{r:Math.min(e,255),g:Math.min(a,255),b:Math.min(u,255)}},RGBA:function(t){var r=t.match(n.COLORREGS.RGBA),e=o.getBase255Number(r[1]||r[4]),a=o.getBase255Number(r[2]||r[5]),u=o.getBase255Number(r[3]||r[6]),s=+r[7];return{r:Math.min(e,255),g:Math.min(a,255),b:Math.min(u,255),a:isNaN(s)||s>1?1:s}},HSL:function(t){var r=t.match(n.COLORREGS.HSL),e=parseInt(r[1]),o=Math.min(parseInt(r[2]),100),u=Math.min(parseInt(r[3]),100);return a.hslToRGB(e,o,u)},HSLA:function(t){var r=t.match(n.COLORREGS.HSLA),e=+r[4],o=parseInt(r[1]),u=Math.min(parseInt(r[2]),100),s=Math.min(parseInt(r[3]),100),i=a.hslToRGB(o,u,s);return i.a=isNaN(e)||e>1?1:e,i},CMYK:function(t){var r=t.match(n.COLORREGS.CMYK),e=o.getCMYKNumber(r[1]||r[5]),u=o.getCMYKNumber(r[2]||r[6]),s=o.getCMYKNumber(r[3]||r[7]),i=o.getCMYKNumber(r[4]||r[8]);return a.cmykToRGB(e,u,s,i)}},r.getRGBObjectFromObject={HEX:function(t){var r={r:o.getDEC(""+t.r),g:o.getDEC(""+t.g),b:o.getDEC(""+t.b)};return void 0!==t.a&&(r.a=o.getDEC(""+t.a)),r},RGB:function(t){return{r:o.getBase255Number(""+t.r),g:o.getBase255Number(""+t.g),b:o.getBase255Number(""+t.b)}},RGBA:function(t){var r=this[n.CONST.RGB](t);return r.a=isNaN(+t.a)||+t.a>1?1:+t.a,r},HSL:function(t){var r=parseInt(""+t.h),e=Math.min(parseInt(""+t.s),100),n=Math.min(parseInt(""+t.l),100);return a.hslToRGB(r,e,n)},HSLA:function(t){var r=this.HSL(t);return r.a=isNaN(+t.a)||+t.a>1?1:+t.a,r},CMYK:function(t){var r=o.getCMYKNumber(""+t.c),e=o.getCMYKNumber(""+t.m),n=o.getCMYKNumber(""+t.y),u=o.getCMYKNumber(""+t.k);return a.cmykToRGB(r,e,n,u)}},r.translateColor={HEX:function(t){return{r:o.getHEX(t.r),g:o.getHEX(t.g),b:o.getHEX(t.b)}},HEXA:function(t){var e=r.translateColor.HEX(t);return e.a=t.hasOwnProperty("a")?o.getHEX(255*t.a):"0xFF",e},RGB:function(t){return t.hasOwnProperty("a")&&delete t.a,t},RGBA:function(t){return t.a=t.hasOwnProperty("a")?t.a:1,t},HSL:function(t){var r=a.rgbToHSL(t.r,t.g,t.b);return delete r.a,r},HSLA:function(t){var e=r.translateColor.HSL(t);return e.a=t.hasOwnProperty("a")?t.a:1,e},CMYK:function(t){return a.rgbToCMYK(t.r,t.g,t.b)}}},function(t,r,e){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.hueToRGB=function(t,r,e){return e<0&&(e+=6),e>=6&&(e-=6),e<1?Math.round(255*((r-t)*e+t)):e<3?Math.round(255*r):e<4?Math.round(255*((r-t)*(4-e)+t)):Math.round(255*t)},r.hslToRGB=function(t,e,n){t/=60,e/=100;var o=(n/=100)<=.5?n*(e+1):n+e-n*e,a=2*n-o;return{r:r.hueToRGB(a,o,t+2),g:r.hueToRGB(a,o,t),b:r.hueToRGB(a,o,t-2)}},r.cmykToRGB=function(t,r,e,n){return n=1-n,{r:Math.round(255*(1-t)*n),g:Math.round(255*(1-r)*n),b:Math.round(255*(1-e)*n)}},r.rgbToCMYK=function(t,r,e){t/=255,r/=255,e/=255;var n=Math.max(t,r,e),o=(n-t)/n,a=(n-r)/n,u=(n-e)/n;return{c:Math.round(100*o),m:Math.round(100*a),y:Math.round(100*u),k:Math.round(100*n)}},r.rgbToHSL=function(t,r,e,n){void 0===n&&(n=1),t/=255,r/=255,e/=255,n=Math.min(n,1);var o=Math.max(t,r,e),a=Math.min(t,r,e),u=o-a,s=0,i=0,c=(o+a)/2;if(0===u)s=0,i=0;else{switch(o){case t:s=(r-e)/u%6;break;case r:s=(e-t)/u+2;break;case e:s=(t-r)/u+4}(s=Math.round(60*s))<0&&(s+=360),i=u/(1-Math.abs(2*c-1))}return{h:s,s:Math.round(100*i),l:Math.round(100*c),a:n}}},function(t,r,e){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=e(1);r.CSS={HEX:function(t){return"#"+n.toHEX(t.r)+n.toHEX(t.g)+n.toHEX(t.b)+(t.a&&n.toHEX(t.a)||"")},RGB:function(t){return"rgb"+(t.a?"a":"")+"("+t.r+","+t.g+","+t.b+(t.a&&","+t.a||"")+")"},HSL:function(t){return"hsl"+(t.a?"a":"")+"("+t.h+","+t.s+"%,"+t.l+"%"+(t.a&&","+t.a||"")+")"},CMYK:function(t){return"device-cmyk("+t.c+"%,"+t.m+"%,"+t.y+"%,"+t.k+"%)"}}}]));
!function(r,t){for(var e in t)r[e]=t[e]}(window,function(r){var t={};function e(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return r[n].call(o.exports,o,o.exports,e),o.l=!0,o.exports}return e.m=r,e.c=t,e.d=function(r,t,n){e.o(r,t)||Object.defineProperty(r,t,{enumerable:!0,get:n})},e.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},e.t=function(r,t){if(1&t&&(r=e(r)),8&t)return r;if(4&t&&"object"==typeof r&&r&&r.__esModule)return r;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:r}),2&t&&"string"!=typeof r)for(var o in r)e.d(n,o,function(t){return r[t]}.bind(null,o));return n},e.n=function(r){var t=r&&r.__esModule?function(){return r.default}:function(){return r};return e.d(t,"a",t),t},e.o=function(r,t){return Object.prototype.hasOwnProperty.call(r,t)},e.p="",e(e.s=2)}([function(r,t,e){"use strict";var n;Object.defineProperty(t,"__esModule",{value:!0}),t.CONST={HEX:"HEX",RGB:"RGB",RGBA:"RGBA",HSL:"HSL",HSLA:"HSLA",CMYK:"CMYK"},t.COLORREGS=((n={})[t.CONST.HEX]=/^#(?:([a-f\d])([a-f\d])([a-f\d])([a-f\d])?|([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?)$/i,n[t.CONST.RGB]=/^rgb\s*\(\s*(?:(\d+%)\s*,\s*(\d+%)\s*,\s*(\d+%)|(\d+)\s*,\s*(\d+)\s*,\s*(\d+))\s*\)$/,n[t.CONST.RGBA]=/^rgba\s*\(\s*(?:(\d+%)\s*,\s*(\d+%)\s*,\s*(\d+%)|(\d+)\s*,\s*(\d+)\s*,\s*(\d+))\s*,\s*(\d\.?\d*)\s*\)$/,n[t.CONST.HSL]=/^hsl\s*\(\s*(-?\d+\.?\d*)\s*,\s*(\d+\.?\d*)%\s*,\s*(\d+\.?\d*)%s*\)$/,n[t.CONST.HSLA]=/^hsla\s*\(\s*(-?\d+\.?\d*)\s*,\s*(\d+\.?\d*)%\s*,\s*(\d+\.?\d*)%\s*,\s*(\d\.?\d*)\s*\)$/,n[t.CONST.CMYK]=/^(?:device-cmyk|cmyk)\s*\(\s*(?:(\d+\.?\d*%)\s*,\s*(\d+\.?\d*%)\s*,\s*(\d+\.?\d*%)\s*,\s*(\d+\.?\d*%)|(\d\.?\d*)\s*,\s*(\d\.?\d*)\s*,\s*(\d\.?\d*)\s*,\s*(\d\.?\d*))\s*\)$/,n),t.PCENT=/^([\d.]+)%$/,t.HEX=/^0x([a-f\d]{1,2})$/i,t.ERRORS={NOT_ACCEPTED_STRING_INPUT:"The provided string color doesn't have a correct format",NOT_ACCEPTED_OBJECT_INPUT:"The provided color object doesn't have the proper keys"}},function(r,t,e){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=e(0);t.hasProp=function(r,t){return Object.prototype.hasOwnProperty.call(r,t)},t.percent=function(r){return n.PCENT.test(""+r)?+(""+r).replace(n.PCENT,"$1"):Math.min(+r,100)},t.getDEC=function(r){return 1===r.length&&(r+=r),parseInt(r,16)},t.getHEX=function(r){var t=parseInt(""+r).toString(16).toUpperCase();return 1===t.length?"0x0"+t:"0x"+t},t.toHEX=function(r){var t=parseInt(""+r).toString(16).toUpperCase();return 1===t.length&&(t="0"+t),t},t.getBase255Number=function(r,t){return void 0===t&&(t=!1),!t&&n.PCENT.test(r)?Math.min(255*+r.replace(n.PCENT,"$1")/100,255):n.HEX.test(r)?3===r.length?t?parseInt(r+r.slice(-1))/255:parseInt(r+r.slice(-1)):t?parseInt(r)/255:parseInt(r):Math.min(+r,t?1:255)},t.getCMYKNumber=function(r){return Math.min(n.PCENT.test(r)?+r.replace(n.PCENT,"$1")/100:+r,1)},t.getOrderedArrayString=function(r){return r.sort().join().toUpperCase()},t.round=function(r,t){void 0===t&&(t=0);var e=Math.pow(10,t);return Math.round(+r*e)/e}},function(r,t,e){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=e(0),o=e(3),u=e(5),a=function(r,t){return"string"==typeof r&&t||"object"==typeof r&&!t},s=function(r,t,e,n,u){var a=n("string"==typeof r?o.getRGBObjectFromString[t](r):o.getRGBObjectFromObject[t](r));return e?u(a):a},i=function(){function r(){}return r.toRGB=function(r,t){void 0===t&&(t=!0);var e=o.getColorModel(r);return s(r,e,t,o.translateColor.RGB,u.CSS.RGB)},r.toRGBA=function(r,t){void 0===t&&(t=!0);var e=o.getColorModel(r);return s(r,e,t,o.translateColor.RGBA,u.CSS.RGB)},r.toHEX=function(r,t){void 0===t&&(t=!0);var e=o.getColorModel(r);return s(r,e,t,o.translateColor.HEX,u.CSS.HEX)},r.toHEXA=function(r,t){void 0===t&&(t=!0);var e=o.getColorModel(r);return s(r,e,t,o.translateColor.HEXA,u.CSS.HEX)},r.toHSL=function(r,t){void 0===t&&(t=!0);var e=o.getColorModel(r);return e===n.CONST.HSL&&a(r,t)?r:s(r,e,t,o.translateColor.HSL,u.CSS.HSL)},r.toHSLA=function(r,t){void 0===t&&(t=!0);var e=o.getColorModel(r);return e===n.CONST.HSLA&&a(r,t)?r:s(r,e,t,o.translateColor.HSLA,u.CSS.HSL)},r.toCMYK=function(r,t){void 0===t&&(t=!0);var e=o.getColorModel(r);return e===n.CONST.CMYK&&a(r,t)?r:s(r,e,t,o.translateColor.CMYK,u.CSS.CMYK)},r}();t.ColorTranslator=i},function(r,t,e){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=e(0),o=e(1),u=e(4);t.getColorModel=function(r){return"string"==typeof r?function(r){var t;if(Object.keys(n.CONST).some(function(e){if(n.COLORREGS[e].test(r))return t=e,!0}),!t)throw new Error(n.ERRORS.NOT_ACCEPTED_STRING_INPUT);return t}(r):function(r){var t,e=o.getOrderedArrayString(Object.keys(r));if(Object.keys(n.CONST).some(function(r){if(o.getOrderedArrayString(r.split(""))===e)return t=r,!0}),!t)throw new Error(n.ERRORS.NOT_ACCEPTED_OBJECT_INPUT);return t}(r)},t.getRGBObjectFromString={HEX:function(r){var t=r.match(n.COLORREGS.HEX),e={r:o.getDEC(t[1]||t[5]),g:o.getDEC(t[2]||t[6]),b:o.getDEC(t[3]||t[7])},u=t[4]||t[8];return void 0!==u&&(e.a=o.getDEC(u)/255),e},RGB:function(r){var t=r.match(n.COLORREGS.RGB),e=o.getBase255Number(t[1]||t[4]),u=o.getBase255Number(t[2]||t[5]),a=o.getBase255Number(t[3]||t[6]);return{r:Math.min(e,255),g:Math.min(u,255),b:Math.min(a,255)}},RGBA:function(r){var t=r.match(n.COLORREGS.RGBA),e=o.getBase255Number(t[1]||t[4]),u=o.getBase255Number(t[2]||t[5]),a=o.getBase255Number(t[3]||t[6]),s=+t[7];return{r:Math.min(e,255),g:Math.min(u,255),b:Math.min(a,255),a:isNaN(s)||s>1?1:o.round(s,2)}},HSL:function(r){var t=r.match(n.COLORREGS.HSL),e=+t[1],a=o.percent(t[2]),s=o.percent(t[3]);return u.hslToRGB(e,a,s)},HSLA:function(r){var t=r.match(n.COLORREGS.HSLA),e=+t[4],a=+t[1],s=o.percent(t[2]),i=o.percent(t[3]),d=u.hslToRGB(a,s,i);return d.a=isNaN(e)||e>1?1:o.round(e,2),d},CMYK:function(r){var t=r.match(n.COLORREGS.CMYK),e=o.getCMYKNumber(t[1]||t[5]),a=o.getCMYKNumber(t[2]||t[6]),s=o.getCMYKNumber(t[3]||t[7]),i=o.getCMYKNumber(t[4]||t[8]);return u.cmykToRGB(e,a,s,i)}},t.getRGBObjectFromObject={RGB:function(r){return{r:o.getBase255Number(""+r.r),g:o.getBase255Number(""+r.g),b:o.getBase255Number(""+r.b)}},RGBA:function(r){var t=this.RGB(r);return t.a=o.hasProp(r,"a")?Math.min(o.getBase255Number(""+r.a,!0),1):1,t},HSL:function(r){var t=o.percent(""+r.s),e=o.percent(""+r.l);return u.hslToRGB(r.h,t,e)},HSLA:function(r){var t=this.HSL(r);return t.a=isNaN(+r.a)||+r.a>1?1:o.round(r.a,2),t},CMYK:function(r){var t=o.getCMYKNumber(""+r.c),e=o.getCMYKNumber(""+r.m),n=o.getCMYKNumber(""+r.y),a=o.getCMYKNumber(""+r.k);return u.cmykToRGB(t,e,n,a)}},t.translateColor={HEX:function(r){return{r:o.getHEX(r.r),g:o.getHEX(r.g),b:o.getHEX(r.b)}},HEXA:function(r){var e=t.translateColor.HEX(r);return e.a=o.hasProp(r,"a")?o.getHEX(255*r.a):"0xFF",e},RGB:function(r){return o.hasProp(r,"a")&&delete r.a,r},RGBA:function(r){return r.a=o.hasProp(r,"a")?o.round(r.a,2):1,r},HSL:function(r){var t=u.rgbToHSL(r.r,r.g,r.b);return delete t.a,t},HSLA:function(r){var e=t.translateColor.HSL(r);return e.a=o.hasProp(r,"a")?o.round(r.a,2):1,e},CMYK:function(r){return u.rgbToCMYK(r.r,r.g,r.b)}}},function(r,t,e){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.hueToRGB=function(r,t,e){return e<0&&(e+=6),e>=6&&(e-=6),e<1?Math.round(255*((t-r)*e+r)):e<3?Math.round(255*t):e<4?Math.round(255*((t-r)*(4-e)+r)):Math.round(255*r)},t.hslToRGB=function(r,e,n){r/=60,e/=100;var o=(n/=100)<=.5?n*(e+1):n+e-n*e,u=2*n-o;return{r:t.hueToRGB(u,o,r+2),g:t.hueToRGB(u,o,r),b:t.hueToRGB(u,o,r-2)}},t.cmykToRGB=function(r,t,e,n){return n=1-n,{r:Math.round(255*(1-r)*n),g:Math.round(255*(1-t)*n),b:Math.round(255*(1-e)*n)}},t.rgbToCMYK=function(r,t,e){r/=255,t/=255,e/=255;var n=1-Math.max(r,t,e),o=1-n,u=(o-r)/o,a=(o-t)/o,s=(o-e)/o;return{c:Math.round(100*u),m:Math.round(100*a),y:Math.round(100*s),k:Math.round(100*n)}},t.rgbToHSL=function(r,t,e,n){void 0===n&&(n=1),r/=255,t/=255,e/=255,n=Math.min(n,1);var o=Math.max(r,t,e),u=Math.min(r,t,e),a=o-u,s=0,i=0,d=(o+u)/2;if(0===a)s=0,i=0;else{switch(o){case r:s=(t-e)/a%6;break;case t:s=(e-r)/a+2;break;case e:s=(r-t)/a+4}(s=Math.round(60*s))<0&&(s+=360),i=a/(1-Math.abs(2*d-1))}return{h:s,s:Math.round(100*i),l:Math.round(100*d),a:n}}},function(r,t,e){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=e(1);t.CSS={HEX:function(r){return"#"+n.toHEX(r.r)+n.toHEX(r.g)+n.toHEX(r.b)+(r.a&&n.toHEX(r.a)||"")},RGB:function(r){return"rgb"+(r.a?"a":"")+"("+n.round(r.r)+","+n.round(r.g)+","+n.round(r.b)+(n.hasProp(r,"a")&&","+n.round(r.a,2)||"")+")"},HSL:function(r){return"hsl"+(r.a?"a":"")+"("+n.round(r.h)+","+n.round(r.s)+"%,"+n.round(r.l)+"%"+(n.hasProp(r,"a")&&","+n.round(r.a,2)||"")+")"},CMYK:function(r){return"device-cmyk("+n.round(r.c)+"%,"+n.round(r.m)+"%,"+n.round(r.y)+"%,"+n.round(r.k)+"%)"}}}]));
import { NumberOrString } from '../@types';
export declare const hasProp: <T>(obj: T, prop: string) => boolean;
export declare const percent: (percent: NumberOrString) => number;
export declare const getDEC: (hex: string) => number;
export declare const getHEX: (number: NumberOrString) => string;
export declare const toHEX: (h: NumberOrString) => string;
export declare const getBase255Number: (color: string) => number;
export declare const getBase255Number: (color: string, alpha?: boolean) => number;
export declare const getCMYKNumber: (color: string) => number;
export declare const getOrderedArrayString: (keys: string[]) => string;
export declare const round: (value: NumberOrString, decimals?: number) => number;
{
"name": "colortranslator",
"version": "1.0.4",
"version": "1.0.5",
"description": "A JavaScript library, written in TypeScript, to convert among different color models",
"main": "dist/colortranslator.node.js",
"types": "dist/colortranslator.d.ts",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [

@@ -12,7 +12,8 @@ "dist/**/*"

"test": "mocha -r ts-node/register -r tsconfig-paths/register tests/**/*.spec.ts",
"lint": "eslint src/**/*.{ts,js}",
"build": "webpack && tscpaths -p tsconfig.json -s ./src -o ./dist",
"demo": "webpack-dev-server --open --config webpack.demo.config.js",
"docs": "webpack --mode=development --config webpack.demo.publish.js",
"docs": "webpack --config webpack.demo.publish.js",
"prepare": "npm run build",
"prepublishOnly": "npm run test",
"prepublishOnly": "npm run lint && npm run test",
"version": "git add .",

@@ -48,2 +49,4 @@ "postversion": "git push && git push --tags"

"@types/node": "^12.0.10",
"@typescript-eslint/eslint-plugin": "^1.11.0",
"@typescript-eslint/parser": "^1.11.0",
"chai": "^4.2.0",

@@ -53,2 +56,3 @@ "clean-webpack-plugin": "^3.0.0",

"css-loader": "^3.0.0",
"eslint": "^6.0.1",
"google-code-prettify": "^1.0.5",

@@ -55,0 +59,0 @@ "html-webpack-plugin": "^3.2.0",

@@ -9,9 +9,9 @@ <p align="center">

# Demo
## Demo
https://elchininet.github.io/ColorTranslator/
# Installation
## Installation
<h4>Using NPM</h4>
#### Using NPM

@@ -22,3 +22,3 @@ ```

<h4>Using Yarn</h4>
#### Using Yarn

@@ -29,5 +29,6 @@ ```

<h4>In the browser</h4>
It is possible to include a compiled version of the package directly in an HTML file. It will create a global `colortranslator` variable that can be accessed from anywhere in your JavaScript code.
#### In the browser
It is possible to include a compiled version of the package directly in an HTML file. It will create a global `ColorTranslator` variable that can be accessed from anywhere in your JavaScript code.
1. Copy the JavaScript file `colortranslator.web.js`, located in the `dist` folder

@@ -41,6 +42,28 @@ 2. Put it in the folder that you prefer in your web server

# Scripts
#### Importing using CommonJS
<h4>build</h4>
```javascript
const { ColorTranslator } = require('colortranslator');
```
#### Importing using ES6 modules
```javascript
import { ColorTranslator } from 'colortranslator';
```
#### Using in the browser
```javascript
/* Use it directly in your JavaScript code */
ColorTranslator;
/* Or access to the global variable if there is a variable with this name in the same scope */
window.ColorTranslator;
```
## Scripts
#### build
`npm run build`

@@ -50,3 +73,3 @@

<h4>test</h4>
#### test

@@ -57,4 +80,10 @@ `npm run test`

<h4>demo</h4>
#### lint
`npm run lint`
Runs eslint in source files.
#### demo
`npm run demo`

@@ -64,10 +93,11 @@

# API
## API
It is not needed to specify the color model from which you are converting, the API will detect the format. You only need to specify to which color model you want to convert calling the specific method.
<h4>Input</h4>
#### Input
It is possible to convert from a CSS string or an object.
<h6>CSS string inputs</h6>
###### CSS string inputs

@@ -88,3 +118,3 @@ | Example of CSS string inputs | Description |

<h6>Object inputs</h6>
###### Object inputs

@@ -103,3 +133,4 @@ | Example of object inputs | Description |

<h4>Methods</h4>
#### Methods
There are 7 methods available and all of them accept any of the previous inputs as the first parameter. The second parameter is optional and it specifies if the output should be a CSS string or an object:

@@ -123,20 +154,18 @@

# Examples
## Example methods
```javascript
import { colortranslator } from 'colortranslator';
ColorTranslator.toRGB('#FF00FF'); // rgb(255,0,255)
colortranslator.toRGB('#FF00FF'); // rgb(255,0,255)
ColorTranslator.toRGBA('hsl(50, 20%, 90%)'); // rgba(235,233,224,1)
colortranslator.toRGBA('hsl(50, 20%, 90%)'); // rgba(235,233,224,1)
ColorTranslator.toHSL('rgb(255, 0, 0)'); // hsl(0,100%,50%)
colortranslator.toHSL('rgb(255, 0, 0)'); // hsl(0,100%,50%)
ColorTranslator.toHSLA('rgba(0, 255, 255, .5)'); // hsla(180,100%,50%,0.5)
colortranslator.toHSLA('rgba(0, 255, 255, .5)'); // hsla(180,100%,50%,0.5)
ColorTranslator.toCMYK('#F0F', false); // {c: 0, m: 100, y: 0, k: 0}
colortranslator.toCMYK('#F0F', false); // {c: 0, m: 100, y: 0, k: 0}
ColorTranslator.toRGB({ h: 115, s: '70%', l: '45%' }); // rgb(48,195,34)
colortranslator.toRGB({ h: 115, s: '70%', l: '45%' }); // rgb(48,195,34)
colortranslator.toHSLA({ r: 115, g: 200, b: 150, a: 0.5 }); // hsla(145,44%,62%,0.5)
ColorTranslator.toHSLA({ r: 115, g: 200, b: 150, a: 0.5 }); // hsla(145,44%,62%,0.5)
```
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