Fast handcraft svg badge generator library . Used on badgen.net.
 
 
Go to file
Evelyn Hathaway 179a1d3c2a
feat: add accessible text alternative in SVG (#62)
* feat: accessible text alternative in SVG

* fix: change alt text strategy to support IE 11
2020-07-06 22:52:07 +08:00
.github Add workflow nodejs.yml 2019-08-24 13:47:07 +08:00
bench refactor: js => ts 2019-10-03 12:10:43 +08:00
preview feat: support `scale` arg (badgen/badgen.net#309) 2019-10-03 10:47:22 +08:00
src feat: add accessible text alternative in SVG (#62) 2020-07-06 22:52:07 +08:00
tap-snapshots feat: add accessible text alternative in SVG (#62) 2020-07-06 22:52:07 +08:00
test test: migrate to typescript 2019-10-04 10:27:41 +08:00
.gitignore use ncc & test on dist 2019-01-29 20:53:41 +08:00
.npmignore use ncc & test on dist 2019-01-29 20:53:41 +08:00
.travis.yml chore: publish bundled badgen.min.js only 2018-09-07 23:05:09 +08:00
LICENSE.md chore: add license and improve readme 2018-08-08 22:05:01 +02:00
README.md docs: update browser bundle url 2020-05-09 14:25:53 +08:00
package-lock.json 3.1.0 2020-05-09 14:26:11 +08:00
package.json 3.1.0 2020-05-09 14:26:11 +08:00
tsconfig.json chore: update tsconfig 2019-10-03 12:31:17 +08:00

README.md

badgen

npm version Coverage Status Bundle size License

Fast handcraft svg badge generator. Used on badgen.net.

  • 🌀 Zero dependency
  • Fast by design (see benchmarks)
  • 👯 Running in node & browser

Usage

npm install badgen

const { badgen } = require('badgen')

// only `status` is required.
const svgString = badgen({
  label: 'npm',     // <Text>
  labelColor: 'ADF' // <Color RGB> or <Color Name> (default: '555')
  status: 'v1.2.3', // <Text>, required
  color: 'blue',    // <Color RGB> or <Color Name> (default: 'blue')
  style: 'flat',    // 'flat' or 'classic' (default: 'classic')
  icon: 'data:image/svg+xml;base64,...', // Use icon (default: undefined)
  iconWidth: 13,    // Set this if icon is not square (default: 13)
  scale: 1          // Set badge scale (default: 1)
})

Available color names:

In browser

<script src="https://unpkg.com/badgen"></script>
<script>
  var svgString = badgen.badgen({ /*...*/ })
</script>

Benchmarks

npm run bench on iMac 5K (Late 2014), 3.5G i5, with Node.js 12.11.0:

[classic] style, long params x 985,898 ops/sec ±0.37% (94 runs sampled)
[classic] style, full params x 1,284,886 ops/sec ±0.42% (95 runs sampled)
[classic] style, with emoji  x 1,291,768 ops/sec ±0.28% (95 runs sampled)
[classic] style, with icon   x 1,177,120 ops/sec ±0.94% (95 runs sampled)
   [flat] style, long params x 780,504 ops/sec ±0.39% (94 runs sampled)
   [flat] style, full params x 1,012,111 ops/sec ±0.40% (97 runs sampled)
   [flat] style, with emoji  x 1,013,695 ops/sec ±0.91% (95 runs sampled)
   [flat] style, with icon   x 994,481 ops/sec ±0.30% (94 runs sampled)

See Also