Coerce text to string.

Caused issues with numbers being .replace()'d.
This commit is contained in:
Thaddee Tyl 2014-11-19 09:15:37 +01:00
parent 7572a829f9
commit 2e868d1e12
2 changed files with 11 additions and 2 deletions

View File

@ -19,7 +19,7 @@ npm install gh-badges
```js
var badge = require('gh-badges');
badge({ text: [ "build", "passed" ], colorscheme: "green" },
function(svg) {
function(svg, err) {
// svg is a String… of your badge.
});
```

View File

@ -52,6 +52,10 @@ function makeImage(data, cb) {
if (!(data.template + '-' + data.format in templates)) {
data.template = 'default';
}
// String coercion.
data.text[0] = '' + data.text[0];
data.text[1] = '' + data.text[1];
var template = templates[data.template + '-' + data.format];
if (data.colorscheme) {
data.colorA = colorscheme[data.colorscheme].colorA;
@ -63,7 +67,12 @@ function makeImage(data, cb) {
];
addEscapers(data);
var result = template(data);
try {
var result = template(data);
} catch(e) {
cb('', e);
return;
}
if (data.format === 'json') {
cb(result);