@flourish/pocket-knife
Advanced tools
Comparing version 0.4.0 to 0.5.0
{ | ||
"name": "@flourish/pocket-knife", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"description": "Flourish module with handy tools", | ||
@@ -31,3 +31,6 @@ "main": "pocket-knife.js", | ||
"*.js": "eslint src" | ||
}, | ||
"dependencies": { | ||
"d3-color": "^1.4.0" | ||
} | ||
} |
@@ -16,2 +16,14 @@ # Flourish pocket knife | ||
### getTextWidth(string, font) | ||
Gets width of text. First argument contains the text you want to calculate the width for. The second argument is optional and lets you set font settings for the text in the standard css font property, eg. `16px arial bold`. If `font` is empty, it uses `10px sans-serif`. | ||
Gets width of text. First argument contains the text you want to calculate the width for. The second argument is optional and lets you set font settings for the text in the standard css font property, eg. `16px arial bold`. If `font` is empty, it uses `10px sans-serif`. | ||
### hexToColor(hex_string, opacity) | ||
Converts hex to d3 color object as described [here](https://github.com/d3/d3-color#color) | ||
``` | ||
hexToColor("#00ff00", 0.5); // {r: 0, g: 255, b: 0, a: 0.5} | ||
``` | ||
### hexToRgba(hex_string, opacity) | ||
Converts hex to rgba string | ||
``` | ||
hexToRgba("#00ff00", 0.5); // rgba(0, 255, 0, 0.5) | ||
``` |
@@ -0,1 +1,5 @@ | ||
### 0.5.0 | ||
* Add `hexToColor()` | ||
* Add `hexToRgba()` | ||
### 0.4.0 | ||
@@ -2,0 +6,0 @@ * Recognise `data:` URIs in the `isUrl()` and `isImage()` functions |
@@ -0,1 +1,3 @@ | ||
import { color } from "d3-color"; | ||
var getTextWidth = (function() { | ||
@@ -20,2 +22,15 @@ var context = document.createElement("canvas").getContext("2d"); | ||
export { getTextWidth, isImage, isUrl } | ||
function hexToColor(hex_string, opacity) { | ||
if (typeof hex_string != "string") return false; | ||
var c = color(hex_string); | ||
c.opacity = opacity !== undefined ? opacity : 1; | ||
return c; | ||
} | ||
function hexToRgba(hex_string, opacity) { | ||
var c = hexToColor(hex_string, opacity); | ||
return c ? c.toString() : false; | ||
} | ||
export { getTextWidth, isImage, isUrl, hexToColor, hexToRgba }; |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
3807
51
28
0
1
+ Addedd3-color@^1.4.0
+ Addedd3-color@1.4.1(transitive)