Comparing version 5.0.4 to 5.1.0
{ | ||
"name": "color-tf", | ||
"version": "5.0.4", | ||
"description": "RGB, HSL, HSV, HWB and more color models convertor", | ||
"version": "5.1.0", | ||
"description": "RGB, HSL, HSV, HWB and more color models convertors", | ||
"main": "proxy", | ||
@@ -44,2 +44,2 @@ "browser": "umd.js", | ||
"dependencies": {} | ||
} | ||
} |
15
proxy.js
@@ -13,2 +13,4 @@ 'use strict'; | ||
var rgb2hwb = require('./rgb2hwb.js'); | ||
var rgbToHex = require('./rgbToHex.js'); | ||
var hexToRgb = require('./hexToRgb.js'); | ||
@@ -30,13 +32,2 @@ | ||
// 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 | ||
}); | ||
/** | ||
@@ -83,3 +74,3 @@ * @return fns to compose between 2 keys in lib object e.g. fns.reduceRight((fn, f) => (...a) => f(...fn(...a))) | ||
var proxy = new Proxy(new Map([...Object.entries(lib), ...Object.entries(libHex)]), { | ||
var proxy = new Proxy(new Map([...Object.entries(lib), ['rgbToHex', rgbToHex.default], ['hexToRgb', hexToRgb.default]]), { | ||
get: (map, key) => { | ||
@@ -86,0 +77,0 @@ if (typeof key !== 'string') return map; |
@@ -7,3 +7,2 @@ ## Color transforms between RGB, HSL, HSV and HWB, and more | ||
* http://alvyray.com/Papers/CG/hwb2rgb.htm | ||
* https://unpkg.com/color-convert@1.9.1/conversions.js (todo add other functions from there) | ||
@@ -13,5 +12,5 @@ naming convention: | ||
* foo2bar: input and output are in [0, 1] | ||
* fooToBar: natural ranges: hues in [0, 360[, colors in [0, 255], saturation/value/lightness in [0, 100] | ||
* fooToBar: natural ranges: hues in [0, 360[, r/g/b in [0, 255], saturation/value/lightness in [0, 100] | ||
The default export is a proxy, there are alse [direct functions](https://unpkg.com/color-tf@5.0.0-beta2/src/) available | ||
The default export is a proxy, there are also [direct functions](https://unpkg.com/color-tf/) available | ||
@@ -18,0 +17,0 @@ ### Usage |
@@ -11,2 +11,4 @@ import hsl2hsv from './hsl2hsv.js'; | ||
import rgb2hwb from './rgb2hwb.js'; | ||
import rgbToHex from './rgbToHex.js'; | ||
import hexToRgb from './hexToRgb.js'; | ||
@@ -28,13 +30,2 @@ | ||
// 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 | ||
}); | ||
/** | ||
@@ -81,3 +72,3 @@ * @return fns to compose between 2 keys in lib object e.g. fns.reduceRight((fn, f) => (...a) => f(...fn(...a))) | ||
var proxy = new Proxy(new Map([...Object.entries(lib), ...Object.entries(libHex)]), { | ||
var proxy = new Proxy(new Map([...Object.entries(lib), ['rgbToHex', rgbToHex], ['hexToRgb', hexToRgb]]), { | ||
get: (map, key) => { | ||
@@ -84,0 +75,0 @@ if (typeof key !== 'string') return map; |
18
umd.js
@@ -152,11 +152,11 @@ (function (global, factory) { | ||
// 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 rgbToHex = ((R, G, B, A = 1, forceLongVersion) => !forceLongVersion && A === 1 && R % 17 === 0 && G % 17 === 0 && B % 17 === 0 // 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 !== 1 ? Math.floor(A * 256).toString(16).padStart(2, 0) : '')); | ||
var libHex = /*#__PURE__*/Object.freeze({ | ||
hexToRgb: hexToRgb, | ||
rgbToHex: rgbToHex | ||
// format a hex to 6-chars, ignore leading # | ||
const parseHex = hex => hex.length < 6 ? hex[hex.length - 3].repeat(2) + hex[hex.length - 2].repeat(2) + hex[hex.length - 1].repeat(2) : hex.slice(-(hex.length / 2 | 0) * 2); | ||
var hexToRgb = (hex => { | ||
const s = parseHex(hex); | ||
return [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) || 'ff', 16) / 0.255) / 1000]; | ||
}); | ||
@@ -205,3 +205,3 @@ | ||
var proxy = new Proxy(new Map([...Object.entries(lib), ...Object.entries(libHex)]), { | ||
var proxy = new Proxy(new Map([...Object.entries(lib), ['rgbToHex', rgbToHex], ['hexToRgb', hexToRgb]]), { | ||
get: (map, key) => { | ||
@@ -208,0 +208,0 @@ if (typeof key !== 'string') return map; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23420
31
596
24