UNPKG

@resk/core

Version:

An innovative TypeScript framework that empowers developers to build applications with a fully decorator-based architecture for efficient resource management. By combining the power of decorators with a resource-oriented design, DecorRes enhances code cla

2 lines 2.83 kB
'use strict';var y=require('../isNonNullString');require('../string');var p=require('qs');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var y__default=/*#__PURE__*/_interopDefault(y);var p__default=/*#__PURE__*/_interopDefault(p);var g=Object.defineProperty;var f=Object.getOwnPropertySymbols;var l=Object.prototype.hasOwnProperty,u=Object.prototype.propertyIsEnumerable;var c=(r,t,e)=>t in r?g(r,t,{enumerable:true,configurable:true,writable:true,value:e}):r[t]=e,a=(r,t)=>{for(var e in t||(t={}))l.call(t,e)&&c(r,e,t[e]);if(f)for(var e of f(t))u.call(t,e)&&c(r,e,t[e]);return r};const h=(r,t=true)=>{if(typeof r!="string")return "";let e=j(r);return r=typeof e.search=="string"?e.search:"",t&&r?"?"+r.ltrim("?"):(r=r.trim().ltrim("?").rtrim("?"),r)},m=function(r,t={}){return typeof r!="string"?{}:p__default.default.parse(h(r,false),a({allowSparse:true},Object.assign({},t)))},d=function(r,t=false){return typeof r!="string"?"":(r=r.replace(/#.*$/,"").replace(/\?.*$/,""),t===true?decodeURIComponent(r):r)},b={indices:false,arrayFormat:"brackets",encodeValuesOnly:true};function Q(r,t,e,o={}){if(typeof r!="string"||!r)return "";let n=m(r);return r=d(r),typeof t=="object"?(t||(t={}),o=typeof o=="object"&&o?o:typeof e=="object"&&e?e:{}):typeof t=="string"&&(t={[t]:e}),typeof t=="object"&&t&&!Array.isArray(t)&&Object.assign(n,t),r+"?"+p__default.default.stringify(n,a(a({},b),Object.assign({},o)))}function A(r,t=false){if(r==null||typeof r!="object")return "";function e(n,s){if(Array.isArray(n)){n.forEach(function(i){e(i,s+"[]");});return}if(n!==null&&typeof n=="object"){Object.keys(n).forEach(function(i){e(n[i],s+"["+i+"]");});return}o.push((t?encodeURIComponent(s):s)+"="+(t?encodeURIComponent(n):n));}const o=[];return Object.keys(r).forEach(function(n){e(r[n],n);}),o.join("&")}const j=r=>{if(typeof r!="string")return {};var t=r.match(/^(([^:\/?#]+:)?(?:\/\/((?:([^\/?#:]*):([^\/?#:]*)@)?([^\/?#:]*)(?::([^\/?#:]*))?)))?([^?#]*)(\?[^#]*)?(#.*)?$/);let e=t?{hash:t[10]||"",host:t[3]||"",hostname:t[6]||"",href:t[0]||"",origin:t[1]||"",pathname:t[8]||(t[1]?"/":""),port:t[7]||"",protocol:t[2]||"",search:t[9]||"",username:t[4]||"",password:t[5]||""}:{};return e.protocol&&e.protocol.length==2&&(e.protocol="file:///"+e.protocol.toUpperCase(),e.origin=e.protocol+"//"+e.host),e.protocol&&(e.href=e.origin+e.pathname+e.search+e.hash),e},C=r=>{if(!y__default.default(r)||!r.trim())return false;if(/^(?:\w+:)?\/\/([^\s\.]+\.\S{2}|localhost[\:?\d]*)\S*$/.test(r))return true;if(typeof URL!="undefined"&&URL)try{const t=new URL(r);return t.protocol==="http:"||t.protocol==="https:"}catch(t){return false}return false}; exports.extractQueryString=h;exports.getQueryParams=m;exports.isValidUrl=C;exports.objectToQueryString=A;exports.parseURI=j;exports.removeQueryString=d;exports.setQueryParams=Q;