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

color-name-list

Package Overview
Dependencies
Maintainers
2
Versions
390
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

color-name-list - npm Package Compare versions

Comparing version 3.5.0 to 3.6.0

2

package.json
{
"name": "color-name-list",
"version": "3.5.0",
"version": "3.6.0",
"description": "long list of color names",

@@ -5,0 +5,0 @@ "main": "dist/colornames.json",

@@ -43,3 +43,3 @@ # __15930__ color-names

### CDN 🌍 [JSON](https://unpkg.com/color-name-list/dist/colornames.json), [CSV](https://unpkg.com/color-name-list/dist/colornames.csv), [YML](https://unpkg.com/color-name-list/dist/colornames.yaml), [JS](https://unpkg.com/color-name-list/dist/colornames.js)
### CDN 🌍 [JSON](https://unpkg.com/color-name-list/dist/colornames.json), [CSV](https://unpkg.com/color-name-list/dist/colornames.csv), [YML](https://unpkg.com/color-name-list/dist/colornames.yaml), [JS](https://unpkg.com/color-name-list/dist/colornames.umd.js)

@@ -57,10 +57,9 @@ ### API (v1) 🃏

{
"status": "names for '212121' returned",
"colors": {
"#212121": {
"name": "Lead",
"hex": "#212121",
"rgb": {"r":33, "g":33, "b":33},
"isExactMatch": true
}
"colors": [{
"name": "Lead",
"hex": "#212121",
"rgb": {"r":33, "g":33, "b":33},
"distance": 0, // its an exact match
"requestedHex": "#212121"
}]
}

@@ -67,0 +66,0 @@ ```

@@ -41,3 +41,3 @@ const http = require('http');

* @param {string} color hex representation of color
* @return {boolen}
* @return {boolen}
*/

@@ -54,16 +54,18 @@ const validateColor = (color) => (

const nameColors = (colorArr) => {
let colors = {};
colorArr.forEach((hex) => {
return colorArr.map((hex) => {
const closestColor = nc(`#${hex}`);
const rgb = hexToRgb(hex);
colors[`#${hex}`] = {
return {
hex: closestColor.value,
name: closestColor.name,
hex: closestColor.value,
rgb: closestColor.rgb,
isExactMatch: closestColor.rgb.r === rgb.r &&
closestColor.rgb.g === rgb.g &&
closestColor.rgb.b === rgb.b
requestedHex: `#${hex}`,
// checks if the requested & returned color are identical
distance: Math.sqrt(
Math.pow(closestColor.rgb.r - rgb.r, 2) +
Math.pow(closestColor.rgb.g - rgb.g, 2) +
Math.pow(closestColor.rgb.b - rgb.b, 2)
),
};
});
return colors;
})
};

@@ -74,3 +76,3 @@

'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'POST, GET, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Methods': 'GET',
'Access-Control-Allow-Credentials': false,

@@ -88,8 +90,7 @@ 'Access-Control-Max-Age': '86400',

const isAPI = requestUrl.pathname.indexOf(baseUrl) !== -1;
let statusCode = 404;
let colorQuery = request.url.toLowerCase();
colorQuery = colorQuery.split(baseUrl)[1] || '';
const urlColorList = colorQuery.split(',');
const responseObj = {status: 'Someting went wrong', colors: {}};
const urlColorList = colorQuery.split(',').filter((hex) => (hex));
const responseObj = {};
const invalidColors = urlColorList.filter((hex) => (

@@ -100,18 +101,22 @@ !validateColor(hex) && hex

if (!isAPI) {
responseObj.status = 'invalid URL: make sure to provide the API version';
statusCode = 404;
responseObj.error = {
status: 404,
message: 'invalid URL: make sure to provide the API version',
};
} else if (!urlColorList[0]) {
responseObj.status = `no color(s) provided, returning all the ${colors.length} colors`;
responseObj.colors = colors;
statusCode = 200;
} else if (invalidColors.length) {
responseObj.status = `'${invalidColors.join(', ')}' is not a valid HEX color`;
statusCode = 404;
responseObj.error = {
status: 404,
message: `'${invalidColors.join(', ')}' is not a valid HEX color`,
};
} else if (!invalidColors.length && isAPI) {
responseObj.status = `names for '${urlColorList.join(', ')}' returned`;
responseObj.colors = nameColors(urlColorList);
statusCode = 200;
}
httpRespond(response, responseObj, statusCode);
httpRespond(
response,
responseObj,
responseObj.error ? responseObj.error.status : 200
);
};

@@ -118,0 +123,0 @@

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