UNPKG

qw-utils

Version:

qw Utils package

36 lines (35 loc) 926 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.urlUtils = void 0; /** * 处理连接 */ class urlUtils { constructor() { } /** * 修改链接的参数值 * @param url 连接 * @param arg 要替换的参数 * @param arg_val 要替换的值 * @returns */ changeURLArg(url, arg, arg_val) { const pattern = arg + '=([^&]*)'; const replaceText = arg + '=' + arg_val; if (url.match(pattern)) { let tmp = '/(' + arg + '=)([^&]*)/gi'; tmp = url.replace(eval(tmp), replaceText); window.history.pushState('', '', tmp); return tmp; } else { if (url.match('[?]')) { return url + '&' + replaceText; } else { return url + '?' + replaceText; } } } } exports.urlUtils = urlUtils;