You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
562 B
TypeScript
23 lines
562 B
TypeScript
2 years ago
|
import { BaseContext } from "koa";
|
||
|
import qs from "qs";
|
||
|
|
||
|
export async function sleep(time: number) {
|
||
|
return new Promise((resolve) => setTimeout(resolve, time));
|
||
|
}
|
||
|
|
||
|
export type Awaited<T> = T extends Promise<infer U> ? U : T;
|
||
|
export type UnwrapArray<T> = T extends Array<infer U> ? U : T;
|
||
|
|
||
|
export function* naturalNumbers(min: number, max: number) {
|
||
|
for (let i = min; i <= max; i++) {
|
||
|
yield i;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export function UrlWithNewParams(
|
||
|
ctx: BaseContext,
|
||
|
query_params: Record<string, unknown>
|
||
|
): string {
|
||
|
return `${ctx.path}?${qs.stringify(query_params)}`;
|
||
|
}
|