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

color-tf

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

color-tf - npm Package Compare versions

Comparing version 5.0.1 to 5.0.2

13

hsl2hsv.js

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

"use strict";
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _default = (h, s, l) => {
var hsl2hsv = ((h, s, l) => {
const t = s * (l < 0.5 ? l : 1 - l),

@@ -13,4 +8,4 @@ V = l + t,

return [h, S, V];
};
});
exports.default = _default;
module.exports = hsl2hsv;

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

"use strict";
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _default = (h, s, l) => {
var hsl2rgb = ((h, s, l) => {
if (s === 0) return [l, l, l]; // achromatic

@@ -14,6 +9,4 @@

return [hue2rgb(p, q, h + 1 / 3), hue2rgb(p, q, h), hue2rgb(p, q, h - 1 / 3)];
};
});
exports.default = _default;
function hue2rgb(p, q, t) {

@@ -27,2 +20,4 @@ // private fn

return p;
}
}
module.exports = hsl2rgb;

@@ -1,14 +0,9 @@

"use strict";
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _default = (h, s, v) => {
var hsv2hsl = ((h, s, v) => {
const L = (2 - s) * v / 2,
S = s * v / (L < 0.5 ? L * 2 : 2 - L * 2);
return [h, S || 0, L];
};
});
exports.default = _default;
module.exports = hsv2hsl;

@@ -1,10 +0,5 @@

"use strict";
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var hsv2hwb = ((h, s, v) => [h, (1 - s) * v, 1 - v]);
var _default = (h, s, v) => [h, (1 - s) * v, 1 - v];
exports.default = _default;
module.exports = hsv2hwb;

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

"use strict";
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _default = (h, s, v) => {
var hsv2rgb = ((h, s, v) => {
const i = Math.floor(h * 6);

@@ -35,4 +30,4 @@ const f = h * 6 - i;

}
};
});
exports.default = _default;
module.exports = hsv2rgb;

@@ -1,10 +0,5 @@

"use strict";
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var hwb2hsv = ((h, w, b) => [h, b === 1 ? 0 : Math.max(0, 1 - w / (1 - b)), 1 - b]);
var _default = (h, w, b) => [h, b === 1 ? 0 : Math.max(0, 1 - w / (1 - b)), 1 - b];
exports.default = _default;
module.exports = hwb2hsv;

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

"use strict";
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _default = (h, w, b) => {
var hwb2rgb = ((h, w, b) => {
// could throw or warn, or normalize if w+b>=1 ?

@@ -36,4 +31,4 @@ const v = 1 - b;

}
};
});
exports.default = _default;
module.exports = hwb2rgb;
{
"name": "color-tf",
"version": "5.0.1",
"version": "5.0.2",
"description": "RGB, HSL, HSV, HWB and more color models convertor",
"main": "proxy",
"browser": "umd.js",
"module": "src/proxy",
"module": "src",
"scripts": {
"test": "babel-node --presets @babel/env test/index.spec",
"rollup": "NODE_ENV=rollup npx rollup -c",
"build": "rm -rf dist && npx babel --out-dir dist --source-type module src && npm run rollup && cp package.json dist/ && cp README.md dist/ && cp -r src dist/",
"rollup": "rm -rf dist && NODE_ENV=rollup rollup -c",
"build": "rm -rf dist && npm run rollup && cp package.json dist/ && cp README.md dist/",
"pub": "npm run build && npm publish dist"

@@ -38,6 +38,6 @@ },

"@babel/preset-env": "^7.0.0-beta.46",
"rollup": "^0.58.2",
"rollup": "github:rollup/rollup",
"rollup-plugin-babel": "^4.0.0-beta.4"
},
"dependencies": {}
}
}

@@ -1,14 +0,40 @@

"use strict";
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
var hsl2hsv = require('./hsl2hsv.js');
var hsl2rgb = require('./hsl2rgb.js');
var hsv2hsl = require('./hsv2hsl.js');
var hsv2hwb = require('./hsv2hwb.js');
var hsv2rgb = require('./hsv2rgb.js');
var hwb2hsv = require('./hwb2hsv.js');
var hwb2rgb = require('./hwb2rgb.js');
var rgb2hsl = require('./rgb2hsl.js');
var rgb2hsv = require('./rgb2hsv.js');
var rgb2hwb = require('./rgb2hwb.js');
var lib = /*#__PURE__*/Object.freeze({
hsl2hsv: hsl2hsv.default,
hsl2rgb: hsl2rgb.default,
hsv2hsl: hsv2hsl.default,
hsv2hwb: hsv2hwb.default,
hsv2rgb: hsv2rgb.default,
hwb2hsv: hwb2hsv.default,
hwb2rgb: hwb2rgb.default,
rgb2hsl: rgb2hsl.default,
rgb2hsv: rgb2hsv.default,
rgb2hwb: rgb2hwb.default
});
exports.default = void 0;
var lib = _interopRequireWildcard(require("./fns"));
// Hex <-> RGB
// ab128c -> [r, g, b]
const hexToRgb = s => s.length === 3 ? [parseInt(s[0] + s[0], 16), parseInt(s[1] + s[1], 16), parseInt(s[2] + s[2], 16)] : s.length === 6 ? [parseInt(s.slice(0, 2), 16), parseInt(s.slice(2, 4), 16), parseInt(s.slice(4, 6), 16)] : [parseInt(s.slice(0, 2), 16), parseInt(s.slice(2, 4), 16), parseInt(s.slice(4, 6), 16), Math.round(parseInt(s.slice(6, 8), 16) / 0.255) / 1000];
const rgbToHex = (R, G, B, A) => R % 17 === 0 && G % 17 === 0 && B % 17 === 0 && A === undefined // short version
? R.toString(16)[0] + G.toString(16)[0] + B.toString(16)[0] : R.toString(16).padStart(2, 0) + G.toString(16).padStart(2, 0) + B.toString(16).padStart(2, 0) + (A ? Math.round(A * 255).toString(16).padStart(2, 0) : '');
var libHex = _interopRequireWildcard(require("./hex"));
var libHex = /*#__PURE__*/Object.freeze({
hexToRgb: hexToRgb,
rgbToHex: rgbToHex
});
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
const libKeys = Object.keys(lib);

@@ -59,3 +85,3 @@ /**

var _default = new Proxy(new Map([...Object.entries(lib), ...Object.entries(libHex)]), {
var proxy = new Proxy(new Map([...Object.entries(lib), ...Object.entries(libHex)]), {
get: (map, key) => {

@@ -87,2 +113,2 @@ if (typeof key !== 'string') return map;

exports.default = _default;
module.exports = proxy;

@@ -23,2 +23,3 @@ ## Color transforms between RGB, HSL, HSV and HWB, and more

colorTf.hslToRgb(200, 95, 62); // [ 66, 189, 250 ]
console.assert(hsl2hsv === colorTf.hsl2hsv);
```

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

"use strict";
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _default = (r, g, b) => {
var rgb2hsl = ((r, g, b) => {
const max = Math.max(r, g, b),

@@ -18,4 +13,4 @@ min = Math.min(r, g, b);

return [h / 6, s, l];
};
});
exports.default = _default;
module.exports = rgb2hsl;

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

"use strict";
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _default = (r, g, b) => {
var rgb2hsv = ((r, g, b) => {
const max = Math.max(r, g, b),

@@ -18,4 +13,4 @@ min = Math.min(r, g, b);

return [h / 6, s, v];
};
});
exports.default = _default;
module.exports = rgb2hsv;

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

"use strict";
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _default = (R, G, B) => {
var rgb2hwb = ((R, G, B) => {
const max = Math.max(R, G, B),

@@ -18,4 +13,4 @@ min = Math.min(R, G, B);

return [hue / 6, min, b];
};
});
exports.default = _default;
module.exports = rgb2hwb;

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

export default (h, s, l) => {
var hsl2hsv = ((h, s, l) => {
const t = s * (l < 0.5 ? l : 1 - l),
V = l + t,
S = l > 0 ? 2 * t / V : 0;
V = l + t,
S = l > 0 ? 2 * t / V : 0;
return [h, S, V];
};
});
export default hsl2hsv;

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

export default (h, s, l) => {
var hsl2rgb = ((h, s, l) => {
if (s === 0) return [l, l, l]; // achromatic

@@ -7,3 +7,3 @@

return [hue2rgb(p, q, h + 1 / 3), hue2rgb(p, q, h), hue2rgb(p, q, h - 1 / 3)];
};
});

@@ -18,2 +18,4 @@ function hue2rgb(p, q, t) {

return p;
}
}
export default hsl2rgb;

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

export default (h, s, v) => {
var hsv2hsl = ((h, s, v) => {
const L = (2 - s) * v / 2,
S = s * v / (L < 0.5 ? L * 2 : 2 - L * 2);
S = s * v / (L < 0.5 ? L * 2 : 2 - L * 2);
return [h, S || 0, L];
});
return [h, S || 0, L];
};
export default hsv2hsl;

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

export default (h, s, v) => [h, (1 - s) * v, 1 - v];
var hsv2hwb = ((h, s, v) => [h, (1 - s) * v, 1 - v]);
export default hsv2hwb;

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

export default (h, s, v) => {
var hsv2rgb = ((h, s, v) => {
const i = Math.floor(h * 6);

@@ -12,13 +12,20 @@ const f = h * 6 - i;

return [v, t, p];
case 1:
return [q, v, p];
case 2:
return [p, v, t];
case 3:
return [p, q, v];
case 4:
return [t, p, v];
case 5:
return [v, p, q];
}
};
});
export default hsv2rgb;

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

export default (h, w, b) => [h, b === 1 ? 0 : Math.max(0, 1 - w / (1 - b)), 1 - b];
var hwb2hsv = ((h, w, b) => [h, b === 1 ? 0 : Math.max(0, 1 - w / (1 - b)), 1 - b]);
export default hwb2hsv;

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

export default (h, w, b) => {
var hwb2rgb = ((h, w, b) => {
// could throw or warn, or normalize if w+b>=1 ?

@@ -6,2 +6,3 @@ const v = 1 - b;

const f = i & 1 ? 1 + i - h * 6 : h * 6 - i; // if i is odd
const n = w + f * (v - w); // linear interpolation

@@ -13,13 +14,20 @@

return [v, n, w];
case 1:
return [n, v, w];
case 2:
return [w, v, n];
case 3:
return [w, n, v];
case 4:
return [n, w, v];
case 5:
return [v, w, n];
}
};
});
export default hwb2rgb;

@@ -1,13 +0,47 @@

import * as lib from './fns';
import hsl2hsv from './hsl2hsv.js';
import hsl2rgb from './hsl2rgb.js';
import hsv2hsl from './hsv2hsl.js';
import hsv2hwb from './hsv2hwb.js';
import hsv2rgb from './hsv2rgb.js';
import hwb2hsv from './hwb2hsv.js';
import hwb2rgb from './hwb2rgb.js';
import rgb2hsl from './rgb2hsl.js';
import rgb2hsv from './rgb2hsv.js';
import rgb2hwb from './rgb2hwb.js';
import * as libHex from './hex';
var lib = /*#__PURE__*/Object.freeze({
hsl2hsv: hsl2hsv,
hsl2rgb: hsl2rgb,
hsv2hsl: hsv2hsl,
hsv2hwb: hsv2hwb,
hsv2rgb: hsv2rgb,
hwb2hsv: hwb2hsv,
hwb2rgb: hwb2rgb,
rgb2hsl: rgb2hsl,
rgb2hsv: rgb2hsv,
rgb2hwb: rgb2hwb
});
// Hex <-> RGB
// ab128c -> [r, g, b]
const hexToRgb = s => s.length === 3 ? [parseInt(s[0] + s[0], 16), parseInt(s[1] + s[1], 16), parseInt(s[2] + s[2], 16)] : s.length === 6 ? [parseInt(s.slice(0, 2), 16), parseInt(s.slice(2, 4), 16), parseInt(s.slice(4, 6), 16)] : [parseInt(s.slice(0, 2), 16), parseInt(s.slice(2, 4), 16), parseInt(s.slice(4, 6), 16), Math.round(parseInt(s.slice(6, 8), 16) / 0.255) / 1000];
const rgbToHex = (R, G, B, A) => R % 17 === 0 && G % 17 === 0 && B % 17 === 0 && A === undefined // short version
? R.toString(16)[0] + G.toString(16)[0] + B.toString(16)[0] : R.toString(16).padStart(2, 0) + G.toString(16).padStart(2, 0) + B.toString(16).padStart(2, 0) + (A ? Math.round(A * 255).toString(16).padStart(2, 0) : '');
var libHex = /*#__PURE__*/Object.freeze({
hexToRgb: hexToRgb,
rgbToHex: rgbToHex
});
const libKeys = Object.keys(lib);
/**
* @return the shortest (inverted) path fn between 2 keys in lib object
*/
const getPath = (fromKey, toKey) => {
let nodes = [fromKey];
const visited = new Map(); // map node key => parent key
while (nodes.length) {

@@ -22,2 +56,3 @@ // search breadth-first

let fn = lib[k + '2' + toKey];
for (let key = k; visited.has(key) && key !== fromKey; key = visited.get(key)) {

@@ -27,13 +62,12 @@ // compose functions while there's a parent

}
return arr;
}
libKeys
.filter(s => s.slice(0, 3) === k)
.map(s => s.slice(4))
.filter(key => !visited.has(key))
.forEach(key => {
visited.set(key, k);
newNodes.push(key);
});
libKeys.filter(s => s.slice(0, 3) === k).map(s => s.slice(4)).filter(key => !visited.has(key)).forEach(key => {
visited.set(key, k);
newNodes.push(key);
});
}
nodes = newNodes;

@@ -44,3 +78,2 @@ }

const roundH = ([h, s, l]) => [Math.round(360 * h) % 360, Math.round(100 * s), Math.round(100 * l)];
/**

@@ -51,35 +84,31 @@ * all functions available from a Proxy (to generate missing ones dynamically)

*/
export default new Proxy(
new Map([...Object.entries(lib), ...Object.entries(libHex)]),
{
get: (map, key) => {
if (typeof key !== 'string') return map;
if (map.has(key)) return map.get(key);
const fromKey = key.slice(0, 3);
const toKey = key.slice(-3).toLowerCase();
var proxy = new Proxy(new Map([...Object.entries(lib), ...Object.entries(libHex)]), {
get: (map, key) => {
if (typeof key !== 'string') return map;
if (map.has(key)) return map.get(key);
const fromKey = key.slice(0, 3);
const toKey = key.slice(-3).toLowerCase();
const k = fromKey + '2' + toKey;
let fn = lib[k];
const k = fromKey + '2' + toKey;
let fn = lib[k];
if (!fn) {
// todo check fromKey, toKey are in available keys, else getPath might be in infinite loop
if (!fn) {
// todo check fromKey, toKey are in available keys, else getPath might be in infinite loop
const path = getPath(fromKey, toKey);
const funcs = Array.from({
length: path.length - 1
}, (_, i) => lib[`${path[i + 1]}2${path[i]}`]);
fn = funcs.reduceRight((func, f) => (...a) => f(...func(...a)));
map.set(k, fn);
}
const path = getPath(fromKey, toKey);
const funcs = Array.from({ length: path.length - 1 }, (_, i) => lib[`${path[i + 1]}2${path[i]}`]);
fn = funcs.reduceRight((func, f) => (...a) => f(...func(...a)));
map.set(k, fn);
}
if (key[3] === '2') return fn;
if (key[3] === '2') return fn;
const K = fromKey + 'To' + toKey[0].toUpperCase() + toKey.slice(1);
const FN = fromKey === 'rgb' ? (r, g, b) => roundH(fn(r / 255, g / 255, b / 255)) : toKey === 'rgb' ? (h, x, y) => fn(h / 360, x / 100, y / 100).map(v => Math.round(v * 255)) : (h, x, y) => roundH(fn(h / 360, x / 100, y / 100));
map.set(K, FN);
return FN;
}
});
const K = fromKey + 'To' + toKey[0].toUpperCase() + toKey.slice(1);
const FN = fromKey === 'rgb'
? (r, g, b) => roundH(fn(r / 255, g / 255, b / 255))
: toKey === 'rgb'
? (h, x, y) => fn(h / 360, x / 100, y / 100).map(v => Math.round(v * 255))
: (h, x, y) => roundH(fn(h / 360, x / 100, y / 100));
map.set(K, FN);
return FN;
}
}
);
export default proxy;

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

export default (r, g, b) => {
var rgb2hsl = ((r, g, b) => {
const max = Math.max(r, g, b),
min = Math.min(r, g, b);
min = Math.min(r, g, b);
const l = (max + min) / 2,
d = max - min;
d = max - min;
if (d <= 0) return [0, 0, l]; // achromatic

@@ -12,2 +11,4 @@

return [h / 6, s, l];
};
});
export default rgb2hsl;

@@ -1,8 +0,7 @@

export default (r, g, b) => {
var rgb2hsv = ((r, g, b) => {
const max = Math.max(r, g, b),
min = Math.min(r, g, b);
min = Math.min(r, g, b);
const v = max,
d = max - min,
s = max === 0 ? 0 : d / max;
d = max - min,
s = max === 0 ? 0 : d / max;
if (d <= 0) return [0, s, v]; // achromatic

@@ -12,2 +11,4 @@

return [h / 6, s, v];
};
});
export default rgb2hsv;

@@ -1,14 +0,13 @@

export default (R, G, B) => {
var rgb2hwb = ((R, G, B) => {
const max = Math.max(R, G, B),
min = Math.min(R, G, B);
min = Math.min(R, G, B);
const b = 1 - max,
d = max - min;
d = max - min;
if (d <= 0) return [0, min, b]; // achromatic
const hue = min === R ? 3 - (G - B) / d : min === G ? 5 - (B - R) / d : 1 - (R - G) / d;
const hue = min === R ? 3 - (G - B) / d : min === G ? 5 - (B - R) / d : 1 - (R - G) / d; // const [f, i] = min === R ? [G - B, 3 / 6] : min === G ? [B - R, 5 / 6] : [R - G, 1 / 6];
// const [f, i] = min === R ? [G - B, 3 / 6] : min === G ? [B - R, 5 / 6] : [R - G, 1 / 6];
return [hue / 6, min, b];
});
return [hue / 6, min, b];
};
export default rgb2hwb;
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