kopia lustrzana https://github.com/badgen/badgen
Breaking: simplify options arguments
rodzic
3dc25dd7be
commit
4931e0d1a6
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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">
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
})
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue