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2pHLFFBQUEsYUFBYSxHQUFHLElBQUEscUJBQWEsRUFBQyxDQUFDLE9BQW9DLEVBQUUsRUFBRSxDQUFDLElBQUEsa0NBQWlCLEVBQUMsSUFBQSxjQUFNLEdBQUUsRUFBRSxPQUFPLENBQUMsQ0FBQyxDQUFBO0FBQzdHLFFBQUEsUUFBUSxHQUFHLElBQUEscUJBQWEsRUFBQyxDQUFDLE9BQTJELEVBQUUsRUFBRSxDQUFDLElBQUEsNkJBQVksRUFBQyxJQUFBLGNBQU0sR0FBRSxFQUFFLE9BQU8sQ0FBQyxDQUFDLENBQUE7QUFFdkksd0JBQXdCO0FBQ3hCLG1DQUFtQyJ9 |
@@ -6,4 +6,4 @@ /// <reference types="node" resolution-mode="require"/> | ||
bodyLimit: number; | ||
urlEncodedParser?(search: string): any; | ||
queryParser?(search: string): any; | ||
simplifyUrlEncodedBody?: boolean; | ||
simplifyQuery?: boolean; | ||
} | ||
@@ -10,0 +10,0 @@ export declare function setBufferBodyDefaultOptions(options: Partial<BufferBodyOptions>): void; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -6,5 +9,3 @@ exports.queryFromReq = exports.urlFromReq = exports.urlEncodedFromReq = exports.textFromReq = exports.rawFromReq = exports.jsonFromReq = exports.bufferFromReq = exports.setBufferBodyDefaultOptions = void 0; | ||
const contentType_js_1 = require("./contentType.js"); | ||
function defaultQueryParser(search) { | ||
return Object.fromEntries(new URLSearchParams(search)); // support both leading ? and not | ||
} | ||
const qs_1 = __importDefault(require("qs")); | ||
let bodyDefaultOptions = { bodyLimit: 100 << 10 }; // 100kb | ||
@@ -90,3 +91,5 @@ function setBufferBodyDefaultOptions(options) { | ||
if (buffer) { | ||
return (bodyDefaultOptions.urlEncodedParser ?? options?.urlEncodedParser ?? defaultQueryParser)(buffer.toString(charset)); | ||
const str = buffer.toString(charset); | ||
const { simplifyUrlEncodedBody } = { ...bodyDefaultOptions, ...options }; | ||
return simplifyUrlEncodedBody ? Object.fromEntries(new URLSearchParams(str)) : qs_1.default.parse(str); | ||
} | ||
@@ -100,5 +103,7 @@ } | ||
function queryFromReq(req, options) { | ||
return (bodyDefaultOptions.urlEncodedParser ?? options?.urlEncodedParser ?? defaultQueryParser)(urlFromReq(req).searchParams.toString()); | ||
const query = urlFromReq(req).searchParams.toString(); | ||
const { simplifyQuery } = { ...bodyDefaultOptions, ...options }; | ||
return simplifyQuery ? Object.fromEntries(new URLSearchParams(query)) : qs_1.default.parse(query); | ||
} | ||
exports.queryFromReq = queryFromReq; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYm9keUhlbHBlcnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvYm9keUhlbHBlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQ0EsMkNBQXdEO0FBQ3hELHFEQUFpRDtBQVFqRCxTQUFTLGtCQUFrQixDQUFDLE1BQWM7SUFDekMsT0FBTyxNQUFNLENBQUMsV0FBVyxDQUFDLElBQUksZUFBZSxDQUFDLE1BQU0sQ0FBQyxDQUFDLENBQUEsQ0FBQyxpQ0FBaUM7QUFDekYsQ0FBQztBQUVELElBQUksa0JBQWtCLEdBQXNCLEVBQUMsU0FBUyxFQUFFLEdBQUcsSUFBSSxFQUFFLEVBQUMsQ0FBQSxDQUFDLFFBQVE7QUFDM0UsU0FBZ0IsMkJBQTJCLENBQUMsT0FBbUM7SUFDOUUsa0JBQWtCLEdBQUcsRUFBQyxHQUFHLGtCQUFrQixFQUFFLEdBQUcsT0FBTyxFQUFDLENBQUE7QUFDekQsQ0FBQztBQUZELGtFQUVDO0FBRU0sS0FBSyxVQUFVLGFBQWEsQ0FBQyxHQUFvQixFQUFFLE9BQW9DO0lBQzdGLE1BQU0sRUFBQyxTQUFTLEVBQ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FLEdBQUcsT0FBTyxFQUFDLENBQUE7SUFDM0QsT0FBTyxhQUFhLENBQUMsQ0FBQyxDQUFDLE1BQU0sQ0FBQyxXQUFXLENBQUMsSUFBSSxlQUFlLENBQUMsS0FBSyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsWUFBRSxDQUFDLEtBQUssQ0FBQyxLQUFLLENBQUMsQ0FBQTtBQUN4RixDQUFDO0FBSkQsb0NBSUMifQ== |
@@ -0,9 +1,20 @@ | ||
import type { Key } from 'path-to-regexp'; | ||
import { Chainable } from './dx.js'; | ||
import 'urlpattern-polyfill'; | ||
interface URLPatternOptions { | ||
interface RegexpToPathOptions { | ||
end?: boolean; | ||
strict?: boolean; | ||
sensitive?: boolean; | ||
start?: boolean; | ||
delimiter?: string; | ||
endsWith?: string; | ||
encode?(value: string): string; | ||
prefixes?: string; | ||
} | ||
export declare function matchPattern<Params extends Record<Key['name'], string>>(pathname: string, pattern: string, options?: RegexpToPathOptions): { | ||
matched: any; | ||
params: any; | ||
} | undefined; | ||
interface RouteContext { | ||
matched: URLPatternResult; | ||
params: Record<string, string>; | ||
matched: string; | ||
params: Record<Key['name'], string>; | ||
next(): any; | ||
@@ -17,3 +28,3 @@ } | ||
} | ||
interface RouterOptions extends URLPatternOptions { | ||
interface RouterOptions extends RegexpToPathOptions { | ||
prefix?: string; | ||
@@ -20,0 +31,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.router = void 0; | ||
exports.router = exports.matchPattern = void 0; | ||
const path_to_regexp_1 = require("path-to-regexp"); | ||
const dx_js_1 = require("./dx.js"); | ||
require("urlpattern-polyfill"); | ||
const bodyHelpers_js_1 = require("./bodyHelpers.js"); | ||
// '' matches nothing | ||
// '/' matches both https://example.com and https://example.com/ | ||
// '/foo' matches https://example.com/foo but not https://example.com/foo/ | ||
// '/foo/' matches https://example.com/foo/ but not https://example.com/foo | ||
const cache = {}; | ||
const cacheLimit = 10000; | ||
let cacheCount = 0; | ||
function compilePath(pattern, options) { | ||
const cacheKey = JSON.stringify(options); | ||
const pathCache = cache[cacheKey] || (cache[cacheKey] = {}); | ||
if (pathCache[pattern]) | ||
return pathCache[pattern]; | ||
const keys = []; | ||
const regexp = (0, path_to_regexp_1.pathToRegexp)(pattern, keys, options); | ||
const result = { | ||
regexp, | ||
keys | ||
}; | ||
if (cacheCount < cacheLimit) { | ||
pathCache[pattern] = result; | ||
cacheCount++; | ||
} | ||
return result; | ||
} | ||
function matchPattern(pathname, pattern, options) { | ||
const matched = new URLPattern({ pathname: pattern }, undefined, options).exec({ pathname }); | ||
if (!matched) | ||
options = { ...options }; | ||
options.end ??= true; | ||
options.strict ??= false; | ||
options.sensitive ??= false; | ||
options.start ??= true; | ||
if (!pattern && pattern !== '') | ||
return; | ||
const { regexp, keys } = compilePath(pattern, options); | ||
const match = regexp.exec(pathname); | ||
if (!match) | ||
return; | ||
const [matched, ...values] = match; | ||
return { | ||
matched, | ||
params: matched.pathname.groups | ||
matched, // the matched portion of the URL | ||
params: keys.reduce((acc, key, index) => { | ||
acc[key.name] = values[index]; | ||
return acc; | ||
}, {}) | ||
}; | ||
} | ||
exports.matchPattern = matchPattern; | ||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods | ||
@@ -55,2 +84,2 @@ const allMethods = [ | ||
exports.router[method] = exports.router.method.bind(exports.router, method); | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicm91dGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3JvdXRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSxtQ0FBeUM7QUFFekMsK0JBQTRCO0FBQzVCLHFEQUEyQztBQU8zQyxxQkFBcUI7QUFDckIsZ0VBQWdFO0FBQ2hFLDBFQUEwRTtBQUMxRSwyRUFBMkU7QUFDM0UsU0FBUyxZQUFZLENBQ3BCLFFBQWdCLEVBQ2hC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Q0FBQyxhQUFhLENBQUMsTUFBTSxFQUFFLEVBQUUsT0FBTyxDQUFDLENBQUMsQ0FBQTtBQUNsSCxNQUFNLENBQUMsTUFBTSxPQUFPLEdBQUcsYUFBYSxDQUFDLENBQUMsT0FBb0MsRUFBRSxFQUFFLENBQUMsV0FBVyxDQUFDLE1BQU0sRUFBRSxFQUFFLE9BQU8sQ0FBQyxDQUFDLENBQUE7QUFDOUcsTUFBTSxDQUFDLE1BQU0sTUFBTSxHQUFHLGFBQWEsQ0FBQyxDQUFDLE9BQW9DLEVBQUUsRUFBRSxDQUFDLFVBQVUsQ0FBQyxNQUFNLEVBQUUsRUFBRSxPQUFPLENBQUMsQ0FBQyxDQUFBO0FBQzVHLE1BQU0sQ0FBQyxNQUFNLE9BQU8sR0FBRyxhQUFhLENBQUMsQ0FBQyxPQUFvQyxFQUFFLEVBQUUsQ0FBQyxXQUFXLENBQUMsTUFBTSxFQUFFLEVBQUUsT0FBTyxDQUFDLENBQUMsQ0FBQTtBQUM5RyxNQUFNLENBQUMsTUFBTSxhQUFhLEdBQUcsYUFBYSxDQUFDLENBQUMsT0FBb0MsRUFBRSxFQUFFLENBQUMsaUJBQWlCLENBQUMsTUFBTSxFQUFFLEVBQUUsT0FBTyxDQUFDLENBQUMsQ0FBQTtBQUMxSCxNQUFNLENBQUMsTUFBTSxRQUFRLEdBQUcsYUFBYSxDQUFDLENBQUMsT0FBMkQsRUFBRSxFQUFFLENBQUMsWUFBWSxDQUFDLE1BQU0sRUFBRSxFQUFFLE9BQU8sQ0FBQyxDQUFDLENBQUE7QUFFdkksd0JBQXdCO0FBQ3hCLG1DQUFtQyJ9 |
@@ -6,4 +6,4 @@ /// <reference types="node" resolution-mode="require"/> | ||
bodyLimit: number; | ||
urlEncodedParser?(search: string): any; | ||
queryParser?(search: string): any; | ||
simplifyUrlEncodedBody?: boolean; | ||
simplifyQuery?: boolean; | ||
} | ||
@@ -10,0 +10,0 @@ export declare function setBufferBodyDefaultOptions(options: Partial<BufferBodyOptions>): void; |
import { getContentStream, readStream } from './stream.js'; | ||
import { parseContentType } from './contentType.js'; | ||
function defaultQueryParser(search) { | ||
return Object.fromEntries(new URLSearchParams(search)); // support both leading ? and not | ||
} | ||
import qs from 'qs'; | ||
let bodyDefaultOptions = { bodyLimit: 100 << 10 }; // 100kb | ||
@@ -81,3 +79,5 @@ export function setBufferBodyDefaultOptions(options) { | ||
if (buffer) { | ||
return (bodyDefaultOptions.urlEncodedParser ?? options?.urlEncodedParser ?? defaultQueryParser)(buffer.toString(charset)); | ||
const str = buffer.toString(charset); | ||
const { simplifyUrlEncodedBody } = { ...bodyDefaultOptions, ...options }; | ||
return simplifyUrlEncodedBody ? Object.fromEntries(new URLSearchParams(str)) : qs.parse(str); | ||
} | ||
@@ -89,4 +89,6 @@ } | ||
export function queryFromReq(req, options) { | ||
return (bodyDefaultOptions.urlEncodedParser ?? options?.urlEncodedParser ?? defaultQueryParser)(urlFromReq(req).searchParams.toString()); | ||
const query = urlFromReq(req).searchParams.toString(); | ||
const { simplifyQuery } = { ...bodyDefaultOptions, ...options }; | ||
return simplifyQuery ? Object.fromEntries(new URLSearchParams(query)) : qs.parse(query); | ||
} | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYm9keUhlbHBlcnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvYm9keUhlbHBlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxFQUFDLGdCQUFnQixFQUFFLFVBQVUsRUFBQyxNQUFNLGFBQWEsQ0FBQTtBQUN4RCxPQUFPLEVBQUMsZ0JBQWdCLEVBQUMsTUFBTSxrQkFBa0IsQ0FBQTtBQVFqRCxTQUFTLGtCQUFrQixDQUFDLE1BQWM7SUFDekMsT0FBTyxNQUFNLENBQUMsV0FBVyxDQUFDLElBQUksZUFBZSxDQUFDLE1BQU0sQ0FBQyxDQUFDLENBQUEs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QUMsQ0FBQTtJQUM3RixDQUFDO0FBQ0YsQ0FBQztBQUVELE1BQU0sVUFBVSxVQUFVLENBQUMsR0FBb0I7SUFDOUMsT0FBTyxJQUFJLEdBQUcsQ0FBQyxHQUFHLENBQUMsR0FBRyxJQUFJLEVBQUUsRUFBRSxxQkFBcUIsQ0FBQyxDQUFBO0FBQ3JELENBQUM7QUFFRCxNQUFNLFVBQVUsWUFBWSxDQUFDLEdBQW9CLEVBQUUsT0FBb0M7SUFDdEYsTUFBTSxLQUFLLEdBQUcsVUFBVSxDQUFDLEdBQUcsQ0FBQyxDQUFDLFlBQVksQ0FBQyxRQUFRLEVBQUUsQ0FBQTtJQUNyRCxNQUFNLEVBQUMsYUFBYSxFQUFDLEdBQUcsRUFBQyxHQUFHLGtCQUFrQixFQUFFLEdBQUcsT0FBTyxFQUFDLENBQUE7SUFDM0QsT0FBTyxhQUFhLENBQUMsQ0FBQyxDQUFDLE1BQU0sQ0FBQyxXQUFXLENBQUMsSUFBSSxlQUFlLENBQUMsS0FBSyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsRUFBRSxDQUFDLEtBQUssQ0FBQyxLQUFLLENBQUMsQ0FBQTtBQUN4RixDQUFDIn0= |
@@ -0,9 +1,20 @@ | ||
import type { Key } from 'path-to-regexp'; | ||
import { Chainable } from './dx.js'; | ||
import 'urlpattern-polyfill'; | ||
interface URLPatternOptions { | ||
interface RegexpToPathOptions { | ||
end?: boolean; | ||
strict?: boolean; | ||
sensitive?: boolean; | ||
start?: boolean; | ||
delimiter?: string; | ||
endsWith?: string; | ||
encode?(value: string): string; | ||
prefixes?: string; | ||
} | ||
export declare function matchPattern<Params extends Record<Key['name'], string>>(pathname: string, pattern: string, options?: RegexpToPathOptions): { | ||
matched: any; | ||
params: any; | ||
} | undefined; | ||
interface RouteContext { | ||
matched: URLPatternResult; | ||
params: Record<string, string>; | ||
matched: string; | ||
params: Record<Key['name'], string>; | ||
next(): any; | ||
@@ -17,3 +28,3 @@ } | ||
} | ||
interface RouterOptions extends URLPatternOptions { | ||
interface RouterOptions extends RegexpToPathOptions { | ||
prefix?: string; | ||
@@ -20,0 +31,0 @@ } |
@@ -0,15 +1,43 @@ | ||
import { pathToRegexp } from 'path-to-regexp'; | ||
import { getReq } from './dx.js'; | ||
import 'urlpattern-polyfill'; | ||
import { urlFromReq } from './bodyHelpers.js'; | ||
// '' matches nothing | ||
// '/' matches both https://example.com and https://example.com/ | ||
// '/foo' matches https://example.com/foo but not https://example.com/foo/ | ||
// '/foo/' matches https://example.com/foo/ but not https://example.com/foo | ||
function matchPattern(pathname, pattern, options) { | ||
const matched = new URLPattern({ pathname: pattern }, undefined, options).exec({ pathname }); | ||
if (!matched) | ||
const cache = {}; | ||
const cacheLimit = 10000; | ||
let cacheCount = 0; | ||
function compilePath(pattern, options) { | ||
const cacheKey = JSON.stringify(options); | ||
const pathCache = cache[cacheKey] || (cache[cacheKey] = {}); | ||
if (pathCache[pattern]) | ||
return pathCache[pattern]; | ||
const keys = []; | ||
const regexp = pathToRegexp(pattern, keys, options); | ||
const result = { | ||
regexp, | ||
keys | ||
}; | ||
if (cacheCount < cacheLimit) { | ||
pathCache[pattern] = result; | ||
cacheCount++; | ||
} | ||
return result; | ||
} | ||
export function matchPattern(pathname, pattern, options) { | ||
options = { ...options }; | ||
options.end ??= true; | ||
options.strict ??= false; | ||
options.sensitive ??= false; | ||
options.start ??= true; | ||
if (!pattern && pattern !== '') | ||
return; | ||
const { regexp, keys } = compilePath(pattern, options); | ||
const match = regexp.exec(pathname); | ||
if (!match) | ||
return; | ||
const [matched, ...values] = match; | ||
return { | ||
matched, | ||
params: matched.pathname.groups | ||
matched, // the matched portion of the URL | ||
params: keys.reduce((acc, key, index) => { | ||
acc[key.name] = values[index]; | ||
return acc; | ||
}, {}) | ||
}; | ||
@@ -52,2 +80,2 @@ } | ||
router[method] = router.method.bind(router, method); | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicm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xNQUFNLENBQUMsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUFDLENBQUMsQ0FBQyxFQUFFLE1BQU0sQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFBO0lBQzVELENBQUM7SUFDRCxHQUFHLENBQUMsR0FBRyxNQUFNO1FBQ1osT0FBTyxPQUFPLE1BQU0sQ0FBQyxDQUFDLENBQUMsS0FBSyxRQUFRO1lBQ25DLENBQUMsQ0FBQyxVQUFVLENBQUMsU0FBUyxFQUFFLENBQUMsQ0FBQyxNQUFNLENBQUMsQ0FBQyxDQUFDLEVBQUUsTUFBTSxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsRUFBRSxNQUFNLENBQUMsQ0FBQyxDQUFDLENBQUM7WUFDNUQsQ0FBQyxDQUFDLFVBQVUsQ0FBQyxTQUFTLEVBQUUsTUFBTSxDQUFDLE9BQU8sQ0FBQyxNQUFNLENBQUMsQ0FBQyxDQUFDLENBQUMsRUFBRSxNQUFNLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQTtJQUMvRCxDQUFDO0NBQ0QsQ0FBQTtBQUVELEtBQUssTUFBTSxNQUFNLElBQUksVUFBVTtJQUFFLE1BQU0sQ0FBQyxNQUFNLENBQUMsR0FBRyxNQUFNLENBQUMsTUFBTSxDQUFDLElBQUksQ0FBQyxNQUFNLEVBQUUsTUFBTSxDQUFDLENBQUEifQ== |
{ | ||
"name": "dx-server", | ||
"version": "0.5.9", | ||
"version": "0.5.10", | ||
"main": "./cjs/index.js", | ||
@@ -32,3 +32,5 @@ "homepage": "https://github.com/tranvansang/dx-server", | ||
"devDependencies": { | ||
"@types/node": "^20.12.8", | ||
"@types/node": "^20.12.7", | ||
"@types/path-to-regexp": "^1.7.0", | ||
"@types/qs": "^6.9.15", | ||
"@types/send": "^0.17.4", | ||
@@ -39,5 +41,6 @@ "typescript": "^5.4.5" | ||
"jdefer": "^0.0.14", | ||
"send": "^0.18.0", | ||
"urlpattern-polyfill": "^10.0.0" | ||
"path-to-regexp": "^6.2.2", | ||
"qs": "^6.12.1", | ||
"send": "^0.18.0" | ||
} | ||
} |
@@ -122,3 +122,3 @@ # dx-server - modern, unopinionated, and satisfactory server | ||
authContext.chain(), // chain context will set the context value to authContext.value in every request | ||
router.post('/api/*', async ({next}) => {// example of catching error for all /api/* routes | ||
router.post('/api', async ({next}) => {// example of catching error for all /api/* routes | ||
try { | ||
@@ -139,3 +139,3 @@ await next() | ||
} | ||
}), | ||
}, {end: false}), // note: {end: false} is required to match all /api/* routes. This option is passed directly to path-to-regexp | ||
router.post({ | ||
@@ -294,21 +294,23 @@ '/api/sample-public-api'() { // sample POST router | ||
```typescript | ||
interface RouterOptions { | ||
interface RegexpToPathOptions { | ||
end?: boolean // default true. match till end of string | ||
strict?: boolean // default false. disallow trailing delimiter | ||
sensitive?: boolean // default false | ||
start?: boolean // default true. match from beginning of string | ||
delimiter?: string // default '/#?'. delimiter for segments | ||
endsWith?: string // default undefined. optional character that matches at the end of the string | ||
encode?(value: string): string // default x => x. encode strings before inserting into RegExp | ||
prefixes?: string // default `./`. List of characters to automatically consider prefixes when parsing. | ||
} | ||
interface RouterOptions extends RegexpToPathOptions { | ||
prefix?: string | ||
sensitive?: string | ||
} | ||
``` | ||
`options: RegexpToPathOptions` (except `prefix` key) is directly passed to [path-to-regexp](https://www.npmjs.com/package/path-to-regexp) package. | ||
Patterns are matched using [URLPattern](https://developer.mozilla.org/en-US/docs/Web/API/URLPattern). | ||
This does not always match the same as ExpressJS. | ||
For example, to match any path prefixed with `/api/`, use `/api/*`. | ||
Note the following: | ||
- `''` matches nothing. | ||
- `'/'` matches both https://example.com and https://example.com/. | ||
- `'/foo'` matches https://example.com/foo but not https://example.com/foo/. | ||
- `'/foo/'` matches https://example.com/foo/ but not https://example.com/foo. | ||
`Route` is defined as follows: | ||
```typescript | ||
interface RouteContext { | ||
matched: URLPatternResult // result returned from URLPattern.exec() | ||
matched: string | ||
params: Record<string, string> | ||
@@ -315,0 +317,0 @@ next(): any |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
178653
2134
351
4
5
+ Addedpath-to-regexp@^6.2.2
+ Addedqs@^6.12.1
+ Addedcall-bind-apply-helpers@1.0.1(transitive)
+ Addedcall-bound@1.0.3(transitive)
+ Addeddunder-proto@1.0.1(transitive)
+ Addedes-define-property@1.0.1(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.0.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.6(transitive)
+ Addedgopd@1.2.0(transitive)
+ Addedhas-symbols@1.1.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedmath-intrinsics@1.1.0(transitive)
+ Addedobject-inspect@1.13.3(transitive)
+ Addedpath-to-regexp@6.3.0(transitive)
+ Addedqs@6.13.1(transitive)
+ Addedside-channel@1.1.0(transitive)
+ Addedside-channel-list@1.0.0(transitive)
+ Addedside-channel-map@1.0.1(transitive)
+ Addedside-channel-weakmap@1.0.2(transitive)
- Removedurlpattern-polyfill@^10.0.0
- Removedurlpattern-polyfill@10.0.0(transitive)