append-queries-to-url.js

import { default as stringify } from './stringify';
/**
 * 向URL中追加query
 *
 * @private
 * @param url
 * @param query query字符串,如"a=12"
 */
function appendQueryToUrl(url, query) {
    if (!url || !query) {
        return url;
    }
    var symbol = url && url.indexOf('?') > -1 ? '&' : '?';
    var len = url.length;
    if (url[len - 1] === '?' || url[len - 1] === '&') {
        symbol = '';
    }
    var result = "".concat(url).concat(symbol).concat(query);
    return result;
}
/**
 * 向url中添加query
 * 备注: key/value均会进行一次encodeURIComponent
 * @param {string} url
 * @param {object} params kv键值对,如: {chInf: 'abc'};
 *
 * @example
 *
 * import { appendQueriesToUrl } from '@jairwinl/utils/esm/appendQueriesToUrl';
 *
 * appendQueriesToUrl('https://example.com', { a: 'b', c: 'd' })
 *
 * // => 'https://example.com?a=b&c=d'
 */
function appendQueriesToUrl(url, params) {
    if (params === void 0) { params = {}; }
    if (!url || !params) {
        return url;
    }
    return appendQueryToUrl(url, stringify(params));
}
export default appendQueriesToUrl;
//# sourceMappingURL=append-queries-to-url.js.map