Spaces:
Sleeping
Sleeping
File size: 582 Bytes
b022cb9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import queryString from 'query-string'
export function getParam<T>(name: string, defaultValue: T): T {
try {
const params = queryString.parseUrl(
typeof window !== "undefined" ? (window.location.href || "") : ""
)
const stringValue = params.query[name]?.toString() || `${defaultValue || ""}`
if (typeof defaultValue === "number") {
return Number(stringValue) as T
} else if (typeof defaultValue === "boolean") {
return Boolean(stringValue) as T
} else {
return stringValue as T
}
} catch (err) {
return defaultValue
}
} |