UNPKG

kubo-rpc-client

Version:
44 lines 1.4 kB
import { parseMtime } from '../lib/files/utils.js'; import { modeToString } from './mode-to-string.js'; export function toUrlSearchParams({ arg, searchParams, hashAlg, mtime, mode, ...options } = {}) { if (searchParams != null) { options = { ...options, ...searchParams }; } if (hashAlg != null) { options.hash = hashAlg; } if (mtime != null) { mtime = parseMtime(mtime); options.mtime = mtime.secs; options.mtimeNsecs = mtime.nsecs; } if (mode != null) { options.mode = modeToString(mode); } if (!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]; } // Filter out undefined and null values to avoid sending "undefined" or "null" as strings const filteredOptions = {}; for (const [key, value] of Object.entries(options)) { if (value !== undefined && value !== null) { filteredOptions[key] = value; } } const urlSearchParams = new URLSearchParams(filteredOptions); arg.forEach((arg) => { urlSearchParams.append('arg', arg); }); return urlSearchParams; } //# sourceMappingURL=to-url-search-params.js.map