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

colors-convert

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

colors-convert - npm Package Compare versions

Comparing version 1.1.1 to 1.1.2

dist/constants/colorNames.d.ts

4

dist/index.d.ts
export { isHex, isRgb, isRgba, isCmyk, isHsl, isColor } from './types/isType';
export { color2string, color2cssString } from './lib/color';
export { hex2rgbOrRgba, hex2rgba, hex2hexWithAlpha, hex2cmyk, hex2hsl } from './lib/hex';
export { rgb2hex, rgb2cmyk, rgb2hsl } from './lib/rgb';
export { rgb2hex, rgb2cmyk, rgb2hsl, rgba2rgb, rgb2rgba, color2rgb } from './lib/rgb';
export { cmyk2rgb, cmyk2hex, cmyk2hsl } from './lib/cmyk';
export { hsl2hex, hsl2rgb, hsl2cmyk } from './lib/hsl';
export { getRandomColor } from './lib/random';
export { mix } from './lib/mix';
export { name } from './lib/name';
export { isHex, isRgb, isRgba, isCmyk, isHsl, isColor } from './types/isType';
export { color2string, color2cssString } from './lib/color';
export { hex2rgbOrRgba, hex2rgba, hex2hexWithAlpha, hex2cmyk, hex2hsl } from './lib/hex';
export { rgb2hex, rgb2cmyk, rgb2hsl } from './lib/rgb';
export { rgb2hex, rgb2cmyk, rgb2hsl, rgba2rgb, rgb2rgba, color2rgb } from './lib/rgb';
export { cmyk2rgb, cmyk2hex, cmyk2hsl } from './lib/cmyk';
export { hsl2hex, hsl2rgb, hsl2cmyk } from './lib/hsl';
export { getRandomColor } from './lib/random';
export { mix } from './lib/mix';
export { name } from './lib/name';
//# sourceMappingURL=index.js.map

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

import { CMYK, RGB, HSL } from '../types/types';
export declare const cmyk2rgb: (cmyk: CMYK) => RGB;
export declare const cmyk2hex: (cmyk: CMYK) => string;
export declare const cmyk2hsl: (cmyk: CMYK) => HSL;
import { CMYK, HEX, RGB, HSL } from '../types/types';
export declare function cmyk2rgb(cmyk: CMYK): RGB;
export declare function cmyk2hex(cmyk: CMYK): HEX;
export declare function cmyk2hsl(cmyk: CMYK): HSL;

@@ -6,3 +6,3 @@ import { applyFnToEachObjValue } from './utils';

// Convert a cmyk color to a rgb
export var cmyk2rgb = function (cmyk) {
export function cmyk2rgb(cmyk) {
if (!isCmyk(cmyk)) {

@@ -19,5 +19,5 @@ throw new Error(cmyk + " is not a cmyk color.");

return rgb;
};
}
// Convert a cmyk color to a hex
export var cmyk2hex = function (cmyk) {
export function cmyk2hex(cmyk) {
if (!isCmyk(cmyk)) {

@@ -29,5 +29,5 @@ throw new Error(cmyk + " is not a cmyk color.");

return hex;
};
}
// Convert an cmyk object to hsl
export var cmyk2hsl = function (cmyk) {
export function cmyk2hsl(cmyk) {
if (!isCmyk(cmyk)) {

@@ -39,3 +39,3 @@ throw new Error(cmyk + " is not a cmyk color.");

return hsl;
};
}
//# sourceMappingURL=cmyk.js.map

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

import { COLOR } from '../types/types';
export declare const color2string: (color: COLOR) => string;
export declare const color2cssString: (color: COLOR) => string;
import { Color } from '../types/types';
export declare function color2string(color: Color): string;
export declare function color2cssString(color: Color): string;
import { isHex, isRgb, isRgba, isCmyk, isColor } from '../types/isType';
import { toUpper } from 'lodash';
// Convert a color to a string format
export var color2string = function (color) {
export function color2string(color) {
if (!isColor(color)) {

@@ -23,5 +23,5 @@ throw new Error(color + " is not a color.");

}
};
}
// Convert a color to a string format usable in CSS
export var color2cssString = function (color) {
export function color2cssString(color) {
if (!isColor(color)) {

@@ -45,3 +45,3 @@ throw new Error(color + " is not a color.");

}
};
}
//# sourceMappingURL=color.js.map

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

import { RGB, RGBA, CMYK, HSL } from '../types/types';
export declare const hex2rgbOrRgba: (hex: string) => RGB | RGBA;
export declare const hex2rgba: (hex: string, alpha?: number) => RGBA;
export declare const hex2hexWithAlpha: (hex: string, alpha: number) => string;
export declare const hex2cmyk: (hex: string) => CMYK;
export declare const hex2hsl: (hex: string) => HSL;
import { HEX, RGB, RGBA, CMYK, HSL } from '../types/types';
export declare function hex2rgbOrRgba(hex: HEX): RGB | RGBA;
export declare function hex2rgba(hex: HEX, alpha?: number): RGBA;
export declare function hex2hexWithAlpha(hex: HEX, alpha: number): HEX;
export declare function hex2cmyk(hex: HEX): CMYK;
export declare function hex2hsl(hex: HEX): HSL;

@@ -17,3 +17,3 @@ var __assign = (this && this.__assign) || function () {

// Convert an hex to a rgb or rgba color (depeds on hex format)
export var hex2rgbOrRgba = function (hex) {
export function hex2rgbOrRgba(hex) {
if (!isHex(hex)) {

@@ -23,4 +23,4 @@ throw new Error(hex + " is not a hex color.");

var RGB_HEX = /^#?(?:([0-9a-f]{3})|([0-9a-f]{6})([0-9a-f]{2})?)$/i;
// short and long are or undefined or the original_hex without #
var _a = hex.match(RGB_HEX) || [], original_hex = _a[0], short = _a[1], long = _a[2], opacity = _a[3];
// short and long are or undefined or the originalHex without #
var _a = hex.match(RGB_HEX) || [], originalHex = _a[0], short = _a[1], long = _a[2], opacity = _a[3];
if (long) {

@@ -42,5 +42,5 @@ var value = Number.parseInt(long, 16);

}
};
}
// Convert an hex to a rgba object
export var hex2rgba = function (hex, alpha) {
export function hex2rgba(hex, alpha) {
if (alpha === void 0) { alpha = 1; }

@@ -63,5 +63,5 @@ if (!isHex(hex)) {

}
};
}
// Convert an hex to another hex with the given alpha
export var hex2hexWithAlpha = function (hex, alpha) {
export function hex2hexWithAlpha(hex, alpha) {
if (!isHex(hex)) {

@@ -77,5 +77,5 @@ throw new Error(hex + " is not a hex color.");

return "" + hex + alphaHexPadded;
};
}
// Convert an hex to a cmyk. If hex is in the long format (e.g. #000000FF) it removes the last two chars because cmyk doens't support opacity
export var hex2cmyk = function (hex) {
export function hex2cmyk(hex) {
if (!isHex(hex)) {

@@ -89,5 +89,5 @@ throw new Error(hex + " is not a hex color.");

return cmyk;
};
}
// Convert an hex object to hsl
export var hex2hsl = function (hex) {
export function hex2hsl(hex) {
if (!isHex(hex)) {

@@ -99,3 +99,3 @@ throw new Error(hex + " is not a hex color.");

return hsl;
};
}
//# sourceMappingURL=hex.js.map

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

import { HSL, RGB, CMYK } from '../types/types';
export declare const hsl2hex: (hsl: HSL) => string;
export declare const hsl2rgb: (hsl: HSL) => RGB;
export declare const hsl2cmyk: (hsl: HSL) => CMYK;
import { HSL, RGB, CMYK, HEX } from '../types/types';
export declare function hsl2hex(hsl: HSL): HEX;
export declare function hsl2rgb(hsl: HSL): RGB;
export declare function hsl2cmyk(hsl: HSL): CMYK;

@@ -6,3 +6,3 @@ import { isHsl } from '../types/isType';

// Convert an hsl object to hex
export var hsl2hex = function (hsl) {
export function hsl2hex(hsl) {
if (!isHsl(hsl)) {

@@ -14,5 +14,5 @@ throw new Error(hsl + " is not a hsl color.");

return hex;
};
}
// Convert an hsl object to rgb
export var hsl2rgb = function (hsl) {
export function hsl2rgb(hsl) {
if (!isHsl(hsl)) {

@@ -61,5 +61,5 @@ throw new Error(hsl + " is not a hsl color.");

return rgb;
};
}
// Convert an hsl object to cmyk
export var hsl2cmyk = function (hsl) {
export function hsl2cmyk(hsl) {
if (!isHsl(hsl)) {

@@ -71,3 +71,3 @@ throw new Error(hsl + " is not a hsl color.");

return cmyk;
};
}
//# sourceMappingURL=hsl.js.map

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

export declare const getRandomColor: () => string;
import { HEX } from '../types/types';
export declare function getRandomColor(): HEX;

@@ -5,3 +5,3 @@ // TODO: not only hex

// Create a random hex
export var getRandomColor = function () {
export function getRandomColor() {
var alphabet = '0123456789ABCDEF';

@@ -13,3 +13,3 @@ var color = '#';

return color;
};
}
//# sourceMappingURL=random.js.map

@@ -1,4 +0,7 @@

import { RGB, CMYK, HSL } from '../types/types';
export declare const rgb2hex: (rgb: RGB) => string;
export declare const rgb2cmyk: (rgb: RGB) => CMYK;
export declare const rgb2hsl: (rgb: RGB) => HSL;
import { RGB, RGBA, CMYK, HEX, HSL, Color } from '../types/types';
export declare function rgb2hex(rgb: RGB): HEX;
export declare function rgb2cmyk(rgb: RGB): CMYK;
export declare function rgb2hsl(rgb: RGB): HSL;
export declare function rgba2rgb(rgba: RGBA): RGB;
export declare function rgb2rgba(rgb: RGB): RGBA;
export declare function color2rgb(color: Color): RGB;

@@ -1,6 +0,7 @@

import { isRgb } from '../types/isType';
import { isRgb, isRgba, isColor, isHex, isCmyk } from '../types/isType';
import { applyFnToEachObjValue } from './utils';
import { round } from 'lodash';
import { hex2rgba, cmyk2rgb, hsl2rgb } from '..';
// Convert an rgb object to hex
export var rgb2hex = function (rgb) {
export function rgb2hex(rgb) {
if (!isRgb(rgb)) {

@@ -18,5 +19,5 @@ throw new Error(rgb + " is not a rgb color.");

return "#" + hex;
};
}
// Convert an rgb to a cmyk
export var rgb2cmyk = function (rgb) {
export function rgb2cmyk(rgb) {
if (!isRgb(rgb)) {

@@ -39,5 +40,8 @@ throw new Error(rgb + " is not a rgb color.");

return roundedCmyk;
};
}
// Convert an rgb object to hsl
export var rgb2hsl = function (rgb) {
export function rgb2hsl(rgb) {
if (!isRgb(rgb)) {
throw new Error(rgb + " is not a rgb color.");
}
var r = rgb.r, g = rgb.g, b = rgb.b;

@@ -68,3 +72,39 @@ var max = Math.max(r, g, b);

return hslRounded;
};
}
// Convert an rgba color to a rgb color removing the alpha value
export function rgba2rgb(rgba) {
if (!isRgba(rgba)) {
throw new Error(rgba + " is not a rgba color.");
}
return { r: rgba.r, g: rgba.g, b: rgba.b };
}
// Convert an rgb color to a rgba color adding 1 as alpha
export function rgb2rgba(rgb) {
if (!isRgb(rgb)) {
throw new Error(rgb + " is not a rgb color.");
}
return { r: rgb.r, g: rgb.g, b: rgb.b, a: 1 };
}
// Convert a generic color to rgb
export function color2rgb(color) {
if (!isColor(color)) {
throw new Error(color + " is not a valid color.");
}
else if (isHex(color)) {
return rgba2rgb(hex2rgba(color));
}
else if (isRgb(color)) {
return color;
}
else if (isRgba(color)) {
return rgba2rgb(color);
}
else if (isCmyk(color)) {
return cmyk2rgb(color);
}
else {
// hsl
return hsl2rgb(color);
}
}
//# sourceMappingURL=rgb.js.map

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

export declare const between: (value: number, range: [number, number]) => boolean;
export declare const betweenMaxNotIncluded: (value: number, range: [number, number]) => boolean;
export declare const sameContent: (a: any[], b: any[]) => boolean;
export declare const applyFnToEachObjValue: (obj: Object, fn: Function) => Object;
export declare function between(value: number, range: [number, number]): boolean;
export declare function betweenMaxNotIncluded(value: number, range: [number, number]): boolean;
export declare function sameContent(a: any[], b: any[]): boolean;
export declare function applyFnToEachObjValue(obj: Object, fn: Function): any;

@@ -1,13 +0,15 @@

export var between = function (value, range) {
export function between(value, range) {
var min = Math.min.apply(Math, range);
var max = Math.max.apply(Math, range);
return value >= min && value <= max;
};
export var betweenMaxNotIncluded = function (value, range) {
}
export function betweenMaxNotIncluded(value, range) {
var min = Math.min.apply(Math, range);
var max = Math.max.apply(Math, range);
return value >= min && value < max;
};
export var sameContent = function (a, b) { return a.sort().toString() == b.sort().toString(); };
export var applyFnToEachObjValue = function (obj, fn) {
}
export function sameContent(a, b) {
return a.sort().toString() === b.sort().toString();
}
export function applyFnToEachObjValue(obj, fn) {
Object.entries(obj).forEach(function (_a) {

@@ -19,3 +21,3 @@ var key = _a[0], value = _a[1];

return obj;
};
}
//# sourceMappingURL=utils.js.map

@@ -9,3 +9,2 @@ import { cmyk2rgb, cmyk2hex, cmyk2hsl } from '../index';

expect(cmyk2rgb({ c: 73, m: 45, y: 0, k: 4 })).toStrictEqual({ r: 66, g: 135, b: 245 });
// expect(hex2cmyk('')).toThrow(new Error(' is not a cmyk color.'))
});

@@ -19,3 +18,2 @@ ////////////////////////////////////////////////////////

expect(cmyk2hex({ c: 73, m: 45, y: 0, k: 4 })).toStrictEqual('#4287f5');
// expect(cmyk2hex('')).toThrow(new Error(' is not a cmyk color.'))
});

@@ -36,4 +34,3 @@ ////////////////////////////////////////////////////////

expect(cmyk2hsl({ c: 0, m: 95, y: 93, k: 5 })).toStrictEqual({ h: 359, s: 90, l: 50 });
// expect(cmyk2hsl('')).toThrow(new Error(' is not a cmyk color.'))
});
//# sourceMappingURL=cmyk.test.js.map

@@ -10,3 +10,2 @@ import { color2string, color2cssString } from '../index';

expect(color2string({ c: 0, m: 0, y: 0, k: 0 })).toBe('0%, 0%, 0%, 0%');
// expect(color2string('')).toThrow(new Error(' is not a color.'))
});

@@ -21,4 +20,3 @@ ////////////////////////////////////////////////////////

expect(color2cssString({ c: 0, m: 0, y: 0, k: 0 })).toBe('cmyk(0%, 0%, 0%, 0%)');
// expect(color2cssString('')).toThrow(new Error(' is not a color.'))
});
//# sourceMappingURL=color.test.js.map

@@ -8,3 +8,2 @@ import { hex2rgbOrRgba, hex2rgba, hex2hexWithAlpha, hex2cmyk, hex2hsl } from '../index';

expect(hex2rgbOrRgba('#00000000')).toStrictEqual({ r: 0, g: 0, b: 0, a: 0 });
// expect(hex2rgbOrRgba('')).toThrow(new Error(' is not a hex color.'))
});

@@ -20,4 +19,2 @@ ////////////////////////////////////////////////////////

expect(hex2rgba('#000000', 0.5)).toStrictEqual({ r: 0, g: 0, b: 0, a: 0.5 });
// expect(hex2rgba('')).toThrow(new Error(' is not a hex color.'))
// expect(hex2rgba('#000000', 3)).toThrow(new Error('3 is not in the range [0, 1].'))
});

@@ -31,4 +28,2 @@ ////////////////////////////////////////////////////////

expect(hex2hexWithAlpha('#000', 1)).toBe('#000ff');
// expect(hex2hexWithAlpha('')).toThrow(new Error(' is not a hex color.'))
// expect(hex2hexWithAlpha('#000000', 3)).toThrow(new Error('3 is not in the range [0, 1].'))
});

@@ -44,3 +39,2 @@ ////////////////////////////////////////////////////////

expect(hex2cmyk('#00000000')).toStrictEqual({ c: 0, m: 0, y: 0, k: 100 });
// expect(hex2cmyk('')).toThrow(new Error(' is not a hex color.'))
});

@@ -61,4 +55,3 @@ ////////////////////////////////////////////////////////

expect(hex2hsl('#f20d11')).toEqual({ h: 359, s: 90, l: 50 });
// expect(hex2hsl('')).toThrow(new Error(' is not a hex color.'))
});
//# sourceMappingURL=hex.test.js.map

@@ -16,3 +16,2 @@ import { hsl2hex, hsl2rgb, hsl2cmyk } from '../index';

expect(hsl2hex({ h: 359, s: 90, l: 50 })).toEqual('#f20d11');
// expect(hsl2hex('')).toThrow(new Error(' is not a hex color.'))
});

@@ -34,3 +33,2 @@ ////////////////////////////////////////////////////////

expect(hsl2rgb({ h: 359, s: 90, l: 50 })).toStrictEqual({ r: 242, g: 13, b: 17 }); // angleRangeIndex = 5
// expect(hsl2rgb('')).toThrow(new Error(' is not a hex color.'))
});

@@ -51,4 +49,3 @@ ////////////////////////////////////////////////////////

expect(hsl2cmyk({ h: 359, s: 90, l: 50 })).toStrictEqual({ c: 0, m: 95, y: 93, k: 5 });
// expect(hsl2cmyk('')).toThrow(new Error(' is not a hex color.'))
});
//# sourceMappingURL=hsl.test.js.map

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

import { rgb2hex, rgb2cmyk, rgb2hsl } from '../index';
import { rgb2hex, rgb2cmyk, rgb2hsl, rgba2rgb, rgb2rgba, color2rgb } from '../index';
////////////////////////////////////////////////////////

@@ -8,3 +8,2 @@ // rgb2hex

expect(rgb2hex({ r: 255, g: 255, b: 255 })).toBe('#ffffff');
// expect(rgb2hex({})).toThrow(new Error('{} is not a rgb color.'))
});

@@ -18,3 +17,2 @@ ////////////////////////////////////////////////////////

expect(rgb2cmyk({ r: 66, g: 135, b: 245 })).toStrictEqual({ c: 73, m: 45, y: 0, k: 4 });
// expect(rgb2cmyk('')).toThrow(new Error(' is not a rgb color.'))
});

@@ -35,4 +33,25 @@ ////////////////////////////////////////////////////////

expect(rgb2hsl({ r: 242, g: 13, b: 17 })).toStrictEqual({ h: 359, s: 90, l: 50 });
// expect(rgb2hsl('')).toThrow(new Error(' is not a rgb color.'))
});
////////////////////////////////////////////////////////
// rgba2rgb
////////////////////////////////////////////////////////
test("rgba2rgb", function () {
expect(rgba2rgb({ r: 0, g: 0, b: 0, a: 0 })).toStrictEqual({ r: 0, g: 0, b: 0 });
});
////////////////////////////////////////////////////////
// rgb2rgba
////////////////////////////////////////////////////////
test("rgb2rgba", function () {
expect(rgb2rgba({ r: 0, g: 0, b: 0 })).toStrictEqual({ r: 0, g: 0, b: 0, a: 1 });
});
////////////////////////////////////////////////////////
// color2rgb
////////////////////////////////////////////////////////
test("color2rgb", function () {
expect(color2rgb('#FFFFFF')).toStrictEqual({ r: 255, g: 255, b: 255 });
expect(color2rgb({ r: 0, g: 0, b: 0 })).toStrictEqual({ r: 0, g: 0, b: 0 });
expect(color2rgb({ r: 0, g: 0, b: 0, a: 1 })).toStrictEqual({ r: 0, g: 0, b: 0 });
expect(color2rgb({ c: 0, m: 0, y: 0, k: 0 })).toStrictEqual({ r: 255, g: 255, b: 255 });
expect(color2rgb({ h: 0, s: 0, l: 0 })).toStrictEqual({ r: 0, g: 0, b: 0 });
});
//# sourceMappingURL=rgb.test.js.map

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

import { HEX, RGB, RGBA, CMYK, COLOR, HSL } from './types';
import { HEX, RGB, RGBA, CMYK, Color, HSL } from './types';
export declare function isHex(color: any): color is HEX;

@@ -7,2 +7,2 @@ export declare function isRgb(color: any): color is RGB;

export declare function isHsl(color: any): color is HSL;
export declare function isColor(color: any): color is COLOR;
export declare function isColor(color: any): color is Color;

@@ -73,4 +73,4 @@ import { between, sameContent } from '../lib/utils';

export function isColor(color) {
return isHex(color) || isRgb(color) || isRgba(color) || isCmyk(color);
return isHex(color) || isRgb(color) || isRgba(color) || isCmyk(color) || isHsl(color);
}
//# sourceMappingURL=isType.js.map

@@ -24,2 +24,4 @@ export declare type HEX = string;

};
export declare type COLOR = HEX | RGB | RGBA | CMYK | HSL;
export declare type Color = HEX | RGB | RGBA | CMYK | HSL;
export declare type ColorFormat = 'hex' | 'rgb' | 'rgba' | 'cmyk' | 'hsl';
export declare type ColorName = string;
{
"name": "colors-convert",
"version": "1.1.1",
"version": "1.1.2",
"main": "dist/index.js",

@@ -5,0 +5,0 @@ "types": "dist/index.d.ts",

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

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

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

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc