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.
colortranslator
Advanced tools
A JavaScript library, written in TypeScript, to convert among different color models
A JavaScript library, written in TypeScript, to convert among different color models
https://elchininet.github.io/ColorTranslator/
npm install colortranslator
yarn add colortranslator
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.
colortranslator.web.js
, located in the dist
folder<script src="wherever/you/instelled/colortranslator.web.js"></script>
const { ColorTranslator } = require('colortranslator');
import { ColorTranslator } from 'colortranslator';
/* 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;
npm run build
Transpiles the TypeScript code and creates two bundles in the dist
folder (colortranslator.node.js
for Node environments and colortranslator.web.js
to use directly in the browser).
npm run test
Runs multiple dynamic tests converting from / to all the color models available (excepting CMYK) using a table of colors.
npm run lint
Runs eslint in source files.
npm run demo
Opens a development server that provides live reloading using webpack-dev-server. Some demo examples located in the @demo
folder will be shown. You can modify the code of the demos and the changes will be live reloaded in the browser.
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.
It is possible to convert from a CSS string or an object.
Example of CSS string inputs | Description |
---|---|
#FF00FF | Hexadecimal color |
#F0F | Shorthand hexadecimal color |
#FF00FF80 | Hexadecimal color with alpha |
rgb(255, 0, 255) | Functional RGB notation |
rgba(255, 0, 255, 0.5) | Functional RGB notation with alpha |
hsl(300, 100%, 50%) | Functional HSL notation |
hsla(300, 100%, 50%, 0.5) | Functional HSL notation with alpha |
cmyk(0%, 100%, 100%, 0%) | Functional CMYK notation with percentages |
cmyk(0, 1, 1, 0) | Functional CMYK notation with numbers |
device-cmyk(0%, 100%, 100%, 0%) | Device-dependent functional CMYK notation with percentages |
device-cmyk(0, 1, 1, 0) | Device-dependent functional CMYK notation with numbers |
Example of object inputs | Description |
---|---|
{r: "0xFF", g: "0x00", b: "0xFF"} | Hexadecimal color |
{r: "0xF", g: "0x0", b: "0xF"} | Shorthand hexadecimal color |
{r: "0xFF", g: "0x00", b: "0xFF", a: "0x80"} | Hexadecimal color with alpha |
{r: 255, g: 0, b: 255} | RGB notation |
{r: 255, g: 0, b: 255, a: 0.5} | RGB notation with alpha |
{h: 300, s: "100%", l: "50%"} | HSL notation |
{h: 300, s: "100%", l: "50%", a: 0.5} | HSL notation with alpha |
{c: "0%", m: "100%", y: "100%", k: "0%"} | CMYK notation with percentages |
{c: 0, m: 1, y: 1, k: 0} | CMYK notation with numbers |
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:
anyMethod(color: string | object, css: boolean = true)
Available methods | Description |
---|---|
toHEX | Convert to an hexadecimal notation |
toHEXA | Convert to an hexadecimal notation with alpha |
toRGB | Convert to an RGB notation |
toRGBA | Convert to an RGB notation with alpha |
toHSL | Convert to an HSL notation |
toHSLA | Convert to an HSL notation with alpha |
toCMYK | Convert to a CMYK notation |
Note: The conversion to a CMYK color is made taking a random value of black as a base (in this case, taking the greater value from red, green or blue). When a value of black is assumed, the rest of the colors can be calculated from it. The result will be visually similar to the original light color, but if you try to convert it back you will not obtain the same original value.
ColorTranslator.toRGB('#FF00FF'); // rgb(255,0,255)
ColorTranslator.toRGBA('hsl(50, 20%, 90%)'); // rgba(235,233,224,1)
ColorTranslator.toHSL('rgb(255, 0, 0)'); // hsl(0,100%,50%)
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.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)
[1.0.5] - 2019-07-05
FAQs
A JavaScript library, written in TypeScript, to convert among different color models
The npm package colortranslator receives a total of 15,396 weekly downloads. As such, colortranslator popularity was classified as popular.
We found that colortranslator 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.