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

@lephenix47/color-converter

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lephenix47/color-converter - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

8

dist/lib/commonjs/classes/color-conversion.classes.d.ts

@@ -89,3 +89,3 @@ import { RedGreenBlue, HueSaturationLightness, HueWhitenessBlackness, HueSaturationValue, CyanMagentaYellowKey, ColorRepresentation } from "../variables/color-types.variables";

* @param {string} currentModel - The current color model.
* @param {string|RedGreenBlue|HueSaturationLightness|HueWhitenessBlackness|HueSaturationValue} color - The color value.
* @param {ColorRepresentation} color - The color value.
*/

@@ -106,5 +106,5 @@ constructor(currentModel: string, color: ColorRepresentation);

* @param {string} targetModel - The target color model.
* @returns {string|RedGreenBlue|HueSaturationLightness|HueWhitenessBlackness|HueSaturationValue} The converted color value.
* @returns {ColorRepresentation} The converted color value.
*/
convertTo(targetModel: string): ColorRepresentation;
convertTo(targetModel: string, needToStringify?: boolean): ColorRepresentation;
/**

@@ -114,3 +114,3 @@ * Retrieves all color models for the current color.

*/
getAllColorModels(): ColorRepresentation[];
getAllColorModels(needToStringify?: boolean): ColorRepresentation[];
}

@@ -505,3 +505,3 @@ "use strict";

* @param {string} currentModel - The current color model.
* @param {string|RedGreenBlue|HueSaturationLightness|HueWhitenessBlackness|HueSaturationValue} color - The color value.
* @param {ColorRepresentation} color - The color value.
*/

@@ -520,2 +520,10 @@ function ColorConverter(currentModel, color) {

ColorConverter.prototype.normalizeToRgb = function () {
var unitREGEX = /deg|°|%/g;
var isString = typeof this.color === "string";
var values = "";
if (isString) {
values = this.color.split("(")[1];
values = values.slice(0, values.length - 1);
values = values.replace(unitREGEX, "");
}
switch (this.currentModel) {

@@ -527,2 +535,10 @@ case "hex": {

case "rgb": {
if (isString) {
var _a = values.split(","), red = _a[0], green = _a[1], blue = _a[2];
this.color = {
red: Number(red),
green: Number(green),
blue: Number(blue),
};
}
this.normalizedColor = this.color;

@@ -532,2 +548,10 @@ break;

case "hsl": {
if (isString) {
var _b = values.split(","), hue = _b[0], saturation = _b[1], lightness = _b[2];
this.color = {
hue: Number(hue),
saturation: Number(saturation),
lightness: Number(lightness),
};
}
this.normalizedColor = this.fromHslToRgb(this.color);

@@ -537,2 +561,10 @@ break;

case "hwb": {
if (isString) {
var _c = values.split(","), hue = _c[0], whiteness = _c[1], blackness = _c[2];
this.color = {
hue: Number(hue),
whiteness: Number(whiteness),
blackness: Number(blackness),
};
}
this.normalizedColor = this.fromHwbToRgb(this.color);

@@ -542,2 +574,10 @@ break;

case "hsv": {
if (isString) {
var _d = values.split(","), hue = _d[0], saturation = _d[1], value = _d[2];
this.color = {
hue: Number(hue),
saturation: Number(saturation),
value: Number(value),
};
}
this.normalizedColor = this.fromHsvToRgb(this.color);

@@ -547,2 +587,11 @@ break;

case "cmyk": {
if (isString) {
var _e = values.split(","), cyan = _e[0], magenta = _e[1], yellow = _e[2], key = _e[3];
this.color = {
cyan: Number(cyan),
magenta: Number(magenta),
yellow: Number(yellow),
key: Number(key),
};
}
this.normalizedColor = this.fromCmykToRgb(this.color);

@@ -573,5 +622,6 @@ break;

* @param {string} targetModel - The target color model.
* @returns {string|RedGreenBlue|HueSaturationLightness|HueWhitenessBlackness|HueSaturationValue} The converted color value.
* @returns {ColorRepresentation} The converted color value.
*/
ColorConverter.prototype.convertTo = function (targetModel) {
ColorConverter.prototype.convertTo = function (targetModel, needToStringify) {
if (needToStringify === void 0) { needToStringify = false; }
targetModel = targetModel.toLowerCase();

@@ -583,19 +633,40 @@ switch (targetModel) {

case "rgb": {
return this.normalizedColor;
var _a = this.normalizedColor, red = _a.red, green = _a.green, blue = _a.blue;
if (needToStringify) {
return "rgb(".concat(red, ", ").concat(green, ", ").concat(blue, ")");
}
return { red: red, green: green, blue: blue };
}
case "hsl": {
return this.fromRgbToHsl(this.normalizedColor);
var _b = this.fromRgbToHsl(this.normalizedColor), hue = _b.hue, saturation = _b.saturation, lightness = _b.lightness;
if (needToStringify) {
return "hsl(".concat(hue, "\u00B0, ").concat(saturation, "%, ").concat(lightness, "%)");
}
return { hue: hue, saturation: saturation, lightness: lightness };
}
case "hwb": {
return this.fromRgbToHwb(this.normalizedColor);
var _c = this.fromRgbToHwb(this.normalizedColor), hue = _c.hue, whiteness = _c.whiteness, blackness = _c.blackness;
if (needToStringify) {
return "hwb(".concat(hue, "\u00B0, ").concat(whiteness, "%, ").concat(blackness, "%)");
}
return { hue: hue, whiteness: whiteness, blackness: blackness };
}
case "hsv": {
return this.fromRgbToHsv(this.normalizedColor);
var _d = this.fromRgbToHsv(this.normalizedColor), hue = _d.hue, saturation = _d.saturation, value = _d.value;
if (needToStringify) {
return "hsv(".concat(hue, "\u00B0, ").concat(saturation, "%, ").concat(value, "%)");
}
return { hue: hue, saturation: saturation, value: value };
}
case "cmyk": {
return this.fromRgbToCmyk(this.normalizedColor);
var _e = this.fromRgbToCmyk(this.normalizedColor), cyan = _e.cyan, magenta = _e.magenta, yellow = _e.yellow, key = _e.key;
if (needToStringify) {
return "cmyk(".concat(cyan, "%, ").concat(magenta, "%, ").concat(yellow, "%, ").concat(key, "%)");
}
return { cyan: cyan, magenta: magenta, yellow: yellow, key: key };
}
case "name": {
var hexColor = this.fromRgbToHex(this.normalizedColor);
return this.fromHexToName(hexColor);
var name_1 = this.fromHexToName(hexColor);
return name_1;
}

@@ -611,3 +682,4 @@ default: {

*/
ColorConverter.prototype.getAllColorModels = function () {
ColorConverter.prototype.getAllColorModels = function (needToStringify) {
if (needToStringify === void 0) { needToStringify = false; }
var hexColor = this.fromRgbToHex(this.normalizedColor);

@@ -620,2 +692,13 @@ var rgbColor = this.normalizedColor;

var nameColor = this.fromHexToName(hexColor);
if (needToStringify) {
return [
nameColor || "N/A",
hexColor,
"rgb(".concat(rgbColor.red, "\u00B0, ").concat(rgbColor.green, "%, ").concat(rgbColor.blue, "%)"),
"hsl(".concat(hslColor.hue, "\u00B0, ").concat(hslColor.saturation, "%, ").concat(hslColor.lightness, "%)"),
"hwb(".concat(hwbColor.hue, "\u00B0, ").concat(hwbColor.whiteness, "%, ").concat(hwbColor.blackness, "%)"),
"hsv(".concat(hsvColor.hue, "\u00B0, ").concat(hsvColor.saturation, "%, ").concat(hsvColor.value, "%)"),
"cmyk(".concat(cmykColor.cyan, "\u00B0, ").concat(cmykColor.magenta, "%, ").concat(cmykColor.yellow, "%, ").concat(cmykColor.key, "%)"),
];
}
return [

@@ -622,0 +705,0 @@ nameColor,

export { AbstractConversionMethods, ColorConverter, } from "./classes/color-conversion.classes";
export { RedGreenBlue, NameColor, ColorRepresentation, CyanMagentaYellowKey, HueSaturationLightness, HueSaturationValue, HueWhitenessBlackness, } from "./variables/color-types.variables";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ColorConverter = exports.AbstractConversionMethods = void 0;
//Methods
var color_conversion_classes_1 = require("./classes/color-conversion.classes");
Object.defineProperty(exports, "AbstractConversionMethods", { enumerable: true, get: function () { return color_conversion_classes_1.AbstractConversionMethods; } });
Object.defineProperty(exports, "ColorConverter", { enumerable: true, get: function () { return color_conversion_classes_1.ColorConverter; } });

@@ -89,3 +89,3 @@ import { RedGreenBlue, HueSaturationLightness, HueWhitenessBlackness, HueSaturationValue, CyanMagentaYellowKey, ColorRepresentation } from "../variables/color-types.variables";

* @param {string} currentModel - The current color model.
* @param {string|RedGreenBlue|HueSaturationLightness|HueWhitenessBlackness|HueSaturationValue} color - The color value.
* @param {ColorRepresentation} color - The color value.
*/

@@ -106,5 +106,5 @@ constructor(currentModel: string, color: ColorRepresentation);

* @param {string} targetModel - The target color model.
* @returns {string|RedGreenBlue|HueSaturationLightness|HueWhitenessBlackness|HueSaturationValue} The converted color value.
* @returns {ColorRepresentation} The converted color value.
*/
convertTo(targetModel: string): ColorRepresentation;
convertTo(targetModel: string, needToStringify?: boolean): ColorRepresentation;
/**

@@ -114,3 +114,3 @@ * Retrieves all color models for the current color.

*/
getAllColorModels(): ColorRepresentation[];
getAllColorModels(needToStringify?: boolean): ColorRepresentation[];
}

@@ -502,3 +502,3 @@ var __extends = (this && this.__extends) || (function () {

* @param {string} currentModel - The current color model.
* @param {string|RedGreenBlue|HueSaturationLightness|HueWhitenessBlackness|HueSaturationValue} color - The color value.
* @param {ColorRepresentation} color - The color value.
*/

@@ -517,2 +517,10 @@ function ColorConverter(currentModel, color) {

ColorConverter.prototype.normalizeToRgb = function () {
var unitREGEX = /deg|°|%/g;
var isString = typeof this.color === "string";
var values = "";
if (isString) {
values = this.color.split("(")[1];
values = values.slice(0, values.length - 1);
values = values.replace(unitREGEX, "");
}
switch (this.currentModel) {

@@ -524,2 +532,10 @@ case "hex": {

case "rgb": {
if (isString) {
var _a = values.split(","), red = _a[0], green = _a[1], blue = _a[2];
this.color = {
red: Number(red),
green: Number(green),
blue: Number(blue),
};
}
this.normalizedColor = this.color;

@@ -529,2 +545,10 @@ break;

case "hsl": {
if (isString) {
var _b = values.split(","), hue = _b[0], saturation = _b[1], lightness = _b[2];
this.color = {
hue: Number(hue),
saturation: Number(saturation),
lightness: Number(lightness),
};
}
this.normalizedColor = this.fromHslToRgb(this.color);

@@ -534,2 +558,10 @@ break;

case "hwb": {
if (isString) {
var _c = values.split(","), hue = _c[0], whiteness = _c[1], blackness = _c[2];
this.color = {
hue: Number(hue),
whiteness: Number(whiteness),
blackness: Number(blackness),
};
}
this.normalizedColor = this.fromHwbToRgb(this.color);

@@ -539,2 +571,10 @@ break;

case "hsv": {
if (isString) {
var _d = values.split(","), hue = _d[0], saturation = _d[1], value = _d[2];
this.color = {
hue: Number(hue),
saturation: Number(saturation),
value: Number(value),
};
}
this.normalizedColor = this.fromHsvToRgb(this.color);

@@ -544,2 +584,11 @@ break;

case "cmyk": {
if (isString) {
var _e = values.split(","), cyan = _e[0], magenta = _e[1], yellow = _e[2], key = _e[3];
this.color = {
cyan: Number(cyan),
magenta: Number(magenta),
yellow: Number(yellow),
key: Number(key),
};
}
this.normalizedColor = this.fromCmykToRgb(this.color);

@@ -570,5 +619,6 @@ break;

* @param {string} targetModel - The target color model.
* @returns {string|RedGreenBlue|HueSaturationLightness|HueWhitenessBlackness|HueSaturationValue} The converted color value.
* @returns {ColorRepresentation} The converted color value.
*/
ColorConverter.prototype.convertTo = function (targetModel) {
ColorConverter.prototype.convertTo = function (targetModel, needToStringify) {
if (needToStringify === void 0) { needToStringify = false; }
targetModel = targetModel.toLowerCase();

@@ -580,19 +630,40 @@ switch (targetModel) {

case "rgb": {
return this.normalizedColor;
var _a = this.normalizedColor, red = _a.red, green = _a.green, blue = _a.blue;
if (needToStringify) {
return "rgb(".concat(red, ", ").concat(green, ", ").concat(blue, ")");
}
return { red: red, green: green, blue: blue };
}
case "hsl": {
return this.fromRgbToHsl(this.normalizedColor);
var _b = this.fromRgbToHsl(this.normalizedColor), hue = _b.hue, saturation = _b.saturation, lightness = _b.lightness;
if (needToStringify) {
return "hsl(".concat(hue, "\u00B0, ").concat(saturation, "%, ").concat(lightness, "%)");
}
return { hue: hue, saturation: saturation, lightness: lightness };
}
case "hwb": {
return this.fromRgbToHwb(this.normalizedColor);
var _c = this.fromRgbToHwb(this.normalizedColor), hue = _c.hue, whiteness = _c.whiteness, blackness = _c.blackness;
if (needToStringify) {
return "hwb(".concat(hue, "\u00B0, ").concat(whiteness, "%, ").concat(blackness, "%)");
}
return { hue: hue, whiteness: whiteness, blackness: blackness };
}
case "hsv": {
return this.fromRgbToHsv(this.normalizedColor);
var _d = this.fromRgbToHsv(this.normalizedColor), hue = _d.hue, saturation = _d.saturation, value = _d.value;
if (needToStringify) {
return "hsv(".concat(hue, "\u00B0, ").concat(saturation, "%, ").concat(value, "%)");
}
return { hue: hue, saturation: saturation, value: value };
}
case "cmyk": {
return this.fromRgbToCmyk(this.normalizedColor);
var _e = this.fromRgbToCmyk(this.normalizedColor), cyan = _e.cyan, magenta = _e.magenta, yellow = _e.yellow, key = _e.key;
if (needToStringify) {
return "cmyk(".concat(cyan, "%, ").concat(magenta, "%, ").concat(yellow, "%, ").concat(key, "%)");
}
return { cyan: cyan, magenta: magenta, yellow: yellow, key: key };
}
case "name": {
var hexColor = this.fromRgbToHex(this.normalizedColor);
return this.fromHexToName(hexColor);
var name_1 = this.fromHexToName(hexColor);
return name_1;
}

@@ -608,3 +679,4 @@ default: {

*/
ColorConverter.prototype.getAllColorModels = function () {
ColorConverter.prototype.getAllColorModels = function (needToStringify) {
if (needToStringify === void 0) { needToStringify = false; }
var hexColor = this.fromRgbToHex(this.normalizedColor);

@@ -617,2 +689,13 @@ var rgbColor = this.normalizedColor;

var nameColor = this.fromHexToName(hexColor);
if (needToStringify) {
return [
nameColor || "N/A",
hexColor,
"rgb(".concat(rgbColor.red, "\u00B0, ").concat(rgbColor.green, "%, ").concat(rgbColor.blue, "%)"),
"hsl(".concat(hslColor.hue, "\u00B0, ").concat(hslColor.saturation, "%, ").concat(hslColor.lightness, "%)"),
"hwb(".concat(hwbColor.hue, "\u00B0, ").concat(hwbColor.whiteness, "%, ").concat(hwbColor.blackness, "%)"),
"hsv(".concat(hsvColor.hue, "\u00B0, ").concat(hsvColor.saturation, "%, ").concat(hsvColor.value, "%)"),
"cmyk(".concat(cmykColor.cyan, "\u00B0, ").concat(cmykColor.magenta, "%, ").concat(cmykColor.yellow, "%, ").concat(cmykColor.key, "%)"),
];
}
return [

@@ -619,0 +702,0 @@ nameColor,

export { AbstractConversionMethods, ColorConverter, } from "./classes/color-conversion.classes";
export { RedGreenBlue, NameColor, ColorRepresentation, CyanMagentaYellowKey, HueSaturationLightness, HueSaturationValue, HueWhitenessBlackness, } from "./variables/color-types.variables";

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

//Methods
export { AbstractConversionMethods, ColorConverter, } from "./classes/color-conversion.classes";
{
"name": "@lephenix47/color-converter",
"version": "1.1.1",
"version": "1.2.0",
"description": "This is a versatile color conversion library for JavaScript. It provides a convenient way to convert color values between different color models, including color names, RGB, HEX, HSL, HWB, HSV and CMYK. With @lephenix47/color-converter, you can effortlessly convert colors, normalize them to a consistent format, and retrieve color values in various color models.",

@@ -5,0 +5,0 @@ "main": "dist/lib/es6/index.js",

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