jizy-url
Version:
A simple JS url maker library.
3 lines (2 loc) • 805 B
JavaScript
/*! jUrl v2.1.1 | 2025-08-27T09:13Z | [default] */
!function(e){"use strict";if("object"!=typeof e||!e)throw new Error("jUrl requires a window");if(void 0!==e.jUrl)throw new Error("jUrl is already defined");var t=class{constructor(e){this.setBasePath(e||"/")}setBasePath(e){return this.basePath=e?e.replace(/\/+$/,"")+"/":"/",this}make(e,t,r){e="string"==typeof e?e.replace(/^\/+|\/+$/g,""):"",t=t||{},r=r||!1;let o=this.basePath;return!1===r&&(o+="json/"),e&&(o+=e+"/"),t&&(o+=this.toQueryString(t)),o}toQueryString(e){const t=[];for(let r in e)if(Array.isArray(e[r]))for(let o of e[r])t.push(`${encodeURIComponent(r)}[]=${encodeURIComponent(o)}`);else t.push(`${encodeURIComponent(r)}=${encodeURIComponent(e[r])}`);return t.length?"?"+t.join("&"):""}};e.jUrl=t}("undefined"!=typeof window?window:this);