badgen/README.md

84 wiersze
2.9 KiB
Markdown

2018-08-22 08:05:46 +00:00
# badgen
2018-07-18 07:38:59 +00:00
2018-08-08 20:05:01 +00:00
[![npm version][npm-src]][npm-href]
[![Coverage Status][coveralls-src]][coveralls-href]
2019-10-04 02:43:01 +00:00
[![Bundle size][bundlephobia-src]][bundlephobia-href]
2018-08-08 20:05:01 +00:00
[![License][license-src]][license-href]
2018-05-30 03:13:32 +00:00
2018-08-04 12:58:11 +00:00
Fast handcraft svg badge generator. Used on [badgen.net](https://badgen.net).
2018-05-30 03:13:32 +00:00
2018-08-23 02:23:52 +00:00
- 🌀 Zero dependency
2018-07-19 06:54:54 +00:00
- ⚡️ Fast by design (see [benchmarks](#benchmarks))
2019-10-03 04:31:08 +00:00
- 👯‍ Running in node & browser
2018-06-23 09:54:52 +00:00
2018-05-30 03:13:32 +00:00
## Usage
2018-06-23 03:20:45 +00:00
`npm install badgen`
2018-05-30 03:13:32 +00:00
2018-06-23 03:20:45 +00:00
```javascript
2019-10-03 05:33:08 +00:00
const { badgen } = require('badgen')
2018-05-30 03:13:32 +00:00
2019-07-06 07:39:09 +00:00
// only `status` is required.
2018-06-23 03:20:45 +00:00
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')
2019-10-03 04:31:08 +00:00
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)
2018-07-16 13:58:23 +00:00
})
2018-06-23 03:20:45 +00:00
```
2018-06-22 17:20:48 +00:00
2018-06-29 15:21:35 +00:00
Available color names:
2018-07-27 06:45:25 +00:00
![](https://badgen.net/badge/color/blue/blue)
![](https://badgen.net/badge/color/cyan/cyan)
![](https://badgen.net/badge/color/green/green)
![](https://badgen.net/badge/color/yellow/yellow)
![](https://badgen.net/badge/color/orange/orange)
![](https://badgen.net/badge/color/red/red)
![](https://badgen.net/badge/color/pink/pink)
![](https://badgen.net/badge/color/purple/purple)
![](https://badgen.net/badge/color/grey/grey)
2018-08-24 14:02:08 +00:00
![](https://badgen.net/badge/color/black/black)
2018-06-29 15:21:35 +00:00
2018-09-08 03:57:39 +00:00
### In browser
```html
2020-05-09 06:25:53 +00:00
<script src="https://unpkg.com/badgen"></script>
2018-09-08 03:57:39 +00:00
<script>
2022-04-30 07:54:32 +00:00
var svgString = badgen({ /*...*/ })
2018-09-08 03:57:39 +00:00
</script>
```
2018-06-23 09:54:52 +00:00
## Benchmarks
`npm run bench` on iMac 5K (Late 2014), 3.5G i5, with Node.js 12.11.0:
2018-06-23 09:54:52 +00:00
```bash
[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)
2018-06-23 09:54:52 +00:00
```
2018-09-12 03:22:02 +00:00
## See Also
- [gradient-badge][gradient-badge] - Badge generator with color gradient support
2018-08-08 20:05:01 +00:00
[npm-src]: https://badgen.net/npm/v/badgen
[npm-href]: https://www.npmjs.com/package/badgen
2019-10-04 02:43:01 +00:00
[bundlephobia-src]: https://badgen.net/bundlephobia/minzip/badgen
[bundlephobia-href]: https://bundlephobia.com/result?p=badgen
2018-08-08 20:05:01 +00:00
[coveralls-src]: https://badgen.net/coveralls/c/github/amio/badgen/master
[coveralls-href]: https://coveralls.io/github/amio/badgen?branch=master
[license-src]: https://badgen.net/github/license/amio/badgen
[license-href]: LICENSE.md
2018-09-12 03:22:02 +00:00
[gradient-badge]: https://github.com/bokub/gradient-badge