kopia lustrzana https://github.com/badgen/badgen.net
Extract match-router to standalone package
rodzic
03550f4bdc
commit
cf6a5bfb7c
|
@ -18,8 +18,7 @@ export const meta: Meta = {
|
|||
}
|
||||
|
||||
export const handlers: Handlers = {
|
||||
'/david/:topic/:user/:repo': handler,
|
||||
'/david/:topic/:user/:repo/:path+': handler
|
||||
'/david/:topic/:user/:repo/:path*': handler
|
||||
}
|
||||
|
||||
const statusInfo = {
|
||||
|
|
|
@ -60,8 +60,7 @@ export const meta: Meta = {
|
|||
}
|
||||
|
||||
export const handlers: Handlers = {
|
||||
'/https/:hostname': handler,
|
||||
'/https/:hostname/:path+': handler
|
||||
'/https/:hostname/:path*': handler
|
||||
}
|
||||
|
||||
async function handler ({ hostname, path }: Args) {
|
||||
|
|
|
@ -76,8 +76,7 @@ export const meta: Meta = {
|
|||
}
|
||||
|
||||
export const handlers: Handlers = {
|
||||
'/runkit/:endpoint-id': handler,
|
||||
'/runkit/:endpoint-id/:path+': handler
|
||||
'/runkit/:endpoint-id/:path*': handler
|
||||
}
|
||||
|
||||
async function handler ({ 'endpoint-id': id, path }: Args) {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import url from 'url'
|
||||
import matchRoute from 'my-way'
|
||||
|
||||
import serve404 from './serve-404'
|
||||
import serveBadge from './serve-badge'
|
||||
import matchRoute from './match-route'
|
||||
import sentry from './sentry'
|
||||
|
||||
import { BadgenParams } from './types'
|
||||
|
|
|
@ -8119,6 +8119,11 @@
|
|||
"integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=",
|
||||
"dev": true
|
||||
},
|
||||
"my-way": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/my-way/-/my-way-0.2.0.tgz",
|
||||
"integrity": "sha512-NY438jtUh89Oijs+vnwTQJb7vj42jvhgHUDbvPrMZPJZY0sZNN8zQrBWJBKygN9Ah+A9k19eKrz+k9K1pCTntQ=="
|
||||
},
|
||||
"nanoid": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-1.2.1.tgz",
|
||||
|
@ -8525,7 +8530,7 @@
|
|||
},
|
||||
"find-up": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz",
|
||||
"resolved": false,
|
||||
"integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
|
@ -8548,7 +8553,7 @@
|
|||
},
|
||||
"locate-path": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz",
|
||||
"resolved": false,
|
||||
"integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
|
@ -8577,7 +8582,7 @@
|
|||
},
|
||||
"p-locate": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz",
|
||||
"resolved": false,
|
||||
"integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
|
@ -8592,7 +8597,7 @@
|
|||
},
|
||||
"path-exists": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz",
|
||||
"resolved": false,
|
||||
"integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=",
|
||||
"dev": true
|
||||
},
|
||||
|
@ -8604,7 +8609,7 @@
|
|||
},
|
||||
"pkg-dir": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-3.0.0.tgz",
|
||||
"resolved": false,
|
||||
"integrity": "sha512-/E57AYkoeQ25qkxMj5PBOVgF8Kiu/h7cYS30Z5+R7WaiCCBfLq58ZI/dSeaEKb9WVJV5n/03QwrN3IeWIFllvw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
|
@ -8613,13 +8618,13 @@
|
|||
},
|
||||
"resolve-from": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz",
|
||||
"resolved": false,
|
||||
"integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==",
|
||||
"dev": true
|
||||
},
|
||||
"rimraf": {
|
||||
"version": "2.6.3",
|
||||
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz",
|
||||
"resolved": false,
|
||||
"integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
"lodash.debounce": "^4.0.8",
|
||||
"micro": "^9.3.4",
|
||||
"millify": "^3.1.0",
|
||||
"my-way": "^0.2.0",
|
||||
"react-debounce-render": "^5.0.0",
|
||||
"semver": "^6.1.1",
|
||||
"serve-handler": "^6.0.1",
|
||||
|
|
|
@ -1,84 +0,0 @@
|
|||
import tap from 'tap'
|
||||
import matchRoute from '../libs/match-route'
|
||||
|
||||
const runTest = (t, route, suite) => {
|
||||
// @ts-ignore
|
||||
Object.entries(suite).forEach(([url, result]) => {
|
||||
t.strictSame(
|
||||
matchRoute(route, url),
|
||||
result,
|
||||
`test match ${url}`
|
||||
)
|
||||
})
|
||||
t.end()
|
||||
}
|
||||
|
||||
const testRouteSimple = '/user/:id<\\d+>'
|
||||
tap.test(testRouteSimple, t => {
|
||||
const suite = {
|
||||
'/user/eiyo': null,
|
||||
'/user/123': { id: '123' },
|
||||
'/user/123/': { id: '123' }
|
||||
}
|
||||
runTest(t, testRouteSimple, suite)
|
||||
})
|
||||
|
||||
const testRouteMultiRegex = '/user/:id<\\d+>/:status?<active|inactive>'
|
||||
tap.test(testRouteMultiRegex, t => {
|
||||
const suite = {
|
||||
'/user/eiyo': null,
|
||||
'/user/123': { id: '123' },
|
||||
'/user/123/active': { id: '123', status: 'active'},
|
||||
'/user/123/eiyo': null
|
||||
}
|
||||
runTest(t, testRouteMultiRegex, suite)
|
||||
})
|
||||
|
||||
const testRoutePlusSegment = '/david/:topic/:path+'
|
||||
tap.test(testRoutePlusSegment, t => {
|
||||
const suite = {
|
||||
'/david/dep': null,
|
||||
'/david/dep/packages/babel-cli': {
|
||||
topic: 'dep',
|
||||
path: 'packages/babel-cli'
|
||||
},
|
||||
'/david/dep/https://eiyo.com': {
|
||||
topic: 'dep',
|
||||
path: 'https://eiyo.com'
|
||||
}
|
||||
}
|
||||
runTest(t, testRoutePlusSegment, suite)
|
||||
})
|
||||
|
||||
const testRouteOptionalSegment= '/github/:topic<stars|forks>/:owner/:repo/:chanel?/:more?'
|
||||
tap.test(testRouteOptionalSegment, t => {
|
||||
const suite = {
|
||||
'/github/stars/amio/': null,
|
||||
'/github/eiyou/amio/badgen': null,
|
||||
'/github/stars/amio/badgen': {
|
||||
topic: 'stars',
|
||||
owner: 'amio',
|
||||
repo: 'badgen'
|
||||
},
|
||||
'/github/stars/amio/badgen/master': {
|
||||
topic: 'stars',
|
||||
owner: 'amio',
|
||||
repo: 'badgen',
|
||||
chanel: 'master'
|
||||
},
|
||||
'/github/stars/amio/badgen/master/': {
|
||||
topic: 'stars',
|
||||
owner: 'amio',
|
||||
repo: 'badgen',
|
||||
chanel: 'master'
|
||||
},
|
||||
'/github/stars/amio/badgen/master/more': {
|
||||
topic: 'stars',
|
||||
owner: 'amio',
|
||||
repo: 'badgen',
|
||||
chanel: 'master',
|
||||
more: 'more'
|
||||
},
|
||||
}
|
||||
runTest(t, testRouteOptionalSegment, suite)
|
||||
})
|
Ładowanie…
Reference in New Issue