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

color-octree

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

color-octree - npm Package Compare versions

Comparing version 2.1.3 to 2.2.0

20

dist/cjs.js

@@ -81,5 +81,5 @@ 'use strict';

const distRgb = (c1, c2) => (c1[0] - c2[0]) ** 2 + (c1[1] - c2[1]) ** 2 + (c1[2] - c2[2]) ** 2;
const dist = (c1, c2) => (c1[0] - c2[0]) ** 2 + (c1[1] - c2[1]) ** 2 + (c1[2] - c2[2]) ** 2;
const distHex = (a, b) => distRgb(hexToRgb(a), hexToRgb(b));
const distHex = (a, b) => dist(hexToRgb(a), hexToRgb(b));

@@ -144,7 +144,3 @@ const rgbToBin = rgb => rgb.map(x => x.toString(2).padStart(8, 0));

node = node[k];
const idx = node.colors.findIndex(c => c.hex === hex);
if (idx >= 0) {
node.colors = [...node.colors.slice(0, idx), ...node.colors.slice(idx + 1)]; // don't like splice
}
node.colors = node.colors.filter(c => c.hex !== hex);
}

@@ -224,9 +220,9 @@ };

const closestIn = (rgb, colors) => {
let dist = Infinity,
let minD = Infinity,
color;
colors.forEach(col => {
const d = distRgb(hexToRgb(parseHex(col.hex)), rgb);
const d = dist(hexToRgb(parseHex(col.hex)), rgb);
if (d < dist) {
dist = d;
if (d < minD) {
minD = d;
color = col;

@@ -236,3 +232,3 @@ }

return _objectSpread({}, color, {
d: dist ** .5
d: minD ** .5
});

@@ -239,0 +235,0 @@ };

@@ -77,5 +77,5 @@ function _defineProperty(obj, key, value) {

const distRgb = (c1, c2) => (c1[0] - c2[0]) ** 2 + (c1[1] - c2[1]) ** 2 + (c1[2] - c2[2]) ** 2;
const dist = (c1, c2) => (c1[0] - c2[0]) ** 2 + (c1[1] - c2[1]) ** 2 + (c1[2] - c2[2]) ** 2;
const distHex = (a, b) => distRgb(hexToRgb(a), hexToRgb(b));
const distHex = (a, b) => dist(hexToRgb(a), hexToRgb(b));

@@ -142,7 +142,3 @@ const rgbToBin = rgb => rgb.map(x => x.toString(2).padStart(8, 0));

node = node[k];
const idx = node.colors.findIndex(c => c.hex === hex);
if (idx >= 0) {
node.colors = [...node.colors.slice(0, idx), ...node.colors.slice(idx + 1)]; // don't like splice
}
node.colors = node.colors.filter(c => c.hex !== hex);
}

@@ -222,9 +218,9 @@ };

const closestIn = (rgb, colors) => {
let dist = Infinity,
let minD = Infinity,
color;
colors.forEach(col => {
const d = distRgb(hexToRgb(parseHex(col.hex)), rgb);
const d = dist(hexToRgb(parseHex(col.hex)), rgb);
if (d < dist) {
dist = d;
if (d < minD) {
minD = d;
color = col;

@@ -234,3 +230,3 @@ }

return _objectSpread({}, color, {
d: dist ** .5
d: minD ** .5
});

@@ -237,0 +233,0 @@ };

@@ -83,5 +83,5 @@ (function (global, factory) {

const distRgb = (c1, c2) => (c1[0] - c2[0]) ** 2 + (c1[1] - c2[1]) ** 2 + (c1[2] - c2[2]) ** 2;
const dist = (c1, c2) => (c1[0] - c2[0]) ** 2 + (c1[1] - c2[1]) ** 2 + (c1[2] - c2[2]) ** 2;
const distHex = (a, b) => distRgb(hexToRgb(a), hexToRgb(b));
const distHex = (a, b) => dist(hexToRgb(a), hexToRgb(b));

@@ -146,7 +146,3 @@ const rgbToBin = rgb => rgb.map(x => x.toString(2).padStart(8, 0));

node = node[k];
const idx = node.colors.findIndex(c => c.hex === hex);
if (idx >= 0) {
node.colors = [...node.colors.slice(0, idx), ...node.colors.slice(idx + 1)]; // don't like splice
}
node.colors = node.colors.filter(c => c.hex !== hex);
}

@@ -226,9 +222,9 @@ };

const closestIn = (rgb, colors) => {
let dist = Infinity,
let minD = Infinity,
color;
colors.forEach(col => {
const d = distRgb(hexToRgb(parseHex(col.hex)), rgb);
const d = dist(hexToRgb(parseHex(col.hex)), rgb);
if (d < dist) {
dist = d;
if (d < minD) {
minD = d;
color = col;

@@ -238,3 +234,3 @@ }

return _objectSpread({}, color, {
d: dist ** .5
d: minD ** .5
});

@@ -241,0 +237,0 @@ };

19

index.js

@@ -14,5 +14,5 @@ export const parseHex = hex =>

const distRgb = (c1, c2) => (c1[0] - c2[0]) ** 2 + (c1[1] - c2[1]) ** 2 + (c1[2] - c2[2]) ** 2;
const dist = (c1, c2) => (c1[0] - c2[0]) ** 2 + (c1[1] - c2[1]) ** 2 + (c1[2] - c2[2]) ** 2;
export const distHex = (a, b) => distRgb(hexToRgb(a), hexToRgb(b));
export const distHex = (a, b) => dist(hexToRgb(a), hexToRgb(b));

@@ -76,6 +76,3 @@ const rgbToBin = rgb => rgb.map(x => x.toString(2).padStart(8, 0));

node = node[k];
const idx = node.colors.findIndex(c => c.hex === hex);
if (idx >= 0) {
node.colors = [...node.colors.slice(0, idx), ...node.colors.slice(idx + 1)]; // don't like splice
}
node.colors = node.colors.filter(c => c.hex !== hex);
}

@@ -145,12 +142,12 @@ }

const closestIn = (rgb, colors) => {
let dist = Infinity,
let minD = Infinity,
color;
colors.forEach(col => {
const d = distRgb(hexToRgb(parseHex(col.hex)), rgb);
if (d < dist) {
dist = d;
const d = dist(hexToRgb(parseHex(col.hex)), rgb);
if (d < minD) {
minD = d;
color = col;
}
});
return {...color, d: dist ** .5};
return {...color, d: minD ** .5};
};

@@ -25,3 +25,3 @@ import assert from 'assert';

console.log('## color-names (148 colors)');
console.log('\n## color-names (148 colors)');

@@ -42,3 +42,3 @@ const colors = Object.entries(colorNames).map(([hex, name]) => ({hex, name}));

console.log('## color-name-list (17k colors)');
console.log('\n## color-name-list (17k colors)');

@@ -45,0 +45,0 @@ console.time('add');

{
"name": "color-octree",
"version": "2.1.3",
"version": "2.2.0",
"description": "Get closest hex color",

@@ -5,0 +5,0 @@ "main": "dist/cjs.js",

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