Move badge service to standalone repo

pull/3/head
Amio 2018-06-26 14:57:57 +08:00
rodzic 0def272856
commit f775abe85f
5 zmienionych plików z 5 dodań i 113 usunięć

Wyświetl plik

@ -7,38 +7,7 @@ Fast, handcraft, pure JavaScript badge generator.
## Usage
### Badge Service
`https://badgen.now.sh/badge/:subject/:status/:color`
- `subject` Text
- `status` Text
- `color` Color RGB (default '3C1') or Color Preset (`green`, `yellow`, ...see below)
Color Presets:
![](https://badgen.now.sh/badge/color/green/green)
![](https://badgen.now.sh/badge/color/yellow/yellow)
![](https://badgen.now.sh/badge/color/orange/orange)
![](https://badgen.now.sh/badge/color/red/red)
![](https://badgen.now.sh/badge/color/pink/pink)
![](https://badgen.now.sh/badge/color/purple/purple)
![](https://badgen.now.sh/badge/color/blue/blue)
![](https://badgen.now.sh/badge/color/grey/grey)
![](https://badgen.now.sh/badge/color/black/black)
Examples:
| Preview | URL |
| --- | --- |
|![](https://badgen.now.sh/badge/build/passing) | https://badgen.now.sh/badge/build/passing |
|![](https://badgen.now.sh/badge/stars/★★★★☆) | https://badgen.now.sh/badge/stars/★★★★☆ |
|![](https://badgen.now.sh/badge/style/standard/f2a) | https://badgen.now.sh/badge/style/standard/f2a |
|![](https://badgen.now.sh/badge/license/Apache-2.0/blue) | https://badgen.now.sh/badge/license/Apache-2.0/blue |
|![](https://badgen.now.sh/list/platform/ios,macos,tvos/grey) | https://badgen.now.sh/list/platform/ios,macos,tvos/grey |
### Programmatically
### npm package
`npm install badgen`
@ -52,6 +21,10 @@ const svgString = badgen({
})
```
### Badge Service
https://badgen.now.sh/
## Benchmarks
`npm run bench` on my iMac5K(Late 2014), 3.5G i5, with Node.js 10.5.0:

Wyświetl plik

@ -1,8 +0,0 @@
{
"alias": "badgen",
"files": [
"lib",
"README.md",
"service.js"
]
}

31
package-lock.json wygenerowano
Wyświetl plik

@ -815,12 +815,6 @@
"integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=",
"dev": true
},
"fast-decode-uri-component": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fast-decode-uri-component/-/fast-decode-uri-component-1.0.0.tgz",
"integrity": "sha512-WQSYVKn6tDW/3htASeUkrx5LcnuTENQIZQPCVlwdnvIJ7bYtSpoJYq38MgUJnx1CQIR1gjZ8HJxAEcN4gqugBg==",
"dev": true
},
"fast-deep-equal": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-1.1.0.tgz",
@ -858,16 +852,6 @@
"object-assign": "^4.0.1"
}
},
"find-my-way": {
"version": "1.13.0",
"resolved": "https://registry.npmjs.org/find-my-way/-/find-my-way-1.13.0.tgz",
"integrity": "sha512-aIa4UTxZ3klfApaQEJJ5cQvNeqfrxVngcjMgy+G5ygkrOrDPkORhY/RMH6F8mLwBpPt3Z0F03CtzN7gs2Q5H1w==",
"dev": true,
"requires": {
"fast-decode-uri-component": "^1.0.0",
"safe-regex": "^1.1.0"
}
},
"find-root": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/find-root/-/find-root-1.1.0.tgz",
@ -4540,12 +4524,6 @@
"signal-exit": "^3.0.2"
}
},
"ret": {
"version": "0.1.15",
"resolved": "https://registry.npmjs.org/ret/-/ret-0.1.15.tgz",
"integrity": "sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==",
"dev": true
},
"rimraf": {
"version": "2.6.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz",
@ -4591,15 +4569,6 @@
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==",
"dev": true
},
"safe-regex": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/safe-regex/-/safe-regex-1.1.0.tgz",
"integrity": "sha1-QKNmnzsHfR6UPURinhV91IAjvy4=",
"dev": true,
"requires": {
"ret": "~0.1.10"
}
},
"safer-buffer": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",

Wyświetl plik

@ -15,8 +15,6 @@
},
"devDependencies": {
"benchmark": "^2.1.4",
"find-my-way": "^1.13.0",
"lru-cache": "^4.1.3",
"standard": "^11.0.1",
"tap": "^12.0.1"
}

Wyświetl plik

@ -1,40 +0,0 @@
const http = require('http')
const cors = require('@amio/micro-cors')()
const router = require('find-my-way')()
const badgen = require('./lib/index')
const LRU = require('lru-cache')
const cache = new LRU({ max: 1000 })
function serveBadge (req, res, params) {
res.writeHead(200, { 'Content-Type': 'image/svg+xml;charset=utf-8' })
const cached = cache.get(req.url)
if (cached) {
res.end(cached)
} else {
const created = badgen(params)
cache.set(req.url, created)
res.end(created)
}
}
function serveListBadge (req, res, params) {
const { subject, status, color } = params
serveBadge(req, res, { subject, status: status.replace(/,/g, ' | '), color })
}
function redirect (req, res) {
res.writeHead(302, { 'Location': 'https://amio.github.io/badgen' })
res.end()
}
router.get('/badge/:subject/:status', serveBadge)
router.get('/badge/:subject/:status/:color', serveBadge)
router.get('/list/:subject/:status', serveListBadge)
router.get('/list/:subject/:status/:color', serveListBadge)
router.get('/', redirect)
const handler = cors((req, res) => router.lookup(req, res))
const server = http.createServer(handler)
server.listen(3000)