UNPKG

kubo-rpc-client-esm-cjs

Version:
52 lines 1.94 kB
"use strict"; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.toUrlSearchParams = void 0; const mode_to_string_js_1 = require("./mode-to-string.js"); const parse_mtime_js_1 = require("../lib/parse-mtime.js"); /** * @param {*} params * @returns {URLSearchParams} */ function toUrlSearchParams(_a = {}) { var { arg, searchParams, hashAlg, mtime, mode } = _a, options = __rest(_a, ["arg", "searchParams", "hashAlg", "mtime", "mode"]); if (searchParams) { options = Object.assign(Object.assign({}, options), searchParams); } if (hashAlg) { options.hash = hashAlg; } if (mtime != null) { mtime = (0, parse_mtime_js_1.parseMtime)(mtime); options.mtime = mtime.secs; options.mtimeNsecs = mtime.nsecs; } if (mode != null) { options.mode = (0, mode_to_string_js_1.modeToString)(mode); } if (options.timeout && !isNaN(options.timeout)) { // server API expects timeouts as strings options.timeout = `${options.timeout}ms`; } if (arg === undefined || arg === null) { arg = []; } else if (!Array.isArray(arg)) { arg = [arg]; } const urlSearchParams = new URLSearchParams(options); arg.forEach((/** @type {any} */ arg) => urlSearchParams.append('arg', arg)); return urlSearchParams; } exports.toUrlSearchParams = toUrlSearchParams; //# sourceMappingURL=to-url-search-params.js.map