New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@palett/dye-factory

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@palett/dye-factory - npm Package Compare versions

Comparing version 0.8.14 to 0.8.15

304

dist/index.cjs.js

@@ -6,276 +6,6 @@ 'use strict';

var enumColorSpace = require('@palett/enum-color-space');
var oneself = require('@ject/oneself');
var enumAnsiCodes = require('@palett/enum-ansi-codes');
var convert = require('@palett/convert');
var utilAnsi = require('@palett/util-ansi');
const CSI = '[';
const SGR = 'm';
// // // // // // // // // // //
const BOL_ON = '1'; // BOLD / INCREASE_INTENSITY
const DIM_ON = '2'; // DIM / DECREASE_INTENSITY / FAINT
const ITA_ON = '3'; // ITALIC
const UND_ON = '4'; // UNDERLINE
const BLI_ON = '5'; // BLINK
const INV_ON = '7'; // INVERSE
const HID_ON = '8'; // HIDE / CONCEAL
const CRO_ON = '9'; // CROSSED_OUT / STRIKE
// // // // // // // // // // //
const BOL_OFF = '21'; // NOT_BOLD / DOUBLE_UNDERLINE
const DIM_OFF = '22'; // NOT_DIM / NORMAL_INTENSITY
const ITA_OFF = '23'; // NOT_ITALIC
const UND_OFF = '24'; // NOT_UNDERLINE
const BLI_OFF = '25'; // NOT_BLINK
const INV_OFF = '27'; // NOT_INVERSE
const HID_OFF = '28'; // NOT_HIDE / REVEAL
const CRO_OFF = '29'; // NOT_CROSSED_OUT / UNSTRIKE
const FORE_INI = '38;2'; // SET_FORECOLOR (24 bit (true-color))
const FORE_DEF = '39'; // DEFAULT_FORECOLOR
/**
*
* applicable for smaller number
* @param {number} x
* @returns {number}
*/
const round = x => x + (x > 0 ? 0.5 : -0.5) << 0;
const rgbToInt = ([r, g, b]) => ((r & 0xFF) << 16) + ((g & 0xFF) << 8) + (b & 0xFF);
function hexAt(tx, i) {
let n = tx.charCodeAt(i);
return n >> 5 <= 1 ? n & 0xf : (n & 0x7) + 9;
}
const prolif = n => n << 4 | n;
function dil6(hex) {
const hi = hex.length;
if (hi >= 6) return hex;
if (hi === 5) return '0' + hex;
if (hi === 4) return '00' + hex;
if (hi === 3) return '000' + hex;
if (hi === 2) return '0000' + hex;
if (hi === 1) return '00000' + hex;
if (hi <= 0) return '000000';
}
/**
* @param {[number,number,number]} rgb
* @returns {string}
*/
const rgbToHex = rgb => '#' + dil6(rgbToInt(rgb).toString(16));
const bound = ([r, g, b]) => {
let ma = r,
mi = r;
if (g > r) {
ma = g;
} else {
mi = g;
}
if (b > ma) ma = b;
if (b < mi) mi = b;
return {
max: ma,
sum: ma + mi,
dif: ma - mi
};
};
const hue = (r, g, b, max, dif) => {
if (dif === 0) return 0;
switch (max) {
case r:
return ((g - b) / dif + (g < b ? 6 : 0)) % 6;
case g:
return (b - r) / dif + 2;
case b:
return (r - g) / dif + 4;
}
};
const THOUSAND$1 = 1000;
/**
* !dif: dif===0
* @param {number} r - [0,255]
* @param {number} g - [0,255]
* @param {number} b - [0,255]
* @returns {[number,number,number]} [Hue([0,360]), Saturation([0,100]), Lightness([0,100])]
*/
function rgbToHsl([r, g, b]) {
r /= 255;
g /= 255;
b /= 255;
const {
max,
sum,
dif
} = bound([r, g, b]);
let h = hue(r, g, b, max, dif) * 60,
s = !dif ? 0 : sum > 1 ? dif / (2 - sum) : dif / sum,
l = sum / 2;
return [round(h), round(s * THOUSAND$1) / 10, round(l * THOUSAND$1) / 10];
}
/**
* @param {string} hex
* @returns {number}
*/
function hexToInt(hex) {
let lo = 0,
hi = hex.length;
if (hi === 7) lo++, hi--;
if (hi === 6) {
const r = hexAt(hex, lo++) << 4 | hexAt(hex, lo++);
const g = hexAt(hex, lo++) << 4 | hexAt(hex, lo++);
const b = hexAt(hex, lo++) << 4 | hexAt(hex, lo++);
return r << 16 | g << 8 | b;
}
if (hi === 4) lo++, hi--;
if (hi === 3) {
return prolif(hexAt(hex, lo++)) << 16 | prolif(hexAt(hex, lo++)) << 8 | prolif(hexAt(hex, lo++));
}
return 0;
}
/**
*
* @param {string} hex
* @returns {number[]}
*/
function hexToRgb(hex) {
const int = hexToInt(hex);
return [int >> 16 & 0xFF, int >> 8 & 0xFF, int & 0xFF];
}
const THOUSAND = 1000;
/**
* !dif: dif===0
* @param {number} int
* @returns {[number,number,number]} [Hue([0,360]), Saturation([0,100]), Lightness([0,100])]
*/
function intToHsl(int) {
let r = int >> 16 & 0xFF,
g = int >> 8 & 0xFF,
b = int & 0xFF;
r /= 255;
g /= 255;
b /= 255;
const {
max,
sum,
dif
} = bound([r, g, b]);
let h = hue(r, g, b, max, dif) * 60,
s = !dif ? 0 : sum > 1 ? dif / (2 - sum) : dif / sum,
l = sum / 2;
return [round(h), round(s * THOUSAND) / 10, round(l * THOUSAND) / 10];
}
const hexToHsl = hex => {
var _ref, _hex;
return _ref = (_hex = hex, hexToInt(_hex)), intToHsl(_ref);
};
/**
*
* @param {number} n
* @param {number} h
* @param {number} a
* @param {number} l
* @returns {number}
*/
const hf = (n, h, a, l) => {
const k = (n + h / 30) % 12;
return l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
};
/**
*
* @param {number} h
* @param {number} s
* @param {number} l
* @returns {number[]}
*/
function hslToRgb([h, s, l]) {
s /= 100;
l /= 100;
const a = s * Math.min(l, 1 - l),
r = hf(0, h, a, l),
g = hf(8, h, a, l),
b = hf(4, h, a, l);
return [round(r * 0xFF), round(g * 0xFF), round(b * 0xFF)]; // return [r * 0xFF & 0xFF, g * 0xFF & 0xFF, b * 0xFF & 0xFF]
}
const hslToHex = hsl => {
var _ref, _hsl;
return _ref = (_hsl = hsl, hslToRgb(_hsl)), rgbToHex(_ref);
};
/**
*
* @param {number} h
* @param {number} s
* @param {number} l
* @returns {number}
*/
function hslToInt([h, s, l]) {
s /= 100;
l /= 100;
const a = s * Math.min(l, 1 - l),
r = hf(0, h, a, l),
g = hf(8, h, a, l),
b = hf(4, h, a, l);
return ((round(r * 0xFF) & 0xFF) << 16) + ((round(g * 0xFF) & 0xFF) << 8) + (round(b * 0xFF) & 0xFF);
}
const intToRgb = n => [n >> 16 & 0xFF, n >> 8 & 0xFF, n & 0xFF];
const intToHex = int => '#' + dil6(int.toString(16));
var _class, _temp, _class2, _temp2, _class3, _temp3, _class4, _temp4;
(_temp = _class = class Rgb {}, _class.rgb = oneself.oneself, _class.hex = rgbToHex, _class.hsl = rgbToHsl, _class.int = rgbToInt, _temp);
(_temp2 = _class2 = class Rgb {}, _class2.rgb = hexToRgb, _class2.hex = oneself.oneself, _class2.hsl = hexToHsl, _class2.int = hexToInt, _temp2);
(_temp3 = _class3 = class Rgb {}, _class3.rgb = hslToRgb, _class3.hex = hslToHex, _class3.hsl = oneself.oneself, _class3.int = hslToInt, _temp3);
(_temp4 = _class4 = class Rgb {}, _class4.rgb = intToRgb, _class4.hex = intToHex, _class4.hsl = intToHsl, _class4.int = oneself.oneself, _temp4);
function excite() {

@@ -291,4 +21,4 @@ if (this.head.length) this.head += ';';

excite.call(this);
this.head += FORE_INI + utilAnsi.SC + (int >> 16 & 0xFF) + utilAnsi.SC + (int >> 8 & 0xFF) + utilAnsi.SC + (int & 0xFF);
this.tail += FORE_DEF;
this.head += enumAnsiCodes.FORE_INI + utilAnsi.SC + (int >> 16 & 0xFF) + utilAnsi.SC + (int >> 8 & 0xFF) + utilAnsi.SC + (int & 0xFF);
this.tail += enumAnsiCodes.FORE_DEF;
return this;

@@ -300,4 +30,4 @@ }

excite.call(this);
this.head += FORE_INI + utilAnsi.SC + rgb[0] + utilAnsi.SC + rgb[1] + utilAnsi.SC + rgb[2];
this.tail += FORE_DEF;
this.head += enumAnsiCodes.FORE_INI + utilAnsi.SC + rgb[0] + utilAnsi.SC + rgb[1] + utilAnsi.SC + rgb[2];
this.tail += enumAnsiCodes.FORE_DEF;
return this;

@@ -310,3 +40,3 @@ }

return pushInt.call(this, (_hex = hex, hexToInt(_hex)));
return pushInt.call(this, (_hex = hex, convert.hexToInt(_hex)));
}

@@ -318,3 +48,3 @@ /** @param {number[]} hsl */

return pushRgb.call(this, (_hsl = hsl, hslToRgb(_hsl)));
return pushRgb.call(this, (_hsl = hsl, convert.hslToRgb(_hsl)));
}

@@ -329,10 +59,10 @@ const selectEncolor = space => space === enumColorSpace.RGB ? pushRgb : space === enumColorSpace.HEX ? pushHex : space === enumColorSpace.HSL ? pushHsl : space === enumColorSpace.INT ? pushInt : pushRgb;

for (let t of style) t[0] === 'b' ? (this.head += BOL_ON, this.tail += BOL_OFF // BOLD
) : t[0] === 'd' ? (this.head += DIM_ON, this.tail += DIM_OFF // DIM
) : t[0] === 'i' && t[1] === 't' ? (this.head += ITA_ON, this.tail += ITA_OFF // ITALIC
) : t[0] === 'u' ? (this.head += UND_ON, this.tail += UND_OFF // UNDERLINE
) : t[0] === 'b' ? (this.head += BLI_ON, this.tail += BLI_OFF // BLINK
) : t[0] === 'i' ? (this.head += INV_ON, this.tail += INV_OFF // INVERSE
) : t[0] === 'h' ? (this.head += HID_ON, this.tail += HID_OFF // HIDE
) : t[0] === 's' ? (this.head += CRO_ON, this.tail += CRO_OFF // STRIKE
for (let t of style) t[0] === 'b' ? (this.head += enumAnsiCodes.BOL_ON, this.tail += enumAnsiCodes.BOL_OFF // BOLD
) : t[0] === 'd' ? (this.head += enumAnsiCodes.DIM_ON, this.tail += enumAnsiCodes.DIM_OFF // DIM
) : t[0] === 'i' && t[1] === 't' ? (this.head += enumAnsiCodes.ITA_ON, this.tail += enumAnsiCodes.ITA_OFF // ITALIC
) : t[0] === 'u' ? (this.head += enumAnsiCodes.UND_ON, this.tail += enumAnsiCodes.UND_OFF // UNDERLINE
) : t[0] === 'b' ? (this.head += enumAnsiCodes.BLI_ON, this.tail += enumAnsiCodes.BLI_OFF // BLINK
) : t[0] === 'i' ? (this.head += enumAnsiCodes.INV_ON, this.tail += enumAnsiCodes.INV_OFF // INVERSE
) : t[0] === 'h' ? (this.head += enumAnsiCodes.HID_ON, this.tail += enumAnsiCodes.HID_OFF // HIDE
) : t[0] === 's' ? (this.head += enumAnsiCodes.CRO_ON, this.tail += enumAnsiCodes.CRO_OFF // STRIKE
) : void 0;

@@ -413,3 +143,3 @@

render(text) {
return CSI + this.head + SGR + text + CSI + this.tail + SGR;
return enumAnsiCodes.CSI + this.head + enumAnsiCodes.SGR + text + enumAnsiCodes.CSI + this.tail + enumAnsiCodes.SGR;
}

@@ -416,0 +146,0 @@

import { RGB, HEX, HSL, INT } from '@palett/enum-color-space';
import { oneself } from '@ject/oneself';
import { FORE_INI, FORE_DEF, BOL_ON, BOL_OFF, DIM_ON, DIM_OFF, ITA_ON, ITA_OFF, UND_ON, UND_OFF, BLI_ON, BLI_OFF, INV_ON, INV_OFF, HID_ON, HID_OFF, CRO_ON, CRO_OFF, CSI, SGR } from '@palett/enum-ansi-codes';
import { hexToInt, hslToRgb } from '@palett/convert';
import { SC } from '@palett/util-ansi';
const CSI = '[';
const SGR = 'm';
// // // // // // // // // // //
const BOL_ON = '1'; // BOLD / INCREASE_INTENSITY
const DIM_ON = '2'; // DIM / DECREASE_INTENSITY / FAINT
const ITA_ON = '3'; // ITALIC
const UND_ON = '4'; // UNDERLINE
const BLI_ON = '5'; // BLINK
const INV_ON = '7'; // INVERSE
const HID_ON = '8'; // HIDE / CONCEAL
const CRO_ON = '9'; // CROSSED_OUT / STRIKE
// // // // // // // // // // //
const BOL_OFF = '21'; // NOT_BOLD / DOUBLE_UNDERLINE
const DIM_OFF = '22'; // NOT_DIM / NORMAL_INTENSITY
const ITA_OFF = '23'; // NOT_ITALIC
const UND_OFF = '24'; // NOT_UNDERLINE
const BLI_OFF = '25'; // NOT_BLINK
const INV_OFF = '27'; // NOT_INVERSE
const HID_OFF = '28'; // NOT_HIDE / REVEAL
const CRO_OFF = '29'; // NOT_CROSSED_OUT / UNSTRIKE
const FORE_INI = '38;2'; // SET_FORECOLOR (24 bit (true-color))
const FORE_DEF = '39'; // DEFAULT_FORECOLOR
/**
*
* applicable for smaller number
* @param {number} x
* @returns {number}
*/
const round = x => x + (x > 0 ? 0.5 : -0.5) << 0;
const rgbToInt = ([r, g, b]) => ((r & 0xFF) << 16) + ((g & 0xFF) << 8) + (b & 0xFF);
function hexAt(tx, i) {
let n = tx.charCodeAt(i);
return n >> 5 <= 1 ? n & 0xf : (n & 0x7) + 9;
}
const prolif = n => n << 4 | n;
function dil6(hex) {
const hi = hex.length;
if (hi >= 6) return hex;
if (hi === 5) return '0' + hex;
if (hi === 4) return '00' + hex;
if (hi === 3) return '000' + hex;
if (hi === 2) return '0000' + hex;
if (hi === 1) return '00000' + hex;
if (hi <= 0) return '000000';
}
/**
* @param {[number,number,number]} rgb
* @returns {string}
*/
const rgbToHex = rgb => '#' + dil6(rgbToInt(rgb).toString(16));
const bound = ([r, g, b]) => {
let ma = r,
mi = r;
if (g > r) {
ma = g;
} else {
mi = g;
}
if (b > ma) ma = b;
if (b < mi) mi = b;
return {
max: ma,
sum: ma + mi,
dif: ma - mi
};
};
const hue = (r, g, b, max, dif) => {
if (dif === 0) return 0;
switch (max) {
case r:
return ((g - b) / dif + (g < b ? 6 : 0)) % 6;
case g:
return (b - r) / dif + 2;
case b:
return (r - g) / dif + 4;
}
};
const THOUSAND$1 = 1000;
/**
* !dif: dif===0
* @param {number} r - [0,255]
* @param {number} g - [0,255]
* @param {number} b - [0,255]
* @returns {[number,number,number]} [Hue([0,360]), Saturation([0,100]), Lightness([0,100])]
*/
function rgbToHsl([r, g, b]) {
r /= 255;
g /= 255;
b /= 255;
const {
max,
sum,
dif
} = bound([r, g, b]);
let h = hue(r, g, b, max, dif) * 60,
s = !dif ? 0 : sum > 1 ? dif / (2 - sum) : dif / sum,
l = sum / 2;
return [round(h), round(s * THOUSAND$1) / 10, round(l * THOUSAND$1) / 10];
}
/**
* @param {string} hex
* @returns {number}
*/
function hexToInt(hex) {
let lo = 0,
hi = hex.length;
if (hi === 7) lo++, hi--;
if (hi === 6) {
const r = hexAt(hex, lo++) << 4 | hexAt(hex, lo++);
const g = hexAt(hex, lo++) << 4 | hexAt(hex, lo++);
const b = hexAt(hex, lo++) << 4 | hexAt(hex, lo++);
return r << 16 | g << 8 | b;
}
if (hi === 4) lo++, hi--;
if (hi === 3) {
return prolif(hexAt(hex, lo++)) << 16 | prolif(hexAt(hex, lo++)) << 8 | prolif(hexAt(hex, lo++));
}
return 0;
}
/**
*
* @param {string} hex
* @returns {number[]}
*/
function hexToRgb(hex) {
const int = hexToInt(hex);
return [int >> 16 & 0xFF, int >> 8 & 0xFF, int & 0xFF];
}
const THOUSAND = 1000;
/**
* !dif: dif===0
* @param {number} int
* @returns {[number,number,number]} [Hue([0,360]), Saturation([0,100]), Lightness([0,100])]
*/
function intToHsl(int) {
let r = int >> 16 & 0xFF,
g = int >> 8 & 0xFF,
b = int & 0xFF;
r /= 255;
g /= 255;
b /= 255;
const {
max,
sum,
dif
} = bound([r, g, b]);
let h = hue(r, g, b, max, dif) * 60,
s = !dif ? 0 : sum > 1 ? dif / (2 - sum) : dif / sum,
l = sum / 2;
return [round(h), round(s * THOUSAND) / 10, round(l * THOUSAND) / 10];
}
const hexToHsl = hex => {
var _ref, _hex;
return _ref = (_hex = hex, hexToInt(_hex)), intToHsl(_ref);
};
/**
*
* @param {number} n
* @param {number} h
* @param {number} a
* @param {number} l
* @returns {number}
*/
const hf = (n, h, a, l) => {
const k = (n + h / 30) % 12;
return l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
};
/**
*
* @param {number} h
* @param {number} s
* @param {number} l
* @returns {number[]}
*/
function hslToRgb([h, s, l]) {
s /= 100;
l /= 100;
const a = s * Math.min(l, 1 - l),
r = hf(0, h, a, l),
g = hf(8, h, a, l),
b = hf(4, h, a, l);
return [round(r * 0xFF), round(g * 0xFF), round(b * 0xFF)]; // return [r * 0xFF & 0xFF, g * 0xFF & 0xFF, b * 0xFF & 0xFF]
}
const hslToHex = hsl => {
var _ref, _hsl;
return _ref = (_hsl = hsl, hslToRgb(_hsl)), rgbToHex(_ref);
};
/**
*
* @param {number} h
* @param {number} s
* @param {number} l
* @returns {number}
*/
function hslToInt([h, s, l]) {
s /= 100;
l /= 100;
const a = s * Math.min(l, 1 - l),
r = hf(0, h, a, l),
g = hf(8, h, a, l),
b = hf(4, h, a, l);
return ((round(r * 0xFF) & 0xFF) << 16) + ((round(g * 0xFF) & 0xFF) << 8) + (round(b * 0xFF) & 0xFF);
}
const intToRgb = n => [n >> 16 & 0xFF, n >> 8 & 0xFF, n & 0xFF];
const intToHex = int => '#' + dil6(int.toString(16));
var _class, _temp, _class2, _temp2, _class3, _temp3, _class4, _temp4;
(_temp = _class = class Rgb {}, _class.rgb = oneself, _class.hex = rgbToHex, _class.hsl = rgbToHsl, _class.int = rgbToInt, _temp);
(_temp2 = _class2 = class Rgb {}, _class2.rgb = hexToRgb, _class2.hex = oneself, _class2.hsl = hexToHsl, _class2.int = hexToInt, _temp2);
(_temp3 = _class3 = class Rgb {}, _class3.rgb = hslToRgb, _class3.hex = hslToHex, _class3.hsl = oneself, _class3.int = hslToInt, _temp3);
(_temp4 = _class4 = class Rgb {}, _class4.rgb = intToRgb, _class4.hex = intToHex, _class4.hsl = intToHsl, _class4.int = oneself, _temp4);
function excite() {

@@ -277,0 +7,0 @@ if (this.head.length) this.head += ';';

10

package.json
{
"name": "@palett/dye-factory",
"version": "0.8.14",
"version": "0.8.15",
"description": "A colorant to string",

@@ -20,4 +20,6 @@ "main": "dist/index.cjs.js",

"@ject/oneself": "^0.0.12",
"@palett/enum-color-space": "^0.8.14",
"@palett/util-ansi": "^0.8.14"
"@palett/convert": "^0.8.15",
"@palett/enum-ansi-codes": "^0.8.15",
"@palett/enum-color-space": "^0.8.15",
"@palett/util-ansi": "^0.8.15"
},

@@ -42,3 +44,3 @@ "repository": {

"homepage": "https://github.com/hoyeungw/palett/dye#readme",
"gitHead": "2caee8682c727f7206ef9716d3e9c3cc75b33dec"
"gitHead": "d262ae3420015dc9904fb77ce558ed9fd6d1a4c2"
}
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