pull/10/merge
Amio 2018-08-14 21:38:51 +08:00
commit 7f01ac1a82
6 zmienionych plików z 34 dodań i 25 usunięć

5
LICENSE.md 100644
Wyświetl plik

@ -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.

Wyświetl plik

@ -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
![ISC](https://badgen.net/badge/license/ISC/blue)
[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

Wyświetl plik

@ -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 }

Wyświetl plik

@ -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

Wyświetl plik

@ -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)
}

Wyświetl plik

@ -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)