blessing-skin-server/resources/assets/src/scripts/utils.ts
2020-02-11 16:40:26 +08:00

15 lines
455 B
TypeScript

export function queryString(key: string, defaultValue: string = ''): string {
const result = new RegExp(`[?&]${key}=([^&]+)`, 'i').exec(location.search)
if (result === null || result.length < 1) {
return defaultValue
}
return result[1]
}
export function queryStringify(params: { [key: string]: string }): string {
return Object.keys(params)
.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`)
.join('&')
}