jsfast
Version:
Fastjs(jsfast) is a useful, lightweight JavaScript library for any types of project.
2 lines (1 loc) • 20.1 kB
JavaScript
;function e(e){const t={"fastjs.bold":"[1m","fastjs.reverse":"[7m","fastjs.red":"[31m","fastjs.green":"[32m","fastjs.yellow":"[33m","fastjs.blue":"[34m","fastjs.magenta":"[35m","fastjs.cyan":"[36m","fastjs.white":"[37m","fastjs.gray":"[90m","fastjs.bgRed":"[41m","fastjs.bgGreen":"[42m","fastjs.bgYellow":"[43m","fastjs.bgBlue":"[44m","fastjs.bgMagenta":"[45m","fastjs.bgCyan":"[46m","fastjs.bgWhite":"[47m","fastjs.bgGray":"[100m","fastjs.wrong":"[41m[37m[1m","fastjs.right":"[42m[37m[1m","fastjs.warn":"[43m[90m[1m"};return e?Array.isArray(e)?e.map((e=>t[e])).join(""):t[e]||"":""}function t(t,n,r=[],s=[]){r=(r=(r=r.filter((e=>""!==e))).map(((e,t)=>"string"==typeof e&&"&"!==e[0]&&"&"!==r[t-1]?.[r[t-1].length-1]?"\n > "+e:e))).map((e=>("string"!=typeof e||("&"===e[0]&&(e=` ${e.slice(1)} `),"&"===e[e.length-1]&&(e=`${e.slice(0,-1)} `)),e)));let o=0,l="",a=[];s.length&&e(s[s.length-1]),r.unshift(`[Fastjs warn] ${t}: ${n}`),r.forEach((t=>{if("string"!=typeof t)return l+="%o",void a.push(t);if(t.includes("> *")&&!t.includes("> **")){let n=s[o];t=(t=t.replace("*","")).replace(" >",e(n)+"--\x3e[0m"),o++}if(t.includes("***")){let n=s[o];t=(t=t.replace("***","")).split("> ")[0]+"> "+e(n)+t.split("> ").slice(1).join("> ")+"[0m",o++}for(;t.includes("**");){let n=s[o];t=(t=t.replace("**",e(n))).replace("**","[0m"),o++}l+=t})),console.warn(l,...a)}function n(e,n,r=[],s=[]){const o=Math.floor(9e7*Math.random()+1e7);return r.push(`Trace: ${o}`),t(e,n,r,s),new Error(`[Fastjs error] ${e}: ${n.replace(/[*&]/g,"")}\n > Trace: ${o}`)}var r={browserCheck:function(e){if(!("undefined"!=typeof window))throw n(`${e}/browserCheck`,"This module is only available in browser environments.")},experimentFeatureWarning:function(e,n,r){t("fastjs/experiment-feature-"+e,`${n} is an experimental feature, it may be removed or changed in the future.`,["call: ",r],["fastjs.warn"])},warn:t,error:n};function s(e,t=document){const n=[];function r(e,t){return e.set?e.get("querySelectorAll")(t):e.querySelectorAll(t)}if("FastjsDom"===t?.construct&&(t=t._el),"FastjsDomList"===t?.construct&&(t=t._list),Array.isArray(t)?t.forEach((t=>{n.push(...o(r(t,e)))})):n.push(...o(r(t,e))),0===n.length)return null;if(n[0].id&&e.includes(`#${n[0].id}`)||["body","head"].includes(e))return n[0];const s=[];return n.forEach((e=>{s.push(e)})),s;function o(e){const t=[];return e.forEach((e=>{t.push(e)})),t}}function o(e){return void 0===e}function l(e){const t=[];for(const n of e)null!=n&&("FastjsDom"===n.construct?t.push(n):Array.isArray(n)?t.push(...n):t.push(g(n)));const n=function(e){return{construct:"FastjsDomList",get length(){return e.length},set length(t){e.length=t}}}(t),r=new Proxy(n,{get(e,t){if(t in e)return e[t];if(t in e._list)return e._list[t];if(t in e._list[0]){const n=e._list[0][t];return"function"==typeof n?function(){for(const n of e._list){const e=n[t];if("function"==typeof e){const t=e.bind(n,...arguments)();if(!o(t)&&"FastjsDom"!==t.construct)return t}}return e}:n}return e[t]},set:(e,t,r)=>(e[t]=r,Number.isInteger(Number(t))&&(n._list[t]=r,e[t]=r),!0)});return r._list=new Proxy(t,{set:(e,t,r)=>(e[Number(t)]=r,n[Number(t)]=r,!0)}),t.forEach(((e,t)=>{r[t]=e})),Object.assign(r,function(e){return{add:t=>(e.push(t),e),delete:(t,n=!0)=>(n&&e[t].remove(),e.splice(t,1),e),each:t=>(e.forEach(((e,n)=>t(e,e.el(),n))),e),el:(t=0)=>e[t].el(),getElement(e=0){return this.el(e)},getDom:(t=0)=>e[t],next(e="*"){const t=s(e,this.toElArray());return Array.isArray(t)?l(t):null===t?null:g(t)},toArray:()=>e,toElArray:()=>e.map((e=>e.el()))}}(r))}async function a(e,t,n=!1,r=!1){return new Promise(((s,o)=>{let l=!1;const a=()=>l;setTimeout((async function n(){try{let r=e(a);r instanceof Promise&&(r=await r),l||!r?setTimeout(n,t):s()}catch(e){r?(setTimeout(n,t),console.error(e)):(o(e),l=!0)}}),n?0:t)}))}function c(e,t){const n=e=>(t?t(e):console.error(e),e);try{const t=e();return t instanceof Promise?t.then((e=>e)).catch(n):t}catch(e){return n(e)}}function i(e){try{const t=e();return t instanceof Promise?new Promise(((e,n)=>{t.then((t=>e([t,null]))).catch((t=>e([void 0,t])))})):[t,null]}catch(e){return[void 0,e]}}async function u(e){try{const t=await async function(e){const{createFastjsDom:t}=await Promise.resolve().then((function(){return y}));let n=t("span");return n.html(r(e)).push(document.body,"lastElementChild"),n.el();function r(e){return e.replace(/\n/g,"<br>").replace(/ /g," ")}}(e);!function(e){if(!e)return;document.execCommand("copy")}(function(e){const t=document.createRange();t.setStart(e,0),t.setEnd(e,e.childNodes.length);const n=window.getSelection();return n?(n.removeAllRanges(),n.addRange(t),n):null}(t)),t.remove()}catch(e){}}function f(e,t,n=0){const r=10*n||1;return[e,t]=[e*r,t*r],(Math.floor(Math.pow(10,14)*Math.random()*Math.random())%(t-e+1)+e)/r}function d(e,t={}){const n="abcdefghijklmnopqrstuvwxyz";let r="";t.number&&(r+="0123456789"),!1!==t.letter&&(t.upper&&(r+=n.toUpperCase()),!1!==t.lower&&(r+=n)),Array.isArray(t.custom)?r+=t.custom.join(""):t?.custom&&(r+=t.custom),t.max&&(e=f(e,t.max));let s="";for(let t=0;t<e;t++)s+=r.charAt(f(0,r.length-1));return s}function m(){const e=e=>d(e,{number:!0});return`${e(8)}-${e(4)}-4${e(3)}-${e(4)}-${e(12)}`}var h={...Object.freeze({__proto__:null,callUntilEnd:a,catchError:c,secureCall:i}),...Object.freeze({__proto__:null,copy:u}),...Object.freeze({__proto__:null,rand:f,randString:d,uuid:m})};function p(e){return{...e(),setCustomProp(e,t){return this[String(e)]=t,this},setCustomProps(e){for(const t in e)this[t]=e[t];return this},getCustomProp(e){return this[String(e)]},setCustomEvent(e,t,n=!1){return this[e]=t,n&&t(this,this),this},callCustomEvent(e,...t){return this[e](this,...t),this},then(e,t=0){const n=()=>e(this);return 0===t?n():setTimeout(n,t),this}}}function g(e=document.body,t){"string"==typeof e?e=document.createElement(e):"construct"in e&&"FastjsDom"===e.construct&&(e=e._el);const n=p((()=>({construct:"FastjsDom",_events:[],_el:e}))),r=Object.assign(n,function(e){function t(t,n){return(r(e._el?.constructor.prototype,t)?.writable||r(e._el?.constructor.prototype,t)?.set)&&(e._el[t]=n),e;function r(e,t){for(;null!==e;){const n=Object.getOwnPropertyDescriptor(e,t);if(n)return n;e=Object.getPrototypeOf(e)}return null}}const n=(t,n)=>{t.forEach((t=>{t.split(" ").forEach((t=>{e.setClass(t,n)}))}))};return{get:function(t){return e._el[t]},set:t,text:function(t){return void 0===t?e._el.textContent||"":(e._el.textContent=t,e)},html:function(t){return void 0===t?e._el.innerHTML:(e._el.innerHTML=t,e)},val:function(n){const r="TEXTAREA"===e._el.tagName?"textContent":"value";return void 0===n?e._el[r]:(t(r,n),e)},el:()=>e._el,remove:()=>(e._el.remove(),e),focus:()=>(e._el.focus(),e),first:()=>e._el.firstElementChild?g(e._el.firstElementChild):null,last:()=>e._el.lastElementChild?g(e._el.lastElementChild):null,father:()=>{const t=e._el.parentElement;return t?g(t):null},children:()=>l([...e._el.children]),next:(t="*")=>{const n=s(t,e._el);return Array.isArray(n)?l(n):null===n?null:g(n)},each:(t,n=!1)=>([...e._el.children].forEach(((e,r)=>{t(g(e),e,r),n&&g(e).each(t,n)})),e),addEvent:function(t,n){let r=t=>n(e,t);return e._events.push({type:t,callback:n,trigger:r,remove:()=>{e.removeEvent(n)}}),e._el.addEventListener(t,r),e},removeEvent:function(t,n){const r={type:"string"==typeof t?t:void 0,callback:"function"==typeof t?t:void 0,key:n};return r.callback?e._events.forEach(((t,n)=>{t.callback===r.callback&&(e._el.removeEventListener(t.type,t.trigger),e._events.splice(n,1))})):r.type&&(void 0!==r.key?(e._el.removeEventListener(e._events[r.key].type,e._events[r.key].trigger),e._events.splice(r.key,1)):e._events.forEach((t=>{t.type===r.type&&(e._el.removeEventListener(t.type,t.trigger),e._events.splice(e._events.indexOf(t),1))}))),e},getStyle:function(t){const n=()=>new Proxy(s,{get:(e,t)=>e.getPropertyValue(t)||e[t]||null,set:(t,n,r)=>(e.setStyle(n,r),Reflect.set(t,n,r))}),r=window.getComputedStyle(e._el),s=Object.assign(r,e._el.style);return"string"==typeof t?s.getPropertyValue(t.replace(/[A-Z]/g,(e=>"-"+e.toLowerCase()))):"function"!=typeof t?n():(t(n(),e),e)},setStyle:function(t,n,r){if(n)e._el.style.setProperty(t.replace(/[A-Z]/g,(e=>"-"+e.toLowerCase())),n,r?"important":"");else if("string"==typeof t)e._el.style.cssText=t;else{let n;for(n in t)e.setStyle(n,t[n])}return e},getClass:function(t){const n=[...e._el.classList];if(!t)return n;t(n)},setClass:function(t,n=!0){if("string"==typeof t)e._el.classList[n?"add":"remove"](t);else for(const n in t)e.setClass(n,t[n]);return e},addClass:function(t){return"string"==typeof t?n([...arguments],!0):t.forEach((t=>e.addClass(t))),e},removeClass:function(t){return"string"==typeof t?n([...arguments],!1):t.forEach((t=>e.removeClass(t))),e},clearClass:()=>(e._el.className="",e),getAttr:function(t){const n=()=>{const t=[...e._el.attributes],n={};return t.forEach((e=>{n[e.name]=e.value})),new Proxy(n,{set:(t,n,r)=>(e.setAttr(n,r),Reflect.set(t,n,r))})};switch(typeof t){case"string":return e._el.getAttribute(t);case"function":return t(n(),e),e;default:return n()}},setAttr:function(t,n){const r=(t,n)=>{null===n?e._el.removeAttribute(t):e._el.setAttribute(t,n)};if("string"==typeof t)r(t,n);else for(const e in t)r(e,t[e]);return e},push:function(t=document.body,n="lastElementChild",r){t=t.tagName?t:t.el();const s="replaceElement"===n,o=g(r?e._el.cloneNode(!0):e._el);if(s){const t=g(e._el.parentElement);if(null===t)throw new Error("father is null");t._el.replaceChild(o._el,e._el)}else if("number"==typeof n)e._el.insertBefore(o._el,e._el.children[n]);else{({firstElementChild:()=>t.prepend(o._el),lastElementChild:()=>t.append(o._el),randomElementChild:function(){const n=[...t.children];0===n.length||f(0,n.length)===n.length?t.appendChild(e._el):t.insertBefore(e._el,n[f(0,n.length-1)])},beforeElement:()=>t.before(o._el),afterElement:()=>t.after(o._el)})[n]()}return{isReplace:s,newElement:s&&o,oldElement:s&&e,index:[...t.children].indexOf(o._el),el:o,origin:e,father:o.father()}},insert:function(t,n="last",r){t=t.tagName?t:t.el();const s=g(r?t.cloneNode(!0):t);if("number"==typeof n)t.insertBefore(s._el,e._el.children[n]);else{({first:()=>e._el.prepend(s._el),last:()=>e._el.append(s._el),random:function(){const t=[...e._el.children];0===t.length?e._el.appendChild(s._el):e._el.insertBefore(s._el,t[f(0,t.length-1)])},before:()=>e._el.before(s._el),after:()=>e._el.after(s._el)})[n]()}return{index:Array.from(t.children).indexOf(s._el),added:s,origin:e}}}}(n));return t&&function(e,t){let n;for(n in t)"html"===n?e.html(t.html):"text"===n?e.text(t.text):"css"===n?e.setStyle(t.css):"class"===n?e.addClass(t.class):"attr"===n?e.setAttr(t.attr):"val"===n?e.val(t.val):n in e._el&&e.set(n,t[n])}(r,t),r}var y=Object.freeze({__proto__:null,createFastjsDom:g});function b(e="body",t=document){const n=s(e,t);return Array.isArray(n)?l(n):null===n?null:g(n)}const _=function(e="body",t=document){return b(e,t)};_.select=b,_.newEl=g,_.newElList=l;var w=_;function E(e=new Date){return[["Y",e.getFullYear()],["M",e.getMonth()+1],["D",e.getDate()],["H",e.getHours()%12],["hh",e.getHours()],["h",e.getHours()],["mm",e.getMinutes()],["m",e.getMinutes()],["ss",e.getSeconds()],["s",e.getSeconds()],["S",e.getMilliseconds()],["A",e.getHours()>=12?"PM":"AM"],["a",e.getHours()>=12?"pm":"am"]].map((e=>{return 1===e[0].length&&"number"==typeof e[1]?[e[0],(t=e[1],t<10?"0"+t:t.toString())]:e;var t}))}function v(e,t){let n=!1,r=new Date;r.setMilliseconds(0);let s="",o=null,l=!1,a=-1;const c=E().map((e=>e[0]));for(let i=0;i<e.length;i++){a++;const u=e[i];if("<"!==u&&">"!==u){if(!n)if(c.includes(u)){if(l)throw"fg3j";switch(u){case"Y":r.setFullYear(Number(t.slice(a,a+4))),a+=3;break;case"M":r.setMonth(Number(t.slice(a,a+2))-1),a+=1;break;case"D":r.setDate(Number(t.slice(a,a+2))),a+=1;break;case"H":s=t.slice(a,a+2),a+=1;break;case"A":o="AM"===t.slice(a,a+2),a+=1;break;case"a":o="am"===t.slice(a,a+2),a+=1;break;case"h":r.setHours(Number(t.slice(a,a+2))),a+=1;break;case"m":r.setMinutes(Number(t.slice(a,a+2))),a+=1;break;case"s":r.setSeconds(Number(t.slice(a,a+2))),a+=1;break;case"S":r.setMilliseconds(Number(t.slice(a,a+3))),a+=2}l=!0}else l=!1}else n="<"===u,l=!1,a--}if(s){if(null===o)throw"2b5s";o?r.setHours(Number(s)):r.setHours(Number(s)+12)}return r.getTime()}function j(e="Y-M-D h:m:s",t=Date.now(),n=!1){"string"==typeof t?t=v(e,t):t instanceof Date&&(t=t.getTime());const r=p((()=>({construct:"FastjsDate",format:e,_date:t,_createAt:Date.now(),timezoneDiff:60*(new Date).getTimezoneOffset()*1e3})));n&&(r._date+=r.timezoneDiff);const s=Object.assign(r,function(e){const t=(t=!0)=>t?e._date:e._date-e.timezoneDiff,n=(n=!0)=>t(n)+Date.now()-e._createAt;return{changeDate:function(t){return"string"==typeof t&&(t=v(e.format,t)),e._date=t,e._createAt=Date.now(),e},changeFormat:t=>(e.format=t,e),setZone:t=>(e.timezoneDiff=3600*t*1e3,e),refresh:()=>(e._createAt=Date.now(),e),toNumber:t,toActiveNumber:n,toString:function(t,n){const r={format:n};t?"number"==typeof t||["utc","local"].includes(t)?r.show=t:r.format=t:r.show="utc";const[s,o]=function(e){const t=[];let n="",r="",s=0;for(const o of e){if("<"===o){if(1==++s)continue}else if(">"===o&&(s--,0===s)){t.push(r),n+=`{{*${t.length-1}}}`,r="";continue}s>0?r+=o:n+=o}return s>0&&(n+=`<${r}`),[n,t]}(r.format||e.format);let l=e._date;"number"==typeof r.show?l-=3600*r.show*1e3:"local"===r.show&&(l-=e.timezoneDiff);let a=s;for(const e of E(new Date(l))){const t=e[0],n=e[1];a=a.replace(new RegExp(t,"g"),String(n))}return o.forEach(((e,t)=>{a=a.replace(`{{*${t}}}`,`${e}`)})),a},toActiveString:function(t,r){return"string"!=typeof t||["utc","local"].includes(t)||(r=t),j(r||e.format,n()).toString()}}}(r));return s}const k=(e,t="Y-M-D h:m:s")=>{const n=j(t,e),r=n.toString(),s=n.toNumber(),o=s+60*(new Date).getTimezoneOffset()*1e3;return{format:t,date:new Date(s),string:r,dateString:r,timestamp:s,utcDate:new Date(o),utcTimestamp:o,utcDateString:j(t,o).toString()}};var A={parse:k,parseTime:(e,t)=>k(e,t),parseDate:(e,t)=>k(e,t),string:(e,t=Date.now())=>k(t,e).string,reformat:(e,t,n="Y-M-D h:m:s")=>j(e,t).toString(n),now:e=>k(Date.now(),e),create:j};const C={timeout:5e3,hooks:{runAll:!1},handler:{handleResponse:async(e,t)=>e.headers.get("Content-Type")?.includes("application/json")?await e.json():await e.text(),responseCode:e=>e>=200&&e<300},check:{ignoreFormatWarning:!1,stringBodyWarning:!0,unrecommendedMethodWarning:!0}};function x(e={}){return{timeout:e.timeout||C.timeout,headers:e.headers||{},wait:e.wait||0,failed:e.failed||(()=>0),callback:e.callback||(()=>0),query:e.query||null,body:e.body||null,hooks:function(){const t={before:[],init:[],success:[],failed:[]};let n;for(n in t){const r=e=>{e&&t[n].push(...Array.isArray(e)?e:[e])};e.hooks?.[n]&&r(e.hooks[n]),C.hooks[n]&&r(C.hooks[n])}return Object.assign(t,{runAll:e.hooks?.runAll||C.hooks.runAll})}()}}function D(e,t){if(!t||0===Object.keys(t).length)return e;const n=function(e){if("string"!=typeof e)return new URLSearchParams(e);"?"===e[0]&&(e=e.slice(1));const t=new URLSearchParams;return e.split("&").forEach((e=>{const[n,r]=e.split("=");t.set(n,r)})),t}(t);return n.size>0&&(e=e+(e.includes("?")?"&":"?")+n.toString()),e}function S(e,t,n=e.url){if(n||(n=e.url),!n)throw new Error("A correct url is required.");const s={body:o(t)?e.data:null,query:(o(t)?null:e.data)||e.config.query};return e.config.wait?(e.wait&&clearTimeout(e.wait),e.wait=setTimeout((()=>{l(),e.wait=null}),e.config.wait)):l(),e;function o(e){return!["GET","HEAD","OPTIONS"].includes(e)}async function l(){const o=e.config.hooks;if(!await P(o.before,[e]))return O("before",e,null);let l=[];[n,l]=function(e,t){const n=e.split("/"),r=/^:/,s=[];return[n.map((e=>{const n=e.replace(":","");if(r.test(e)&&t[n]){s.push(n);const e=t[n];return delete t[n],e}return e})).join("/"),s]}(n,e.data);for(const t of l)delete e.data[t];if("object"==typeof s.body&&(e.config.headers["Content-Type"]="application/json"),e.request=new Request(D(n,s.query),{method:t,headers:e.config.headers,body:s.body?JSON.stringify(s.body):void 0}),!await P(o.init,[e]))return O("init",e,null);const a=e.config.timeout?AbortSignal.timeout(e.config.timeout):null;fetch(e.request,{signal:a}).then((async n=>{const r=await C.handler.handleResponse(n,e),s=n.headers;s.toArray=()=>[...n.headers.entries()],s.toObject=()=>Object.fromEntries(n.headers.entries());const l=function(e){try{return JSON.parse(e)}catch(t){return e}}(r),a={headers:s,response:n,data:l,status:n.status,request:e,resend:()=>S(e,t)},c=Object.create(Object.getPrototypeOf(l));return c.getFullReturn=()=>a,Object.setPrototypeOf(l,c),C.handler.responseCode(n.status,e)?await P(o.success,[a,e])?(T(e.callback.success,[r,a],t),void T(e.callback.finally,[e],t)):O("success",e,a):await async function(e,t,n){let r=e?.status;if(e.data,!await P(t.config.hooks.failed,[r,t]))return O("failed",t,null);const s={error:r,request:t,intercept:!1,hook:null,response:e,headers:e.headers,resend:()=>S(t,t.request?.method)};t.config.failed(s),T(t.callback.failed,[s],null),T(t.callback.finally,[t],null)}(a,e)})).catch((async s=>{if(r.warn("fastjs/request","Failed to send request.",[`url: ${n}`,`method: ${t}`,"body: ",e.body,`error: ${s.message}`,"super: ",e],["fastjs.wrong"]),!await P(o.failed,[s,e]))return O("failed",e,null);const l={error:s,request:e,intercept:!1,hook:null,response:null,headers:null,resend:()=>S(e,e.request?.method)};e.config.failed(l),T(e.callback.failed,[l],t),T(e.callback.finally,[e],t)}))}}function T(e,t,n){for(let r=0;r<e.length;r++){const s=e[r];s.method&&s.method!==n||(s.func(...t),s.once&&(e.splice(r,1),r--))}}function O(e,t,n){const r={error:new Error(`Request interrupted by ${e}`),request:t,intercept:!0,hook:e,response:n,headers:n?.headers||null,resend:()=>S(t,t.request?.method)};t.config.failed(r),T(t.callback.failed,[r],null),T(t.callback.finally,[t],null)}async function P(e,t){if(!e)return!0;if("function"==typeof e){return await e(t[0],t[1])??!0}let n=!0;for(const r of e){if(!1===await r(t[0],t[1])&&(n=!1,!C.hooks.runAll))break}return n}function $(e){const t=(t,n={},r)=>(e.data=Object.assign(e.data,n),S(e,t,r));function n(e){return(n,r)=>function(e,n,r){let s={},o="";return n&&("string"==typeof n?o=n:s=n,r&&("string"==typeof r?o=r:s=r)),t(e,s,o)}(e,n,r)}return{send:t,get:n("GET"),post:n("POST"),put:n("PUT"),delete:n("DELETE"),patch:n("PATCH"),head:n("HEAD"),options:n("OPTIONS"),then:(t,n=!1,r)=>(e.callback.success.push({func:t,once:!n,method:r}),e),catch:(t,n=!1,r)=>(e.callback.failed.push({func:t,once:!n,method:r}),e),finally:(t,n=!1,r)=>(e.callback.finally.push({func:t,once:!n,method:r}),e)}}function M(e,t=null,n){const r=p((()=>({construct:"FastjsRequest",url:e,data:t||{},config:x(n),callback:{success:[],failed:[],finally:[]}})));return Object.assign(r,$(r))}function N(e){return(t,n,r)=>M(t,n,r)[e.toLowerCase()]()}var q={get:N("GET"),post:N("POST"),put:N("PUT"),delete:N("DELETE"),patch:N("PATCH"),head:N("HEAD"),create:(e,t,n)=>M(e,t,n),request:x,config:C};function F(){return"undefined"!=typeof document}function R(e,t){const n=p((()=>({construct:"FastjsCookie",path:e,domain:t})));var r;return Object.assign(n,(r=n,{get:function(e){if(!F())return null;const t=document.cookie.match(new RegExp(`(^| )${e}=([^;]+)`));return t?decodeURIComponent(t[2]):null},set:function(e,t,n={}){if(!F())return r;let s=`${e}=${encodeURIComponent(t)}`;if(n.expires){let e=new Date;"number"==typeof n.expires?e.setTime(e.getTime()+n.expires):e=n.expires,s+=`; expires=${e.toUTCString()}`}return n.path&&(s+=`; path=${n.path}`),n.domain&&(s+=`; domain=${n.domain}`),n.secure&&(s+="; secure"),document.cookie=s,r},remove:function(e){return F()?(document.cookie=`${e}=; expires=Thu, 01 Jan 1970 00:00:00 GMT`,r):r}}))}const L=e=>R().get(e);var H={get:L,exists:e=>null!==L(e),set:(e,t,n={})=>R().set(e,t,n),remove:e=>R().remove(e),create:R};exports.callUntilEnd=a,exports.catchError=c,exports.cookie=H,exports.copy=u,exports.date=A,exports.dom=w,exports.rand=f,exports.randString=d,exports.request=q,exports.secureCall=i,exports.utils=h,exports.uuid=m;