with-query
Version:
Format url with query (string or object), simple and fast, with the power of qs
2 lines (1 loc) • 1.08 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("qs")):"function"==typeof define&&define.amd?define(["exports","qs"],t):t((e=e||self).WithQuery={},e.qs)}(this,function(e,v){"use strict";function b(){return(b=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var i=arguments[t];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(e[n]=i[n])}return e}).apply(this,arguments)}function h(e,t){return"object"==typeof e?e:e?v.parse(e,t):{}}function t(e,t,i){if(void 0===e&&(e=""),!t||"object"!=typeof t&&"string"!=typeof t||"object"==typeof t&&Object.keys(t).length<1)return e||"";var n=i&&i.parseOpt||{},r=i&&i.stringifyOpt||{},f=i&&i.noHash||!1,o=e||"",s=o,p="",u="";if(~o.indexOf("?")){var a=s.split("?");s=a[0],p=a[1]}if(~o.indexOf("#"))if(~s.indexOf("#")){var c=s.split("#");s=c[0],u=c[1]}else if(p&&~p.indexOf("#")){var y=p.split("#");p=y[0],u=y[1]}var d=h(p,n),l=h(t||"",n),O=v.stringify(b({},d,{},l),r);return s+(O?"?"+O:"")+(!f&&u?"#"+u:"")}e.default=t,e.withQuery=t,Object.defineProperty(e,"__esModule",{value:!0})});