@gohanfromgoku/ui-kit 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/index.js +1 -1
- package/package.json +19 -4
- package/types/api/index.d.ts +3 -1
package/dist/api/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const METHODS={GET:"GET",POST:"POST",PUT:"PUT",DELETE:"DELETE"};const appendParams=(t,e)=>{if(!e)return t;const s=new URLSearchParams({...e}).toString();return s?`${t}?${s}`:t},parseResponse=async t=>{const e=t.headers.get("content-type")||"";return e.includes("application/json")?await t.json().catch(()=>null):e.includes("text/")?await t.text():await t.blob().catch(()=>null)}
|
|
1
|
+
export const METHODS={GET:"GET",POST:"POST",PUT:"PUT",DELETE:"DELETE"};const appendParams=(t,e)=>{if(!e)return t;const s=new URLSearchParams({...e}).toString();return s?`${t}?${s}`:t},parseResponse=async t=>{const e=t.headers.get("content-type")||"";return e.includes("application/json")?await t.json().catch(()=>null):e.includes("text/")?await t.text():await t.blob().catch(()=>null)};export class API{baseURL;defaultHeaders={};timeout=0;constructor(t,e={},s=0){this.baseURL=t.replace(/\/+$/,""),this.defaultHeaders={"Content-Type":"application/json",...e},this.timeout=s}createURL(t){return t.startsWith("http")?t:"/"===t||""===t?this.baseURL:t.startsWith("/")?`${this.baseURL}${t}`:`${this.baseURL}/${t}`}async request(t,e,s={}){const{params:a,headers:r,body:n,signal:o}=s,i=appendParams(this.createURL(e),a),c=n instanceof FormData||t===METHODS.GET?{...r}:{...this.defaultHeaders,...r},h=n?n instanceof FormData||"string"==typeof n?n:JSON.stringify(n):void 0,T=new AbortController,l=()=>T.abort();let u=null;try{this.timeout>0&&(u=setTimeout(l,this.timeout)),o&&o.addEventListener("abort",l);const e=await fetch(i,{method:t,body:h,headers:c,signal:T.signal}),s=await parseResponse(e);if(!e.ok)throw s||new Error(e.statusText);return s}catch(s){throw console.error(`${t}: ${e} :: `,s),s}finally{u&&clearTimeout(u),o&&o.removeEventListener("abort",l)}}GET=(t,e)=>this.request(METHODS.GET,t,e);POST=(t,e)=>this.request(METHODS.POST,t,e);PUT=(t,e)=>this.request(METHODS.PUT,t,e);DELETE=(t,e)=>this.request(METHODS.DELETE,t,e)}
|
package/package.json
CHANGED
|
@@ -1,15 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gohanfromgoku/ui-kit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc && tsc-alias && pnpm run minify",
|
|
7
7
|
"minify": "find dist -name '*.js' -exec terser {} --compress --mangle --output {} \\;",
|
|
8
8
|
"watch": "tsc --watch"
|
|
9
9
|
},
|
|
10
|
-
"keywords": [
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
"keywords": [
|
|
11
|
+
"ui-kit",
|
|
12
|
+
"components",
|
|
13
|
+
"typescript",
|
|
14
|
+
"library",
|
|
15
|
+
"ui",
|
|
16
|
+
"gohanfromgoku",
|
|
17
|
+
"frontend",
|
|
18
|
+
"web",
|
|
19
|
+
"javascript",
|
|
20
|
+
"ui-components"
|
|
21
|
+
],
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/iamgohanfromgoku/ui-kit.git"
|
|
25
|
+
},
|
|
26
|
+
"author": "GohanfromGoku",
|
|
27
|
+
"license": "MIT",
|
|
13
28
|
"dependencies": {
|
|
14
29
|
"@preact/signals": "^2.5.1",
|
|
15
30
|
"preact": "^10.28.0"
|
package/types/api/index.d.ts
CHANGED
|
@@ -13,7 +13,9 @@ export interface RequestOptions {
|
|
|
13
13
|
}
|
|
14
14
|
export declare class API {
|
|
15
15
|
private baseURL;
|
|
16
|
-
|
|
16
|
+
private defaultHeaders;
|
|
17
|
+
private timeout;
|
|
18
|
+
constructor(baseURL: string, headers?: Record<string, string>, timeout?: number);
|
|
17
19
|
private createURL;
|
|
18
20
|
private request;
|
|
19
21
|
GET: <T = any>(endpoint: string, opts?: RequestOptions) => Promise<T>;
|