2023-04-08 05:20:27 +00:00
|
|
|
export function sleep(milliseconds: number) {
|
|
|
|
|
return new Promise((r) => setTimeout(r, milliseconds));
|
|
|
|
|
}
|
2023-04-13 13:57:14 +00:00
|
|
|
|
2023-05-24 01:50:57 +00:00
|
|
|
export function splitLines(input: string) {
|
|
|
|
|
return input.match(/.*(?:$|\r?\n)/g).filter(Boolean) // Split lines and keep newline character
|
2023-04-13 13:57:14 +00:00
|
|
|
}
|
2023-05-29 02:09:44 +00:00
|
|
|
|
|
|
|
|
export function splitWords(input: string) {
|
|
|
|
|
return input.match(/\w+|\W+/g).filter(Boolean); // Split consecutive words and non-words
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-02 03:58:34 +00:00
|
|
|
export function isBlank(input: string) {
|
|
|
|
|
return input.trim().length === 0;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-29 02:09:44 +00:00
|
|
|
import { CancelablePromise } from "./generated";
|
|
|
|
|
export function cancelable<T>(promise: Promise<T>, cancel: () => void): CancelablePromise<T> {
|
|
|
|
|
return new CancelablePromise((resolve, reject, onCancel) => {
|
|
|
|
|
promise
|
|
|
|
|
.then((resp: T) => {
|
|
|
|
|
resolve(resp);
|
|
|
|
|
})
|
|
|
|
|
.catch((err: Error) => {
|
|
|
|
|
reject(err);
|
|
|
|
|
});
|
|
|
|
|
onCancel(() => {
|
|
|
|
|
cancel();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|