build-url-ts
Version:
A small library that builds a URL given its components
3 lines (2 loc) • 1.84 kB
JavaScript
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).buildUrl={})}(this,function(e){"use strict";function o(e,r,c){var a=[];for(var n in e)!function(n){var t,o;Object.prototype.hasOwnProperty.call(e,n)&&void 0!==e[n]&&(Array.isArray(e[n])&&e[n].length?c?(o="order_desc"===c?e[n].length-1:0,e[n].forEach(function(e){switch(t=0!==e?e||"":0,c){case"array":a.push("".concat(n,"[]=").concat(encodeURIComponent(String(t).trim())));break;case"order_asc":a.push("".concat(n,"[").concat(o++,"]=").concat(encodeURIComponent(String(t).trim())));break;case"order_desc":a.push("".concat(n,"[").concat(o--,"]=").concat(encodeURIComponent(String(t).trim())));break;default:a.push("".concat(n,"=").concat(encodeURIComponent(String(t).trim())))}})):(t=e[n].map(function(e){return encodeURIComponent(String(0!==e?e||"":0).trim())}),a.push("".concat(n,"=").concat(encodeURIComponent(String(t).trim())))):(t=r?String(e[n]).toLowerCase()||"":0!==e[n]?e[n]||"":0,a.push("".concat(n,"=").concat(encodeURIComponent(String(t).trim())))))}(n);return"?".concat(a.join("&"))}function r(e,n,t){void 0===n&&(n=""),"/"===n[n.length-1]&&(n=n.slice(0,-1));var o=String(e).trim();return t&&(o=o.toLowerCase()),0===o.indexOf("/")?n+=o:n+="/".concat(o),n}function c(e,n){var t="#".concat(String(e).trim());return n?t.toLowerCase():t}function n(e,n){var t;return null===e?t="":"object"==typeof e?(t="",n=e):t=e||"",null!=n&&n.path&&(t=r(n.path,t,n.lowerCase)),null!=n&&n.queryParams&&(t+=o(n.queryParams,n.lowerCase,n.disableCSV)),null!=n&&n.hash&&(t+=c(n.hash,n.lowerCase)),t}e.appendPath=r,e.buildHash=c,e.buildQueryString=o,e.buildUrl=n,e.default=n,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=index.js.map