Socket
Socket
Sign inDemoInstall

color-namer

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

color-namer - npm Package Compare versions

Comparing version 1.3.0 to 1.4.0

11

index.js
"use strict";
var chroma = require('chroma-js')
var WeakMap = require("es6-weak-map")

@@ -16,5 +17,12 @@ // These `require` statements are all explicit

var cache = new WeakMap()
var namer = module.exports = function(color, options) {
options = options || {}
var cacheKey = {color, options}
if (cache.has(cacheKey)) {
return cache.get(cacheKey)
}
var deltaE = String(options.distance).toLowerCase() === 'deltae';
color = chroma(color)

@@ -31,3 +39,3 @@ var results = {}

.map (function(name) {
name.distance = chroma.distance(color, chroma(name.hex))
name.distance = deltaE ? chroma.deltaE(color, chroma(name.hex)) : chroma.distance(color, chroma(name.hex))
return name

@@ -39,2 +47,3 @@ })

}
cache.set(cacheKey, results)
return results

@@ -41,0 +50,0 @@ }

7

package.json
{
"name": "color-namer",
"version": "1.3.0",
"version": "1.4.0",
"description": "Give me a color and I'll name it.",
"repository": "https://github.com/zeke/color-namer",
"repository": "https://github.com/colorjs/color-namer",
"main": "index.js",

@@ -35,4 +35,5 @@ "scripts": {

"dependencies": {
"chroma-js": "^1.3.4"
"chroma-js": "^1.3.4",
"es6-weak-map": "^2.0.3"
}
}

@@ -115,2 +115,12 @@ # Color Namer [![Build Status](https://travis-ci.org/zeke/color-namer.svg?branch=master)](https://travis-ci.org/zeke/color-namer)

### options.distance
If 'deltaE', use the [Delta-E](http://zschuessler.github.io/DeltaE/learn/) distance function, otherwise uses default distance function.
```js
var names = namer(color, { pick: ['basic'], distance: 'deltaE' });
// output: { basic: [...] }
```
###
## Tests

@@ -117,0 +127,0 @@

@@ -24,2 +24,9 @@ "use strict";

test('matches inexact colors with deltaE', function() {
var names = namer('FF0001', { distance: 'deltaE' })
assert.equal(names.basic[0].hex, '#FF0000')
assert.equal(names.basic[0].name, 'red')
assert.equal(Math.floor(names.basic[0].distance*100), 13)
})
test('matches inexact colors', function() {

@@ -26,0 +33,0 @@ var names = namer('FF0001')

Sorry, the diff of this file is not supported yet

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