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

@khanacademy/wonder-blocks-color

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@khanacademy/wonder-blocks-color - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

index.test.js

64

dist/index.js

@@ -106,3 +106,4 @@ module.exports =

var colorRegexp = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i;
var color6Regexp = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i;
var color3Regexp = /^#([0-9a-f])([0-9a-f])([0-9a-f])$/i;
var rgbaRegexp = /^rgba?\(\s*(\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\s*\)$/i;

@@ -117,24 +118,33 @@

var match = color.match(colorRegexp);
if (match) {
var color3Match = color.match(color3Regexp);
if (color3Match) {
return {
r: parseInt(match[1], 16),
g: parseInt(match[2], 16),
b: parseInt(match[3], 16),
r: parseInt("" + color3Match[1] + color3Match[1], 16),
g: parseInt("" + color3Match[2] + color3Match[2], 16),
b: parseInt("" + color3Match[3] + color3Match[3], 16),
a: 1
};
} else {
var rgbaMatch = color.match(rgbaRegexp);
}
if (rgbaMatch) {
return {
r: parseFloat(rgbaMatch[1]),
g: parseFloat(rgbaMatch[2]),
b: parseFloat(rgbaMatch[3]),
a: rgbaMatch[4] ? parseFloat(rgbaMatch[4]) : 1
};
}
var color6Match = color.match(color6Regexp);
if (color6Match) {
return {
r: parseInt(color6Match[1], 16),
g: parseInt(color6Match[2], 16),
b: parseInt(color6Match[3], 16),
a: 1
};
}
throw new Error("Failed to parse color: " + color);
var rgbaMatch = color.match(rgbaRegexp);
if (rgbaMatch) {
return {
r: parseFloat(rgbaMatch[1]),
g: parseFloat(rgbaMatch[2]),
b: parseFloat(rgbaMatch[3]),
a: rgbaMatch[4] ? parseFloat(rgbaMatch[4]) : 1
};
}
throw new Error("Failed to parse color: " + color);
};

@@ -148,9 +158,21 @@

return color.a === 1 ? "#" + r.toString(16) + g.toString(16) + b.toString(16) : "rgba(" + r + "," + g + "," + b + "," + color.a.toFixed(2) + ")";
if (color.a === 1) {
var _s = function _s(c) {
var asString = c.toString(16);
return asString.length === 1 ? asString + asString : asString;
};
return "#" + _s(r) + _s(g) + _s(b);
} else {
return "rgba(" + r + "," + g + "," + b + "," + color.a.toFixed(2) + ")";
}
};
// Set the alpha value of a color.
// Adjust the alpha value of a color.
var fade = exports.fade = function fade(color, percentage) {
return format(_extends({}, parse(color), {
a: percentage
if (percentage < 0 || percentage > 1) {
throw new Error("Percentage must be between 0 and 1");
}
var components = parse(color);
return format(_extends({}, components, {
a: components.a * percentage
}));

@@ -157,0 +179,0 @@ };

@@ -13,3 +13,3 @@ // @flow

type Props = {
type Props = {|
color: string,

@@ -21,3 +21,3 @@ name: string,

segments: 1 | 2 | 3,
};
|};

@@ -24,0 +24,0 @@ const constants = {

@@ -1,2 +0,1 @@

// @flow
// This file is auto-generated by gen-snapshot-tests.js

@@ -10,2 +9,5 @@ // Do not edit this file. To make changes to these snapshot tests:

// Mock react-dom as jest doesn't like findDOMNode.
jest.mock("react-dom");
describe("wonder-blocks-color", () => {

@@ -12,0 +14,0 @@ it("example 1", () => {

// @flow
import {mix, fade} from "./utils.js";
import {mix, fade} from "./util/utils.js";

@@ -4,0 +4,0 @@ const offBlack = "#21242c";

{
"name": "@khanacademy/wonder-blocks-color",
"version": "1.0.2",
"version": "1.0.3",
"design": "v2",

@@ -15,4 +15,4 @@ "publishConfig": {

"devDependencies": {
"@khanacademy/wonder-blocks-core": "^1.0.2",
"@khanacademy/wonder-blocks-typography": "^1.0.2"
"@khanacademy/wonder-blocks-core": "^1.0.3",
"@khanacademy/wonder-blocks-typography": "^1.0.3"
},

@@ -19,0 +19,0 @@ "author": "",

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