Comparing version 2.0.1 to 2.2.0
60
index.js
@@ -13,48 +13,6 @@ /* | ||
template = dot.template(fs.readFileSync(path.join(__dirname, 'templates', 'basic.svg'), 'utf-8')), | ||
// Lookup values based on Verdana ttf of 11px | ||
lookup = [0,25,25,25,25,25,25,25,0,23,0,25,25,0,25,25,25,25,25,25,25,25,25, | ||
25,25,25,25,25,25,0,25,25,3,3,4,6,6,9,7,2,4,4,4,6,3,4,3,3,6,6,6,6,6,6,6, | ||
6,6,6,3,3,6,6,6,6,11,7,7,8,8,7,7,8,8,3,5,7,6,9,8,8,7,8,8,7,7,8,7,10,7,7, | ||
7,3,3,3,5,6,4,6,6,5,6,6,3,6,6,3,3,5,3,9,6,6,6,6,4,5,3,6,5,8,5,5,5,4,3,4, | ||
6,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25, | ||
25,25,25,25,25,25,25,25,25,25,3,4,6,6,6,6,3,6,4,8,4,6,6,0,8,4,4,6,4,4,4, | ||
6,6,3,4,4,4,6,9,9,9,7,7,7,7,7,7,7,10,8,7,7,7,7,3,3,3,3,8,8,8,8,8,8,8,6, | ||
8,8,8,8,8,7,7,7,6,6,6,6,6,6,9,5,6,6,6,6,3,3,3,3,6,6,6,6,6,6,6,6,7,6,6,6, | ||
6,5,6 | ||
]; | ||
v2 = require('./v2'), | ||
utils = require('./utils'); | ||
/** | ||
* Return the size of the text | ||
* | ||
* @method measureText | ||
* @param {String} text Text you want to measure | ||
* @return {Integer} Size in pixels of the text | ||
*/ | ||
function measureText(text) { | ||
var total = 0; | ||
// Measure each letter and add padding between letters | ||
text.split('').forEach(function (letter) { | ||
total += 1 + lookup[letter.charCodeAt(0)] || 0; | ||
}); | ||
// Add 10 extra pixels of padding | ||
return 10 + total; | ||
} | ||
/** | ||
* Escape the string so that it doesn't break xml | ||
* @method escapeXml | ||
* @param {String} string Input String | ||
* @return {String} XML Safe String | ||
*/ | ||
function escapeXml(string) { | ||
return string.replace(/&/g, '&') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>') | ||
.replace(/"/g, '"') | ||
.replace(/'/g, '''); | ||
} | ||
/** | ||
* Generates a SVG for pretty badges | ||
@@ -71,11 +29,12 @@ * | ||
text: [ | ||
escapeXml(field1), | ||
escapeXml(field2) | ||
utils.escapeXml(field1), | ||
utils.escapeXml(field2) | ||
], | ||
widths: [ | ||
measureText(field1), | ||
measureText(field2) | ||
// Add 10 extra pixels of padding | ||
utils.textWidth(field1) + 10, | ||
utils.textWidth(field2) + 10 | ||
], | ||
colorA: '#555', | ||
colorB: escapeXml(color) | ||
colorB: utils.escapeXml(color) | ||
}; | ||
@@ -108,1 +67,4 @@ | ||
}; | ||
// v2 API from v2.js | ||
module.exports.v2 = v2; |
{ | ||
"name": "badge-up", | ||
"version": "2.0.1", | ||
"version": "2.2.0", | ||
"description": "A module that produces hot badges without the need of Cairo", | ||
"main": "index.js", | ||
"scripts": { | ||
"lint": "jshint *.js test/*.js", | ||
"test": "jenkins-mocha" | ||
@@ -21,2 +22,3 @@ }, | ||
"Darren Matsumoto <bobafett@yahoo-inc.com>", | ||
"Drew Folta <folta@yahoo-inc.com>", | ||
"Noah Katzman <nkatzman@yahoo-inc.com>", | ||
@@ -27,12 +29,12 @@ "Peter Peterson <petey@yahoo-inc.com>", | ||
"jshintConfig": { | ||
"node": true, | ||
"json": true | ||
"node": true | ||
}, | ||
"devDependencies": { | ||
"chai": "~1.9.1", | ||
"jenkins-mocha": "~1.0.8", | ||
"mockery": "~1.4.0", | ||
"jenkins-mocha": "^2.6.0", | ||
"jshint": "^2.9.2", | ||
"sinon": "~1.10.3" | ||
}, | ||
"dependencies": { | ||
"css-color-names": "~0.0.3", | ||
"dot": "~1.0.2", | ||
@@ -39,0 +41,0 @@ "svgo": "~0.4.5" |
@@ -8,2 +8,3 @@ # badge-up | ||
## Install | ||
@@ -13,10 +14,7 @@ | ||
## Usage | ||
### Generating an SVG | ||
## V1 Usage | ||
```js | ||
var badge = require('badge-up'); | ||
badge('batman', 'component', badge.colors.green, function (error, svg) { | ||
@@ -28,1 +26,40 @@ // some callback | ||
Produces: ![example](https://cdn.rawgit.com/yahoo/badge-up/master/test/testData/good.svg) | ||
The color argument can be a CSS color, or one of the specially named colors | ||
found in `badge.colors`. | ||
## V2 Usage | ||
With this API you can create arbitrary badges with an arbitrary number of sections. | ||
Each section is an array. The first element is the text to show, and the rest | ||
of the (optional) elements are attributes to apply to the text. If there are no | ||
attributes then a single string (instead of an array of one element) can be | ||
passed instead. | ||
The following attributes are supported: | ||
* `{hex}{hex}{hex}{hex}{hex}{hex}` six hexadecimal characters or `{css-color-name}` a named CSS color, | ||
either of which is used to color the section | ||
The default color for the first section is `696969` and `d3d3d3` for subsequent sections. | ||
Any section can have mulitple lines by putting newlines in its text. | ||
```js | ||
var badge = require('badge-up'); | ||
var sections = [ | ||
'foo/far;fun', | ||
[ 'bar\nbaz', 'orange'], | ||
[ 'mork "mindy"', 'olive'], | ||
[ '<∀>', 'moccasin'] | ||
]; | ||
badge.v2(sections, function (error, svg) { | ||
// some callback | ||
}); | ||
``` | ||
Produces: ![example](https://cdn.rawgit.com/yahoo/badge-up/master/test/testData/v2-example.svg) | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13305
9
189
63
3
2
+ Addedcss-color-names@~0.0.3
+ Addedcss-color-names@0.0.4(transitive)