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

fuzzy-color

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fuzzy-color - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

.idea/fuzzy-color.iml

37

index.js
module.exports = parse;
function parse(str) {
function parse(str, assumeType) {
return rgb(str)
|| rgba(str)
|| other(str)
|| hex(str);
|| hex(str)
|| assume(str, assumeType);
}

@@ -63,3 +64,3 @@

string: 'rgba(' + rgb.join(',') + ')',
raw: rgb.map(function(i){ return parseInt(i, 10); }),
raw: rgb.map(function(i){ return parseFloat(i); }),
type: 'rgba'

@@ -73,2 +74,32 @@ };

/**
* Parse 0, 0, 0 | 0, 0, 0, 0 | 0 0 0 | 0 0 0 0
*
* @param {String} str
* @param {String} type - the type to assume number only values are. eg 'rgb', 'hsv', 'hsl'
* @return {Object}
* @api private
*/
function assume(str, type) {
var result = str.replace(/,/g, '').replace(/ /g, ' ').split(' ');
if (result.length >= 3) {
if (result.length === 4) {
return {
string: 'rgba(' + result.join(',') + ')',
raw: result.map(function(i){ return parseFloat(i); }),
type: 'rgba'
};
} else {
return {
string: type + '(' + result.join(',') + ')',
raw: result.map(function(i){ return parseInt(i, 10); }),
type: type
};
}
}
return false;
}
/**
* Parse #000 and #000000

@@ -75,0 +106,0 @@ *

2

package.json
{
"name": "fuzzy-color",
"version": "0.0.1",
"version": "0.0.2",
"description": "Fuzzy color is a utility that takes a string and does its absolute best to parse a meaningful color value from it.",

@@ -5,0 +5,0 @@ "repository": "https://github.com/jonnyscholes/fuzzy-color",

@@ -39,3 +39,47 @@ var test = require('tape');

test('RGBA test with .5 opacity', function (t) {
t.plan(1);
var rgb = fuzzyColor('rgba(0,0,0,.5)');
t.deepEqual(rgb, {
string: 'rgba(0,0,0,.5)',
raw: [0, 0, 0,.5],
type: 'rgba'
});
});
test('assumeType=rgb with valid rgb value test - "0, 0, 0"', function (t) {
t.plan(1);
var rgb = fuzzyColor('0, 0, 0', 'rgb');
t.deepEqual(rgb, {
string: 'rgb(0,0,0)',
raw: [0, 0, 0],
type: 'rgb'
});
});
test('assumeType=rgb with valid rgb value test and no commas - "0 0 0"', function (t) {
t.plan(1);
var rgb = fuzzyColor('0 0 0', 'rgb');
t.deepEqual(rgb, {
string: 'rgb(0,0,0)',
raw: [0, 0, 0],
type: 'rgb'
});
});
test('assumeType=rgb with valid rgbA value test - "0, 0, 0, .5"', function (t) {
t.plan(1);
var rgb = fuzzyColor('0, 0, 0, .5', 'rgb');
t.deepEqual(rgb, {
string: 'rgba(0,0,0,.5)',
raw: [0, 0, 0, .5],
type: 'rgba'
});
});
test('3 char HEX test', function (t) {

@@ -86,5 +130,2 @@ t.plan(1);

});
});
// support R:252 G:252 B:252
// support (R145 / G145 / B149)
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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