UNPKG

ipfs-http-client

Version:
40 lines (35 loc) 1.03 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var modeToString = require('./mode-to-string.js'); var parseMtime = require('./parse-mtime.js'); function toUrlSearchParams({arg, searchParams, hashAlg, mtime, mode, ...options} = {}) { if (searchParams) { options = { ...options, ...searchParams }; } if (hashAlg) { options.hash = hashAlg; } if (mtime != null) { mtime = parseMtime.parseMtime(mtime); options.mtime = mtime.secs; options.mtimeNsecs = mtime.nsecs; } if (mode != null) { options.mode = modeToString.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; } exports.toUrlSearchParams = toUrlSearchParams;