Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | 13x 13x 13x 13x 37x 36x 13x | import { AnyObject } from '../types'
export interface CreateUrlQueryStringOptions {
/**
* 键值内部的连接符。
*/
pairSeparator?: string
/**
* 各参数间的连接符。
*/
partSeparator?: string
}
/**
* 创建 url 查询字符串。
*
* @param parameters 查询参数
* @param options 选项
* @returns 返回 url 查询字符串
* @example
* ```typescript
* createUrlQueryString({ x: 1, y: 'z' }) // => x=1&y=z
* ```
*/
export function createUrlQueryString(
parameters: AnyObject,
options?: CreateUrlQueryStringOptions,
) {
const pairSeparator = options?.pairSeparator ?? '='
const partSeparator = options?.partSeparator ?? '&'
const parts: string[] = []
for (const key of Object.keys(parameters)) {
if (parameters[key] != null) {
parts.push(
`${encodeURIComponent(key)}${pairSeparator}${encodeURIComponent(
parameters[key],
)}`,
)
}
}
return parts.join(partSeparator)
}
|