UNPKG

@agility/management-sdk

Version:
28 lines (27 loc) 1.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.buildQueryString = buildQueryString; /** * Builds a query string from an object of parameters. * Only includes parameters that have actual values (skips undefined, null, and empty strings). * * @param params - Object containing key-value pairs for query parameters * @returns Query string starting with '?' if parameters exist, empty string otherwise */ function buildQueryString(params) { var queryParams = []; for (var _i = 0, _a = Object.entries(params); _i < _a.length; _i++) { var _b = _a[_i], key = _b[0], value = _b[1]; // Skip undefined and null values if (value === undefined || value === null) { continue; } // Skip empty strings if (typeof value === 'string' && value === '') { continue; } // Include all other values (numbers including 0, booleans including false, non-empty strings) queryParams.push("".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value))); } return queryParams.length > 0 ? "?".concat(queryParams.join('&')) : ''; }