Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
The hsluv npm package provides a human-friendly alternative to the HSL (Hue, Saturation, Lightness) color space. It aims to make it easier to work with colors in a way that is perceptually uniform, meaning that changes in lightness or saturation appear consistent to the human eye.
Convert HSLuv to RGB
This feature allows you to convert HSLuv color values to RGB color values. The code sample demonstrates converting an HSLuv color with hue 0, saturation 100, and lightness 50 to its RGB equivalent.
const hsluv = require('hsluv');
const rgb = hsluv.hsluvToRgb([0, 100, 50]);
console.log(rgb); // [1, 0, 0]
Convert RGB to HSLuv
This feature allows you to convert RGB color values to HSLuv color values. The code sample demonstrates converting an RGB color with values [1, 0, 0] to its HSLuv equivalent.
const hsluv = require('hsluv');
const hsluvColor = hsluv.rgbToHsluv([1, 0, 0]);
console.log(hsluvColor); // [0, 100, 50]
Convert HSLuv to Hex
This feature allows you to convert HSLuv color values to Hex color values. The code sample demonstrates converting an HSLuv color with hue 0, saturation 100, and lightness 50 to its Hex equivalent.
const hsluv = require('hsluv');
const hex = hsluv.hsluvToHex([0, 100, 50]);
console.log(hex); // '#ff0000'
Convert Hex to HSLuv
This feature allows you to convert Hex color values to HSLuv color values. The code sample demonstrates converting a Hex color '#ff0000' to its HSLuv equivalent.
const hsluv = require('hsluv');
const hsluvColor = hsluv.hexToHsluv('#ff0000');
console.log(hsluvColor); // [0, 100, 50]
Chroma.js is a JavaScript library for color conversions and color scales. It supports a wide range of color spaces including RGB, HSL, and LAB. Compared to hsluv, chroma-js offers more extensive functionality for color manipulation and generation, but it does not specifically focus on the perceptual uniformity that HSLuv provides.
The color package is a JavaScript library for color conversion and manipulation. It supports various color models such as RGB, HSL, and CMYK. While it provides a broad range of color manipulation features, it does not focus on the perceptual uniformity that HSLuv aims to achieve.
TinyColor is a small color manipulation and conversion library. It supports multiple color formats including RGB, HSL, and Hex. TinyColor is lightweight and easy to use, but it does not offer the perceptual uniformity features that HSLuv provides.
Install from NPM package repository:
npm install hsluv
ES modules:
import {Hsluv} from "hsluv";
CommonJS:
const {Hsluv} = require("hsluv");
HTML include:
<script src="hsluv-x.x.x.min.js"></script>
to your HTMLwindow.Hsluv
The API is designed to avoid heap allocation. The HSLuv
class defines the following public fields:
hex:String
, rgb_r:Float
[0;1], rgb_g:Float
[0;1], rgb_r:Float
[0;1]xyz_x:Float
, xyz_y:Float
, xyz_z:Float
luv_l:Float
, luv_u:Float
, luv_v:Float
lch_l:Float
, lch_c:Float
, lch_h:Float
hsluv_h:Float
[0;360], hsluv_s:Float
[0;100], hsluv_l:Float
[0;100]hpluv_h:Float
[0;360], hpluv_p:Float
[0;100], hpluv_l:Float
[0;100]To convert between color spaces, simply set the properties of the source color space, run the conversion methods, then read the properties of the target color space.
Use the following methods to convert to and from RGB:
hsluvToRgb()
, hsluvToHex()
, rgbToHsluv()
, hexToHsluv()
hpluvToRgb()
, hpluvToHex()
, rgbToHpluv()
, hexToHpluv()
Use the following methods to do step-by-step conversion:
hsluvToLch()
(or hpluvToLch()
), lchToLuv()
, luvToXyz()
, xyzToRgb()
, rgbToHex()
hexToRgb()
, rgbToXyz()
, xyzToLuv()
, luvToLch()
, lchToHsluv()
(or lchToHpluv()
)For advanced usage, we also export the bounding lines in slope-intercept format, two for each RGB channel representing the limit of the gamut.
r0s
, r0i
r1s
, r1i
g0s
, g0i
g1s
, g1i
b0s
, b0i
b1s
, b1i
Example:
var conv = new Hsluv();
conv.hsluv_h = 10;
conv.hsluv_s = 75;
conv.hsluv_l = 65;
conv.hsluvToHex();
console.log(conv.hex); // Will print "#ec7d82"
Also available for Stylus. See here.
Our GitHub Actions workflow
will build and test every push and PR to the main
branch. When a main
branch receives a commit that
updates the project version in package.json
, the workflow will tag the commit, create a draft release
on GitHub and publish the npm package. Mark your versions with the -rc
suffix to create pre-releases.
FAQs
Human-friendly HSL
The npm package hsluv receives a total of 209,489 weekly downloads. As such, hsluv popularity was classified as popular.
We found that hsluv demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.