UNPKG

@szzbmy/lowcode-cli

Version:

🐇 lowcode-cli is an efficient cli tool for Rabbitpre plugin component secondary development. ❤️

46 lines (45 loc) 1.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.stringifyQuery = void 0; const encodeReserveRE = /[!'()*]/g; const encodeReserveReplacer = (c) => `%${c.charCodeAt(0).toString(16)}`; const commaRE = /%2C/g; const encode = (str) => encodeURIComponent(str) .replace(encodeReserveRE, encodeReserveReplacer) .replace(commaRE, ','); function stringifyQuery(obj = null) { const res = typeof obj === 'string' ? obj : obj ? Object.keys(obj) .map((key) => { const val = obj[key]; if (typeof val === undefined) { return ''; } if (val === null) { return encode(key); } if (Array.isArray(val)) { const result = []; val.forEach(val2 => { if (val2 === undefined) { return; } if (val2 === null) { result.push(encode(key)); } else { result.push(`${encode(key)}=${encode(val2)}`); } }); return result.join('&'); } return `${encode(key)}=${encode(val)}`; }) .filter(x => x.length > 0) .join('&') : null; return res ? `?${res}` : ''; } exports.stringifyQuery = stringifyQuery;