From a338c832eef924317be1457dcaf22ab4547f2f11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20M=C3=BCller?= Date: Wed, 8 Aug 2018 22:05:01 +0200 Subject: [PATCH 1/2] chore: add license and improve readme --- LICENSE.md | 5 +++++ README.md | 30 ++++++++++++++---------------- 2 files changed, 19 insertions(+), 16 deletions(-) create mode 100644 LICENSE.md diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..13e5e80 --- /dev/null +++ b/LICENSE.md @@ -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. diff --git a/README.md b/README.md index b84fd56..e4a24c0 100644 --- a/README.md +++ b/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 - -![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 From e76dfaa370fe2bc942cf915d3574de920afd78ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20M=C3=BCller?= Date: Fri, 10 Aug 2018 16:15:58 +0200 Subject: [PATCH 2/2] refactor: modernize codebase and unify code style (#9) --- bench/index.js | 5 ++++- lib/calc-text-width.js | 4 ++-- lib/index.js | 4 ++-- preview/serve.js | 11 +++++++---- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/bench/index.js b/bench/index.js index 04f4efa..8d8f644 100644 --- a/bench/index.js +++ b/bench/index.js @@ -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 } diff --git a/lib/calc-text-width.js b/lib/calc-text-width.js index 9cd57ed..2be307c 100644 --- a/lib/calc-text-width.js +++ b/lib/calc-text-width.js @@ -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 diff --git a/lib/index.js b/lib/index.js index 4dd9571..0fc3b38 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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', ' must be string') typeAssert(typeof status === 'string', ' 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) } diff --git a/preview/serve.js b/preview/serve.js index 79c1e44..ffbf33a 100644 --- a/preview/serve.js +++ b/preview/serve.js @@ -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)