Add save svg-badge directly to gist

This adds the posibility of saving an SVG badge generated by the same
shields.io dirictly to the gist. Instead of prepering a JSON file to
be sent to their service, we use their library directly, which outputs
an SVG file that we can save to the user’s gist.

Filenames ending in `.svg` will use this library automatically.

Additionally there is a major refactoring where the older `node:http`
library has been swapped out for `fetch`.

Also swap from node 16 to node 20

fixes #24
This commit is contained in:
Rúnar Berg
2023-09-26 17:37:34 -07:00
parent b7809ee0af
commit a2d3829b14
63 changed files with 4632 additions and 137 deletions

18
node_modules/char-width-table-consumer/CHANGELOG.md generated vendored Normal file
View File

@@ -0,0 +1,18 @@
# Changelog
## 1.0.0 Apr 12, 2019
- Update dependencies.
- Same API as previous release.
## 0.2.1 Nov 15, 2018
No external changes.
## 0.2.0 Nov 13, 2018
- Add `loadConsumerSync()` function.
## 0.1.0 Nov 13, 2018
Initial release.

21
node_modules/char-width-table-consumer/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2018 Metabolize LLC
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

32
node_modules/char-width-table-consumer/README.md generated vendored Normal file
View File

@@ -0,0 +1,32 @@
# char-width-table-consumer
[![version](https://img.shields.io/npm/v/char-width-table-consumer.svg?style=flat-square)][npm]
[![license](https://img.shields.io/npm/l/char-width-table-consumer.svg?style=flat-square)][npm]
[![build](https://img.shields.io/circleci/project/github/metabolize/anafanafo.svg?style=flat-square)][build]
[![code style](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)][prettier]
[![lerna](https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg?style=flat-square)][lerna]
[npm]: https://npmjs.com/char-width-table-consumer
[build]: https://circleci.com/gh/metabolize/anafanafo/tree/master
[prettier]: https://prettier.io/
[lerna]: https://lernajs.io/
Measure text using a character width table.
[puppeteer]: https://pptr.dev/
## Features
This library allows efficient text measuring using a character width table.
Create the tables using companion package [char-width-table-builder][].
This performs a simple lookup, without considering kerning.
Built with [Shields][] in mind.
[char-width-table-builder]: https://www.npmjs.com/package/char-width-table-builder
[shields]: https://github.com/badges/shields/
## License
This project is licensed under the MIT license.

16
node_modules/char-width-table-consumer/package.json generated vendored Normal file
View File

@@ -0,0 +1,16 @@
{
"name": "char-width-table-consumer",
"version": "1.0.0",
"repository": "metabolize/anafanafo",
"description": "Measure text using a character width table",
"main": "src",
"scripts": {
"test": "jest"
},
"author": "Metabolize",
"license": "MIT",
"dependencies": {
"binary-search": "^1.3.5"
},
"gitHead": "4bd230d372ffe93cd9bf7f036b83be6ef5dab75e"
}

79
node_modules/char-width-table-consumer/src/consumer.js generated vendored Normal file
View File

@@ -0,0 +1,79 @@
'use strict'
const fs = require('fs')
const bs = require('binary-search')
const { promisify } = require('util')
const readFile = promisify(fs.readFile)
module.exports = class CharWidthTableConsumer {
constructor(data) {
this.data = data
this.emWidth = this.widthOf('m')
}
static create(data) {
return new CharWidthTableConsumer(data)
}
static async load(path) {
const json = await readFile(path)
const data = JSON.parse(json)
return new CharWidthTableConsumer(data)
}
static loadSync(path) {
const json = fs.readFileSync(path)
const data = JSON.parse(json)
return new CharWidthTableConsumer(data)
}
static isControlChar(charCode) {
return charCode <= 31 || charCode === 127
}
widthOfCharCode(charCode) {
if (this.constructor.isControlChar(charCode)) {
return 0.0
}
// https://github.com/darkskyapp/binary-search/pull/18
const index = bs(this.data, charCode, ([lower], needle) => lower - needle)
if (index >= 0) {
// The index matches the beginning of a range.
const [, , width] = this.data[index]
return width
} else {
// The index does not match the beginning of a range, which means it
// should be in the preceeding range A return value of `-x` means the
// needle would be at `x - 1`, and we want to check the element before
// that.
const candidateIndex = -index - 2
const [lower, upper, width] = this.data[candidateIndex]
if (charCode >= lower && charCode <= upper) {
return width
} else {
return undefined
}
}
}
widthOf(text, { guess = true } = {}) {
// Array.from() will split a string into an array of strings, each of
// which contains a single code point.
// https://stackoverflow.com/a/42596897/893113
return Array.from(text).reduce((accumWidth, char) => {
const charWidth = this.widthOfCharCode(char.codePointAt(0))
if (charWidth === undefined) {
if (guess) {
return accumWidth + this.emWidth
} else {
throw Error(
`No width available for character code ${char.codePointAt(0)}`
)
}
} else {
return accumWidth + charWidth
}
}, 0.0)
}
}

16
node_modules/char-width-table-consumer/src/index.js generated vendored Normal file
View File

@@ -0,0 +1,16 @@
'use strict'
const CharWidthTableConsumer = require('./consumer')
const {
create: createConsumer,
load: loadConsumer,
loadSync: loadConsumerSync,
} = CharWidthTableConsumer
module.exports = {
createConsumer,
loadConsumer,
loadConsumerSync,
CharWidthTableConsumer,
}