ipfs-http-client
Version:
A client library for the IPFS HTTP API
32 lines • 890 B
JavaScript
import { modeToString } from './mode-to-string.js';
import { parseMtime } from '../lib/parse-mtime.js';
export function toUrlSearchParams({arg, searchParams, hashAlg, mtime, mode, ...options} = {}) {
if (searchParams) {
options = {
...options,
...searchParams
};
}
if (hashAlg) {
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 (options.timeout && !isNaN(options.timeout)) {
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(arg => urlSearchParams.append('arg', arg));
return urlSearchParams;
}