vtils
Version:
一个面向业务的 JavaScript/TypeScript 实用程序库。
28 lines (27 loc) • 1.03 kB
JavaScript
exports.__esModule = true;
exports.createUrlQueryString = createUrlQueryString;
/**
* 创建 url 查询字符串。
*
* @param parameters 查询参数
* @param options 选项
* @returns 返回 url 查询字符串
* @example
* ```typescript
* createUrlQueryString({ x: 1, y: 'z' }) // => x=1&y=z
* ```
*/
function createUrlQueryString(parameters, options) {
var _options$pairSeparato, _options$partSeparato;
var pairSeparator = (_options$pairSeparato = options == null ? void 0 : options.pairSeparator) != null ? _options$pairSeparato : '=';
var partSeparator = (_options$partSeparato = options == null ? void 0 : options.partSeparator) != null ? _options$partSeparato : '&';
var parts = [];
for (var _i = 0, _Object$keys = Object.keys(parameters); _i < _Object$keys.length; _i++) {
var key = _Object$keys[_i];
if (parameters[key] != null) {
parts.push("" + encodeURIComponent(key) + pairSeparator + encodeURIComponent(parameters[key]));
}
}
return parts.join(partSeparator);
}
;