@ryanuo/utils
Version:
提供多种实用工具函数,涵盖算法、浏览器操作、网络请求等多个领域
26 lines (25 loc) • 859 B
TypeScript
/**
* Parse URL query parameters
* @category URL
* @example
* ```ts twoslash
* import { getUrlParams } from '@ryanuo/utils'
* getUrlParams() // { a: '1', b: '2' }
* ```
* @param url Optional, defaults to the current page URL
* @returns An object of parsed parameters
*/
export declare function getUrlParams(url?: string): Record<string, string>;
/**
* Convert an object to URL parameters
* @category URL
* @example
* ```ts twoslash
* import { getUrlParamsString } from '@ryanuo/utils'
* getUrlParamsString({ a: '1', b: '2' }) // '?a=1&b=2'
* getUrlParamsString({ a: '1', b: '2', c: '3' }) // '?a=1&b=2&c=3'
*```
* @param obj - The object to convert
* @param url - The URL to which parameters will be added, defaults to the current page URL
*/
export declare function getUrlParamsString(obj: Record<string, string>, url?: string): string;