kopia lustrzana https://github.com/badgen/badgen
Merge branch 'master' of https://github.com/amio/badgen
commit
7f01ac1a82
|
@ -0,0 +1,5 @@
|
|||
Copyright 2018 Amio
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
30
README.md
30
README.md
|
@ -1,12 +1,13 @@
|
|||
# badgen
|
||||
# Badgen
|
||||
|
||||
[![npm version][npm-badge]][npm-link]
|
||||
[![install size][pp-badge]][pp-link]
|
||||
[![Coverage Status][cr-badge]][cr-link]
|
||||
[![npm version][npm-src]][npm-href]
|
||||
[![Coverage Status][coveralls-src]][coveralls-href]
|
||||
[![Install size][packagephobia-src]][packagephobia-href]
|
||||
[![License][license-src]][license-href]
|
||||
|
||||
Fast handcraft svg badge generator. Used on [badgen.net](https://badgen.net).
|
||||
|
||||
- 🌀 1 dependency ([unicode-astral-regex][uar-link])
|
||||
- 🌀 1 dependency ([unicode-astral-regex](https://www.npmjs.com/package/unicode-astral-regex))
|
||||
- ⚡️ Fast by design (see [benchmarks](#benchmarks))
|
||||
- 👯 Pure JavaScript, running in node & browser
|
||||
|
||||
|
@ -53,14 +54,11 @@ Available color names:
|
|||
[classic] style, with icon x 844,518 ops/sec ±1.10% (94 runs sampled)
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||

|
||||
|
||||
[npm-badge]: https://badgen.net/npm/v/badgen
|
||||
[npm-link]: https://www.npmjs.com/package/badgen
|
||||
[pp-badge]: https://packagephobia.now.sh/badge?p=badgen
|
||||
[pp-link]: https://packagephobia.now.sh/result?p=badgen
|
||||
[cr-badge]: https://coveralls.io/repos/github/amio/badgen/badge.svg?branch=master
|
||||
[cr-link]: https://coveralls.io/github/amio/badgen?branch=master
|
||||
[uar-link]: https://www.npmjs.com/package/unicode-astral-regex
|
||||
[npm-src]: https://badgen.net/npm/v/badgen
|
||||
[npm-href]: https://www.npmjs.com/package/badgen
|
||||
[packagephobia-src]: https://badgen.net/packagephobia/install/badgen
|
||||
[packagephobia-href]: https://packagephobia.now.sh/result?p=badgen
|
||||
[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
|
||||
|
|
|
@ -2,7 +2,10 @@ const { Suite } = require('benchmark')
|
|||
const badgen = require('..')
|
||||
const dockerIcon = require('../test/docker-icon-b64.js')
|
||||
|
||||
const longParams = { subject: 'build-build-build', status: 'passing-passing-passing' }
|
||||
const longParams = {
|
||||
subject: 'build-build-build',
|
||||
status: 'passing-passing-passing'
|
||||
}
|
||||
const fullParams = { subject: 'license', status: 'Apache 2.0', color: 'cyan' }
|
||||
const emojiParams = { subject: 'emojis', status: '💩🤱🦄💩🤱🦄', emoji: true }
|
||||
const iconParams = { subject: 'docker', status: 'badge', icon: dockerIcon }
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
const widthsVerdana11 = require('./widths-verdana-11.json')
|
||||
const astralRegex = require('unicode-astral-regex')
|
||||
|
||||
function calcWidth (charWidthTable) {
|
||||
const calcWidth = (charWidthTable) => {
|
||||
const SCALE = 10 // Prevent results like 60.599999999999994
|
||||
const widthTable = charWidthTable.map(w => Math.round(w * SCALE))
|
||||
widthTable[64] = widthTable[64] + 6 // Slightly increase width of "@" by 0.6px
|
||||
|
||||
return function (text, astral) {
|
||||
return (text, astral) => {
|
||||
if (astral) text = text.match(astralRegex) || []
|
||||
|
||||
let total = 0
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const calcWidth = require('./calc-text-width.js').Verdana11
|
||||
const colorPresets = require('./color-presets.js')
|
||||
|
||||
module.exports = function ({subject, status, color, style, emoji, icon, iconWidth = 13}) {
|
||||
module.exports = ({ subject, status, color, style, emoji, icon, iconWidth = 13 }) => {
|
||||
typeAssert(typeof subject === 'string', '<subject> must be string')
|
||||
typeAssert(typeof status === 'string', '<status> must be string')
|
||||
color = colorPresets[color] || color || colorPresets['blue']
|
||||
|
@ -54,6 +54,6 @@ module.exports = function ({subject, status, color, style, emoji, icon, iconWidt
|
|||
`
|
||||
}
|
||||
|
||||
function typeAssert (assertion, message) {
|
||||
const typeAssert = (assertion, message) => {
|
||||
if (!assertion) throw new TypeError(message)
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ const serveBadge = (req, res) => {
|
|||
.map(s => qs.unescape(s))
|
||||
|
||||
res.writeHead(200, { 'Content-Type': 'image/svg+xml;charset=utf-8' })
|
||||
res.end(badgen({subject, status, color, style, emoji, icon}))
|
||||
res.end(badgen({ subject, status, color, style, emoji, icon }))
|
||||
}
|
||||
|
||||
// @example
|
||||
|
@ -44,8 +44,11 @@ const serve404 = (req, res) => {
|
|||
|
||||
http.createServer((req, res) => {
|
||||
switch (req.url) {
|
||||
case '/': return serveIndex(req, res)
|
||||
case '/favicon.ico': return serve404(req, res)
|
||||
default: return serveBadge(req, res)
|
||||
case '/':
|
||||
return serveIndex(req, res)
|
||||
case '/favicon.ico':
|
||||
return serve404(req, res)
|
||||
default:
|
||||
return serveBadge(req, res)
|
||||
}
|
||||
}).listen(3000)
|
||||
|
|
Ładowanie…
Reference in New Issue