badge-up
Advanced tools
Comparing version 2.2.0 to 2.3.0
{ | ||
"name": "badge-up", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "A module that produces hot badges without the need of Cairo", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -42,2 +42,4 @@ # badge-up | ||
either of which is used to color the section | ||
* `s{{hex}{hex}{hex}{hex}{hex}{hex}}` six hexadecimal characters or `s{css-color-name}` a named CSS color, | ||
either of which is used to color stroke the section, e.g. `s{d3d3d3}` | ||
@@ -53,3 +55,3 @@ The default color for the first section is `696969` and `d3d3d3` for subsequent sections. | ||
[ 'bar\nbaz', 'orange'], | ||
[ 'mork "mindy"', 'olive'], | ||
[ 'mork "mindy"', 'olive', 's{white}'], | ||
[ '<∀>', 'moccasin'] | ||
@@ -56,0 +58,0 @@ ]; |
33
v2.js
@@ -23,3 +23,19 @@ /* | ||
/** | ||
* Validate and return appropriate color code from input string | ||
* @method getColorCode | ||
* @param {String} input String to check for valid color code | ||
*/ | ||
function getColorCode(input) { | ||
if (input.match(/^[0-9a-f]{6}$/i)) { | ||
return '#' + input.toLowerCase(); | ||
} | ||
if (colors[input]) { | ||
return colors[input]; | ||
} | ||
return false; | ||
} | ||
function sectionsToData(sections) { | ||
@@ -47,9 +63,14 @@ var badgeData = { | ||
section.forEach(function(attribute) { | ||
if (attribute.match(/^[0-9a-f]{6}$/i)) { | ||
sectionData.color = '#' + attribute.toLowerCase(); | ||
return; | ||
// stroke attribute `s{color}` as CSS color or color code in hex | ||
var strokeAttribute = attribute.match(/^s\{(.*?)\}/i); | ||
if (strokeAttribute && strokeAttribute.length > 0) { | ||
if (getColorCode(strokeAttribute[1])) { | ||
sectionData.stroke = getColorCode(strokeAttribute[1]); | ||
} | ||
} | ||
if (colors[attribute]) { | ||
sectionData.color = colors[attribute]; | ||
return; | ||
// fill color attribute (without attribute qualifier) as CSS color or color code in hex | ||
if (getColorCode(attribute)) { | ||
sectionData.color = getColorCode(attribute); | ||
} | ||
@@ -56,0 +77,0 @@ // FUTURE -- text alignment `a{align}` lmr (only matters when multiline) |
Sorry, the diff of this file is not supported yet
23987
10
206
65