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 1.0.1 to 1.1.0

13

lib/calc-text-width.js
// Generate on https://codesandbox.io/s/lr4ynm652m
/* eslint-disable comma-spacing */
const Arial12Widths = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3.333984375,3.333984375,4.259765625,6.673828125,6.673828125,10.669921875,8.00390625,2.291015625,3.99609375,3.99609375,4.669921875,7.0078125,3.333984375,3.99609375,3.333984375,3.333984375,6.673828125,6.673828125,6.673828125,6.673828125,6.673828125,6.673828125,6.673828125,6.673828125,6.673828125,6.673828125,3.333984375,3.333984375,7.0078125,7.0078125,7.0078125,6.673828125,12.181640625,8.00390625,8.00390625,8.666015625,8.666015625,8.00390625,7.330078125,9.333984375,8.666015625,3.333984375,6,8.00390625,6.673828125,9.99609375,8.666015625,9.333984375,8.00390625,9.333984375,8.666015625,8.00390625,7.330078125,8.666015625,8.00390625,11.326171875,8.00390625,8.00390625,7.330078125,3.333984375,3.333984375,3.333984375,5.630859375,6.673828125,3.99609375,6.673828125,6.673828125,6,6.673828125,6.673828125,3.333984375,6.673828125,6.673828125,2.666015625,2.666015625,6,2.666015625,9.99609375,6.673828125,6.673828125,6.673828125,6.673828125,3.99609375,6,3.333984375,6.673828125,6,8.666015625,6,6,6,4.0078125,3.1171875,4.0078125,7.0078125]
const Tahoma12Widths = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3.75,3.984375,4.81640625,8.73046875,6.55078125,11.71875,8.0859375,2.53125,4.59375,4.59375,6.55078125,8.73046875,3.6328125,4.359375,3.6328125,4.587890625,6.55078125,6.55078125,6.55078125,6.55078125,6.55078125,6.55078125,6.55078125,6.55078125,6.55078125,6.55078125,4.2421875,4.2421875,8.73046875,8.73046875,8.73046875,5.68359375,10.91015625,7.1953125,7.072265625,7.20703125,8.138671875,6.732421875,6.2578125,8.009765625,8.103515625,4.4765625,4.998046875,7.0546875,5.970703125,9.24609375,8.009765625,8.490234375,6.615234375,8.490234375,7.447265625,6.685546875,7.0078125,7.869140625,7.16015625,10.822265625,6.966796875,6.9140625,6.708984375,4.59375,4.587890625,4.59375,8.73046875,6.55078125,6.55078125,6.298828125,6.6328125,5.537109375,6.6328125,6.31640625,3.8203125,6.6328125,6.69140625,2.7421875,3.380859375,5.9765625,2.7421875,10.078125,6.69140625,6.515625,6.6328125,6.6328125,4.32421875,5.35546875,4.013671875,6.69140625,5.9765625,8.90625,5.94140625,5.9765625,5.33203125,5.765625,4.587890625,5.765625,8.73046875]
const Verdana12Widths = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4.21875,4.72265625,5.5078125,9.8203125,7.62890625,12.9140625,8.71875,3.22265625,5.44921875,5.44921875,7.62890625,9.8203125,4.365234375,5.44921875,4.365234375,5.44921875,7.62890625,7.62890625,7.62890625,7.62890625,7.62890625,7.62890625,7.62890625,7.62890625,7.62890625,7.62890625,5.44921875,5.44921875,9.8203125,9.8203125,9.8203125,6.544921875,12,8.203125,8.2265625,8.37890625,9.24609375,7.587890625,6.896484375,9.3046875,9.017578125,5.05078125,5.455078125,8.314453125,6.6796875,10.11328125,8.9765625,9.4453125,7.236328125,9.4453125,8.34375,8.203125,7.39453125,8.783203125,8.203125,11.865234375,8.220703125,7.3828125,8.220703125,5.44921875,5.44921875,5.44921875,9.8203125,7.62890625,7.62890625,7.20703125,7.4765625,6.251953125,7.4765625,7.1484375,4.21875,7.4765625,7.59375,3.29296875,4.130859375,7.1015625,3.29296875,11.671875,7.59375,7.283203125,7.4765625,7.4765625,5.12109375,6.251953125,4.728515625,7.59375,7.1015625,9.8203125,7.1015625,7.1015625,6.3046875,7.6171875,5.44921875,7.6171875,9.8203125]
const Arial12Widths = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3.33,3.33,4.26,6.67,6.67,10.7,8,2.29,4,4,4.67,7.01,3.33,4,3.33,3.33,6.67,6.67,6.67,6.67,6.67,6.67,6.67,6.67,6.67,6.67,3.33,3.33,7.01,7.01,7.01,6.67,12.2,8,8,8.67,8.67,8,7.33,9.33,8.67,3.33,6,8,6.67,10,8.67,9.33,8,9.33,8.67,8,7.33,8.67,8,11.3,8,8,7.33,3.33,3.33,3.33,5.63,6.67,4,6.67,6.67,6,6.67,6.67,3.33,6.67,6.67,2.67,2.67,6,2.67,10,6.67,6.67,6.67,6.67,4,6,3.33,6.67,6,8.67,6,6,6,4.01,3.12,4.01,7.01]
const Verdana12Widths = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4.22,4.72,5.51,9.82,7.63,12.9,8.72,3.22,5.45,5.45,7.63,9.82,4.37,5.45,4.37,5.45,7.63,7.63,7.63,7.63,7.63,7.63,7.63,7.63,7.63,7.63,5.45,5.45,9.82,9.82,9.82,6.54,12,8.2,8.23,8.38,9.25,7.59,6.9,9.3,9.02,5.05,5.46,8.31,6.68,10.1,8.98,9.45,7.24,9.45,8.34,8.2,7.39,8.78,8.2,11.9,8.22,7.38,8.22,5.45,5.45,5.45,9.82,7.63,7.63,7.21,7.48,6.25,7.48,7.15,4.22,7.48,7.59,3.29,4.13,7.1,3.29,11.7,7.59,7.28,7.48,7.48,5.12,6.25,4.73,7.59,7.1,9.82,7.1,7.1,6.3,7.62,5.45,7.62,9.82]
function calcWidth (charWidthTable) {
const SHIFT = 10
const LETTER_SPACING = 0.4 * SHIFT
const widthTable = charWidthTable.map(w => Math.round(w * SHIFT + LETTER_SPACING))
const SCALE = 100
const widthTable = charWidthTable.map(w => Math.round(w * SCALE))
return function (text) {

@@ -22,3 +20,3 @@ if (typeof text !== 'string') {

}
return total / SHIFT
return total / SCALE
}

@@ -30,4 +28,3 @@ }

Arial12: calcWidth(Arial12Widths),
Tahoma12: calcWidth(Tahoma12Widths),
Verdana12: calcWidth(Verdana12Widths)
}

@@ -1,2 +0,2 @@

const calcWidth = require('./calc-text-width.js').Arial12
const calcWidth = require('./calc-text-width.js').Verdana12
const colorPresets = require('./color-presets.js')

@@ -7,7 +7,4 @@

const sbTextWidth = calcWidth(subject)
const sbRectWidth = sbTextWidth + 10
const stTextWidth = calcWidth(status)
const stRectWidth = stTextWidth + 11
const sbRectWidth = calcWidth(subject) + 10
const stRectWidth = calcWidth(status) + 11
const stTextStart = sbRectWidth + 5

@@ -23,11 +20,11 @@

</linearGradient>
<rect rx="3" width="${width}" height="20" fill="#555"/>
<rect rx="3" x="${sbRectWidth}" width="${stRectWidth}" height="20" fill="#${color}"/>
<path fill="#${color}" d="M${sbRectWidth} 0h4v20h-4z"/>
<rect rx="3" width="${width}" height="20" fill="#${color}"/>
<rect rx="3" x="0" width="${sbRectWidth}" height="20" fill="#555"/>
<path fill="#555" d="M${sbRectWidth} 0v20h-4v-20h4z"/>
<rect rx="3" width="${width}" height="20" fill="url(#a)"/>
<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 fill="#fff" text-anchor="start" font-family="DejaVu Sans,Verdana,sans-serif" font-size="12">
<text x="6" y="15" fill="#000" opacity="0.2">${subject}</text>
<text x="5" y="14">${subject}</text>
<text x="${stTextStart + 1}" y="15" fill="#000" opacity="0.2">${status}</text>
<text x="${stTextStart}" y="14">${status}</text>
</g><script/>

@@ -34,0 +31,0 @@ </svg>

{
"name": "badgen",
"version": "1.0.1",
"version": "1.1.0",
"description": "Hand-crafted badge generator.",

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

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

```bash
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)
generate by short params x 1,085,052 ops/sec ±1.03% (83 runs sampled)
generate by long params x 1,046,942 ops/sec ±0.61% (93 runs sampled)
generate by full params x 1,266,881 ops/sec ±0.76% (91 runs sampled)
```

@@ -55,3 +55,3 @@

[npm-badge]: https://img.shields.io/npm/v/badgen.svg
[npm-badge]: https://badgen.now.sh/npm/v/badgen
[npm-link]: https://www.npmjs.com/package/badgen

@@ -58,0 +58,0 @@ [pp-badge]: https://packagephobia.now.sh/badge?p=badgen

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