Skip to content

Commit a515559

Browse files
committed
chore: types
1 parent c6ee317 commit a515559

File tree

1 file changed

+38
-17
lines changed

1 file changed

+38
-17
lines changed

util.ts

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export function findBy(...tests: Array<string | RegExp | Predicate<any>>) {
1919
return <A>(xs: A[]) => xs.find(testFn)!;
2020
}
2121

22-
export const fetchText = (path: string) => fetch(path).then((res) => res.text()).catch(() => null);
22+
export const fetchText = (path: string) =>
23+
fetch(path).then((res) => res.text()).catch(() => null);
2324
export const fetchJson = <R>(path: string) =>
2425
fetch(path).then((res) => res.json()).catch(() => null) as Promise<R>;
2526

@@ -81,10 +82,12 @@ const type = (obj: any, access: string): string => {
8182
let ret = "any";
8283
try {
8384
ret = type(obj(), `ReturnType<${access}>`);
84-
} catch (_) { }
85+
} catch (_) {}
8586
return `()=>${ret}`;
8687
}
87-
const identifiers = "abcdefghijklmnopqrstuvwzyz_$".split("").map((i) => `${i}:any`);
88+
const identifiers = "abcdefghijklmnopqrstuvwzyz_$".split("").map((i) =>
89+
`${i}:any`
90+
);
8891
return `(${identifiers.slice(0, obj.length).join(",")})=>any`;
8992
}
9093
case "object": {
@@ -112,12 +115,13 @@ const type = (obj: any, access: string): string => {
112115
}
113116
const blacklist = ["constructor"];
114117
return prototypes.reduce((acc, p) => {
115-
return `${acc}&{${Object.getOwnPropertyNames(p)
116-
.filter((k) => !blacklist.includes(k))
117-
.sort()
118-
.map((k) => `"${k}":${type(obj[k], `${access}["${k}"]`)}`)
119-
.join(";")
120-
}}`;
118+
return `${acc}&{${
119+
Object.getOwnPropertyNames(p)
120+
.filter((k) => !blacklist.includes(k))
121+
.sort()
122+
.map((k) => `"${k}":${type(obj[k], `${access}["${k}"]`)}`)
123+
.join(";")
124+
}}`;
121125
}, "");
122126
}
123127
default:
@@ -136,7 +140,11 @@ const defaultOverride = (curr: any, val: any, key: any) => {
136140
return val;
137141
};
138142

139-
export function deepMerge<T, S>(target: T, source: S, override = defaultOverride): T & S {
143+
export function deepMerge<T, S>(
144+
target: T,
145+
source: S,
146+
override = defaultOverride,
147+
): T & S {
140148
// @ts-ignore
141149
for (const [key, val] of Object.entries(source)) {
142150
// @ts-ignore
@@ -158,7 +166,9 @@ export function deepMerge<T, S>(target: T, source: S, override = defaultOverride
158166
return target;
159167
}
160168

161-
export function stringifyUrlSearchParams(params: Record<string, string | string[]>) {
169+
export function stringifyUrlSearchParams(
170+
params: Record<string, string | string[]>,
171+
) {
162172
const searchParams = new URLSearchParams();
163173
for (const [key, value] of Object.entries(params)) {
164174
if (Array.isArray(value)) {
@@ -175,12 +185,14 @@ export function stringifyUrlSearchParams(params: Record<string, string | string[
175185
export class Transition {
176186
private complete = true;
177187
private promise = Promise.resolve();
178-
constructor() { }
188+
constructor() {}
179189

180190
public extend() {
181191
this.complete = false;
182192
const p = Promise.withResolvers<void>();
183-
this.promise = this.promise.then(() => p.promise).finally(() => this.complete = true);
193+
this.promise = this.promise.then(() => p.promise).finally(() =>
194+
this.complete = true
195+
);
184196
return p.resolve;
185197
}
186198

@@ -208,7 +220,7 @@ const localProxyUrl = new URL(`http://${localProxyHost}/proxy/`);
208220
export const localProxy = (
209221
input: RequestInfo | URL,
210222
init: RequestInit = {},
211-
) => {
223+
): [Request, RequestInit] => {
212224
let url: URL;
213225
if (typeof input === "string") {
214226
url = new URL(input);
@@ -241,7 +253,10 @@ export const localProxy = (
241253
input.duplex = "half";
242254
}
243255

244-
const request = new Request(url, input instanceof Request ? input : undefined);
256+
const request = new Request(
257+
url,
258+
input instanceof Request ? input : undefined,
259+
);
245260
return [request, init];
246261
};
247262

@@ -280,7 +295,10 @@ export const proxy = (
280295
input.duplex = "half";
281296
}
282297

283-
const request = new Request(url, input instanceof Request ? input : undefined);
298+
const request = new Request(
299+
url,
300+
input instanceof Request ? input : undefined,
301+
);
284302
return [request, init];
285303
};
286304

@@ -332,6 +350,9 @@ export const proxy2 = (
332350
input.duplex = "half";
333351
}
334352

335-
const request = new Request(url, input instanceof Request ? input : undefined);
353+
const request = new Request(
354+
url,
355+
input instanceof Request ? input : undefined,
356+
);
336357
return [request, init];
337358
};

0 commit comments

Comments
 (0)