UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

85 lines (84 loc) 1.97 kB
/** * url参数变对象 * @param {string} url 输入URL * @returns {Object} search对象 * * @example * * const res = getQueryObj('https://igame.qq.com?name=mike&age=18&feel=cold&from=China'); * * console.log(res); * { * name: 'mike', * age: '18', * feel: "cold", * from: 'China', * } * */ export declare function getQueryObj(url: string): Record<string, string>; /** * 组装`url`参数,将search参数添加在后面 * @param {string} url 输入URL * @param {Object} queryObj search对象 * @returns {string} 组装后的url * * @example * composeUrlQuery('https://baidu.com', { * name: 'mike', * feel: 'cold', * age: '18', * from: 'test', * }); * // https://baidu.com?name=mike&feel=cold&age=18&from=test * * composeUrlQuery('https://baidu.com?gender=male', { * name: 'mike', * feel: 'cold', * age: '18', * from: 'test', * }); * // https://baidu.com?gender=male&name=mike&feel=cold&age=18&from=test * */ export declare function composeUrlQuery(url: string, queryObj: object): string; /** * 将对象字符串化 * @param {object} obj 输入对象 * @returns {string} 字符串 * @example * * encodeUrlParam({a: 1}) * * // '%7B%22a%22%3A1%7D' * */ export declare function encodeUrlParam(obj: object): string; /** * 将字符串解码,与`encodeUrlParam`相对 * @param {string} obj 输入字符串 * @returns {object} 对象 * @example * * decodeUrlParam('%7B%22a%22%3A1%7D') * * // { a: 1 } * */ export declare function decodeUrlParam(str: string): object; /** * 获取 Url 参数 * @param {string} paraName 参数 key * @param {string} search url search 部分 * @returns paraValue * * @example * ```ts * getUrlPara('gender', '?gender=male&name=mike&feel=cold&age=18&from=test') * // male * * getUrlPara('age', '?gender=male&name=mike&feel=cold&age=18&from=test') * // 18 * ``` */ export declare function getUrlPara(paraName: string, search?: string): string;