@korautils/forms
Version:

2 lines • 2.01 kB
JavaScript
import {c}from'./chunk-6DPEEXVJ.mjs';import _ from'axios';import {useState,useCallback}from'react';var C=/^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/,A=/^(https?:\/\/)((\[[0-9a-fA-F:.]+\])|([a-zA-Z0-9.-]+))(:\d{1,5})?(\/[^\s]*)?$/;var r=class{static API_SERVER};var b=()=>{let[x,p]=useState(!1),[l,i]=useState([]),[y,c$1]=useState(null),[u,R]=useState("single"),T=r.API_SERVER,m=_.create({headers:{"Content-Type":"application/json"}}),f=t=>{p(!0),R(t),c$1(null),i([]);},E=t=>{if(A.test(t))return t;let e=t.startsWith("/")?t.substring(1):t;return `${T}/${e}`},z=useCallback(async t=>{f("single");try{let e=await m({url:E(t.url),method:t.method,headers:t.headers,params:t.params,data:t.data,timeout:t.timeout,responseType:t.responseType,auth:t.auth});return a({response:e,config:[t]}),e}catch(e){return console.log(e),a({error:e,config:[t]}),c(e,"response")}finally{p(!1);}},[]),a=({error:t,response:e,config:o})=>{for(let s of o)t&&typeof s.onError=="function"&&s.onError(t),!t&&typeof s.onSuccess=="function"&&s.onSuccess(e);e&&i(u==="single"?[e]:e),t&&(c$1(t),i([t.response]));},P=useCallback(async t=>{f("multiple");try{let e=t.map(s=>m({url:s.url,method:s.method,headers:s.headers,params:s.params,data:s.data,timeout:s.timeout,responseType:s.responseType,auth:s.auth})),o=await Promise.all(e);return a({response:o,config:t}),o}catch(e){a({error:e,config:t});}finally{p(!1);}},[]);return {fetchData:z,fetchMultipleData:P,loading:x,response:u==="single"?l[0]:l,error:y,getUrl:E}},M=b;export{C as a,A as b,M as c};//# sourceMappingURL=chunk-MIZO24FD.mjs.map
//# sourceMappingURL=chunk-MIZO24FD.mjs.map