swc/bundler/tests/.cache/deno/df5c5594b20da171a7077101b23b0d5e8e3cdc0a.ts
강동윤 f8aa0509ce
fix(bundler): Fix stack overflow (#2080)
swc_bundler:
 - Prevent infinite recursions. (#1963)
2021-08-15 02:37:31 +00:00

33 lines
817 B
TypeScript

// Loaded from https://deno.land/x/tinyhttp@0.1.18/utils/parseUrl.ts
import { parse } from 'https://deno.land/std@0.101.0/node/querystring.ts'
type Regex = {
keys: string[] | boolean
pattern: RegExp
}
export const getURLParams = ({ pattern, keys }: Regex, reqUrl = '/'): URLParams => {
const matches = pattern.exec(reqUrl)
const params: Record<string, string> = {}
if (matches && typeof keys !== 'boolean') for (let i = 0; i < keys.length; i++) params[keys[i]] = matches[i + 1]
return params
}
export type URLParams = {
[key: string]: string
}
export const getPathname = (u: string) => {
const end = u.indexOf('?')
return u.slice(0, end === -1 ? u.length : end)
}
export const getQueryParams = (url = '/'): { [key: string]: string[] | string } =>
parse(url.slice(url.indexOf('?') + 1))