Socket
Socket
Sign inDemoInstall

badgen

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

badgen - npm Package Compare versions

Comparing version 0.3.0 to 1.0.0

4

bench/index.js
const { Suite } = require('benchmark')
const badgen = require('..')
const shortParams = { subject: 'b', status: 'p' }
const shortParams = { subject: '1', status: '2' }
const longParams = { subject: 'build-build-build', status: 'passing-passing-passing' }
const fullParams = { subject: 'license', status: 'Apache-2.0', color: 'blue' }
const fullParams = { subject: 'license', status: 'MIT', color: 'cyan' }

@@ -8,0 +8,0 @@ new Suite()

@@ -8,3 +8,5 @@ // Generate on https://codesandbox.io/s/lr4ynm652m

function calcWidth (charWidthTable) {
const widthTable = charWidthTable.map(w => w + 0.4) // Add letter-spacing
const SHIFT = 10
const LETTER_SPACING = 0.4 * SHIFT
const widthTable = charWidthTable.map(w => Math.round(w * SHIFT + LETTER_SPACING))
return function (text) {

@@ -21,3 +23,3 @@ if (typeof text !== 'string') {

}
return total
return total / SHIFT
}

@@ -24,0 +26,0 @@ }

@@ -5,11 +5,10 @@ const calcWidth = require('./calc-text-width.js').Arial12

module.exports = function ({subject, status, color}) {
color = colorPresets[color] || color || colorPresets['green']
color = colorPresets[color] || color || colorPresets['blue']
const sbTextWidth = calcWidth(subject)
const sbRectWidth = sbTextWidth + 10
const sbTextCenter = sbRectWidth / 2
const stTextWidth = calcWidth(status)
const stRectWidth = stTextWidth + 12
const stTextCenter = sbRectWidth + stRectWidth / 2 - 1
const stRectWidth = stTextWidth + 11
const stTextStart = sbRectWidth + 5

@@ -19,4 +18,3 @@ const width = sbRectWidth + stRectWidth

return `
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
width="${width}" height="20">
<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="20">
<linearGradient id="a" x2="0" y2="100%">

@@ -30,10 +28,10 @@ <stop offset="0" stop-color="#bbb" stop-opacity=".1"/>

<rect rx="3" width="${width}" height="20" fill="url(#a)"/>
<g fill="#fff" text-anchor="middle" font-family="Arial,sans-serif" font-size="12">
<text x="${sbTextCenter + 1}" y="15" textLength="${sbTextWidth}" fill="#000" opacity="0.2">${subject}</text>
<text x="${sbTextCenter}" y="14" textLength="${sbTextWidth}">${subject}</text>
<text x="${stTextCenter + 1}" y="15" textLength="${stTextWidth}" fill="#000" opacity="0.2">${status}</text>
<text x="${stTextCenter}" y="14" textLength="${stTextWidth}">${status}</text>
</g> <script xmlns=""/>
<g fill="#fff" text-anchor="start" font-family="Arial,sans-serif" font-size="12">
<text x="6" y="15" textLength="${sbTextWidth}" fill="#000" opacity="0.2">${subject}</text>
<text x="5" y="14" textLength="${sbTextWidth}">${subject}</text>
<text x="${stTextStart + 1}" y="15" textLength="${stTextWidth}" fill="#000" opacity="0.2">${status}</text>
<text x="${stTextStart}" y="14" textLength="${stTextWidth}">${status}</text>
</g><script/>
</svg>
`
}
{
"name": "badgen",
"version": "0.3.0",
"version": "1.0.0",
"description": "Hand-crafted badge generator.",

@@ -5,0 +5,0 @@ "author": "Amio <amio.cn@gmail.com>",

@@ -5,4 +5,4 @@ # badgen [![npm-version][npm-badge]][npm-link] [![install size][pp-badge]][pp-link]

- 🌀 Zero dependeny
- ⚡️ Fast (see [benchamrks](#benchmarks))
- 🌀 Zero dependency (compare with 11 deps for [gh-badges][gh-badges-link] which being used on [shields.io][shields-io])

@@ -27,2 +27,4 @@ ## Usage

![](https://badgen.now.sh/badge/color/blue/blue)
![](https://badgen.now.sh/badge/color/cyan/cyan)
![](https://badgen.now.sh/badge/color/green/green)

@@ -34,4 +36,2 @@ ![](https://badgen.now.sh/badge/color/yellow/yellow)

![](https://badgen.now.sh/badge/color/purple/purple)
![](https://badgen.now.sh/badge/color/blue/blue)
![](https://badgen.now.sh/badge/color/cyan/cyan)
![](https://badgen.now.sh/badge/color/grey/grey)

@@ -48,5 +48,5 @@

```bash
generate by short params x 543,857 ops/sec ±0.98% (90 runs sampled)
generate by long params x 512,747 ops/sec ±0.66% (91 runs sampled)
generate by full params x 461,409 ops/sec ±0.78% (90 runs sampled)
generate by short params x 806,080 ops/sec ±0.98% (88 runs sampled)
generate by long params x 735,925 ops/sec ±0.85% (90 runs sampled)
generate by full params x 770,180 ops/sec ±0.75% (90 runs sampled)
```

@@ -62,1 +62,3 @@

[pp-link]: https://packagephobia.now.sh/result?p=badgen
[shields-io]: https://shields.io
[gh-badges-link]: https://www.npmjs.com/package/gh-badges
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc