@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 • 4.72 kB
JavaScript
;var m=require('qs');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var m__default=/*#__PURE__*/_interopDefault(m);var d=Object.defineProperty;var l=Object.getOwnPropertySymbols;var y=Object.prototype.hasOwnProperty,S=Object.prototype.propertyIsEnumerable;var u=(t,r,n)=>r in t?d(t,r,{enumerable:true,configurable:true,writable:true,value:n}):t[r]=n,f=(t,r)=>{for(var n in r||(r={}))y.call(r,n)&&u(t,n,r[n]);if(l)for(var n of l(r))S.call(r,n)&&u(t,n,r[n]);return t};function s(t){return !!(t&&typeof t=="string")}var g=function(t,r=""){if(!t||typeof t!="string")return "";if(!r||typeof r!="string")return t.trim();let n=t.length;for(;t.startsWith(r)&&n>=0;)t=t.slice(r.length),--n;return t.toString()},p=function(t,r=""){if(!t||typeof t!="string")return "";if(!r||typeof r!="string")return t.trim();let n=t.length;for(;t.endsWith(r)&&n>=0;)t=t.slice(0,-r.length),--n;return t.toString()},b=(t,r=true)=>typeof t!="string"?false:r!==false?/^\d*\.?\d+$/.test(t):/^\d+$/.test(t);String.prototype.ltrim=function(t){return g(this.toString(),t)};String.prototype.rtrim=function(t){return p(this.toString(),t)};String.prototype.isNumber=function(t=true){return b(this.toString(),t)};String.prototype.replaceAll=function(t,r){return !s(t)||!s(r)?this.toString():this.toString().split(t).join(r)};var C=t=>s(t)?(t=t.trim(),t.replace(/(.)([A-Z][a-z]+)/,"$1_$2").replace(/([a-z0-9])([A-Z])/,"$1_$2").toUpperCase()):"";String.prototype.toSnakeCase=function(){return C(this.toString())};var U=t=>s(t)?(t=t.trim(),t.charAt(0)+t.replace(/(_\w)/g,r=>r[1].toUpperCase()).substring(1)):"";String.prototype.toCamelCase=function(){return U(this.toString())};var j=function(t){return !t||typeof t!="string"?"":(t=t.trim(),t.charAt(0).toUpperCase()+t.slice(1))};String.prototype.upperFirst=function(){return j(this.toString())};var w=function(t){return !t||typeof t!="string"?"":(t=t.trim(),t.charAt(0).toLowerCase()+t.slice(1))};String.prototype.lowerFirst=function(){return w(this.toString())};var I=(t,r=true)=>{if(typeof t!="string")return "";let n=A(t);return t=typeof n.search=="string"?n.search:"",r&&t?"?"+g(t,"?"):(t=p(g(t.trim(),"?"),"?"),t)},R=function(t,r={}){return typeof t!="string"?{}:m__default.default.parse(I(t,false),f({allowSparse:true},Object.assign({},r)))},x=function(t,r=false){return typeof t!="string"?"":(t=t.replace(/#.*$/,"").replace(/\?.*$/,""),r===true?decodeURIComponent(t):t)},O={indices:true,encodeValuesOnly:false,skipNulls:false,arrayFormat:"indices",encoder:t=>encodeURIComponent(t).replace(/%5B/g,"[").replace(/%5D/g,"]")};function q(t,r,n,i={}){if(typeof t!="string")return "";t||(t="");let e=R(t),o=t.split("#"),a=o[0],h=o[1]?"#"+o[1]:"";t=x(a),typeof r=="object"?(r||(r={}),i=typeof i=="object"&&i?i:typeof n=="object"&&n?n:{}):typeof r=="string"&&(r={[r]:n}),typeof r=="object"&&r&&!Array.isArray(r)&&Object.assign(e,r);let c=m__default.default.stringify(e,f(f({},O),Object.assign({},i)));return t+(c?"?"+c:"")+h}function z(t,r=false){if(t==null||typeof t!="object")return "";function n(e,o){if(Array.isArray(e)){e.forEach(function(a){n(a,o+"[]");});return}if(e!==null&&typeof e=="object"){Object.keys(e).forEach(function(a){n(e[a],o+"["+a+"]");});return}i.push((r?encodeURIComponent(o):o)+"="+(r?encodeURIComponent(e):e));}let i=[];return Object.keys(t).forEach(function(e){n(t[e],e);}),i.join("&")}var A=t=>{if(typeof t!="string")return {};if(typeof URL!="undefined"&&URL&&N(t))try{return new URL(t)}catch(i){}t=$(t)?decodeURIComponent(t):t;var r=t.match(/^(([^:\/?#]+:)?(?:\/\/((?:([^\/?#:]*):([^\/?#:]*)@)?([^\/?#:]*)(?::([^\/?#:]*))?)))?([^?#]*)(\?[^#]*)?(#.*)?$/);let n=r?{hash:r[10]||"",host:r[3]||"",hostname:r[6]||"",href:r[0]||"",origin:r[1]||"",pathname:r[8]||(r[1]?"/":""),port:r[7]||"",protocol:r[2]||"",search:r[9]||"",username:r[4]||"",password:r[5]||""}:{};return n.protocol&&n.protocol.length==2&&(n.protocol="file:///"+n.protocol.toUpperCase(),n.origin=n.protocol+"//"+n.host),n.protocol&&(n.href=n.origin+n.pathname+n.search+n.hash),n},N=t=>{if(!s(t)||!t.trim())return false;if(/^(?:\w+:)?\/\/([^\s\.]+\.\S{2}|localhost[\:?\d]*)\S*$/.test(t))return true;if(typeof URL!="undefined"&&URL)try{let r=new URL(t);return r.protocol==="http:"||r.protocol==="https:"}catch(r){return false}return false},$=t=>{if(!s(t)||!t.includes("%"))return false;let r=/%[0-9A-Fa-f]{2}/g;if(!t.match(r))return false;try{let i=decodeURIComponent(t);if(i!==t)return !0;try{if(decodeURIComponent(i)!==i)return !0}catch(e){return !0}}catch(i){return false}return false};
exports.extractQueryString=I;exports.getQueryParams=R;exports.isUriEncoded=$;exports.isValidUrl=N;exports.objectToQueryString=z;exports.parseURI=A;exports.removeQueryString=x;exports.setQueryParams=q;