Breaking: simplify options arguments

pull/3/head
Amio 2018-07-16 21:58:23 +08:00
rodzic 3dc25dd7be
commit 4931e0d1a6
3 zmienionych plików z 7 dodań i 9 usunięć

Wyświetl plik

@ -13,13 +13,13 @@ Fast, handcraft, pure JavaScript badge generator.
```javascript
const badgen = require('badgen')
const options = { style: 'flat' }
const svgString = badgen({
subject: 'npm', // <Text>
status: 'v1.2.3', // <Text>
color: 'blue' // <Color RGB> or <Color Name>, optional
}, options) // options is optional
style: 'flat' // 'flat' or undefined, optional
})
```
Available color names:

Wyświetl plik

@ -1,15 +1,13 @@
const calcWidth = require('./calc-text-width.js').Verdana11
const colorPresets = require('./color-presets.js')
module.exports = function ({subject, status, color}, opts = {}) {
module.exports = function ({subject, status, color, style}) {
color = colorPresets[color] || color || colorPresets['blue']
const sbRectWidth = calcWidth(subject) + 11
const stRectWidth = calcWidth(status) + 11
const width = sbRectWidth + stRectWidth
const { style } = opts
if (style === 'flat') {
return `
<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="20">

Wyświetl plik

@ -13,14 +13,14 @@ tap.test('generate badge with { subject, status, color }', t => {
t.end()
})
tap.test('generate flat badge with { subject, status }', t => {
const svg = badgen({ subject: 'npm', status: 'v1.0.0' }, { style: 'flat' })
tap.test('generate badge with { subject, status, style }', t => {
const svg = badgen({ subject: 'npm', status: 'v1.0.0', style: 'flat' })
t.ok(typeof svg === 'string', 'successfully generated')
t.end()
})
tap.test('generate flat badge with { subject, status, color }', t => {
const svg = badgen({ subject: 'npm', status: 'v1.0.0', color: 'ADF' }, { style: 'flat' })
tap.test('generate badge with { subject, status, color, style }', t => {
const svg = badgen({ subject: 'npm', status: 'v1.0.0', color: 'ADF', style: 'flat' })
t.ok(typeof svg === 'string', 'successfully generated')
t.end()
})