/
utils.ts
41 lines (34 loc) · 811 Bytes
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { gray, lightCyan } from 'kolorist';
const currentTime = () => (new Date()).toLocaleTimeString();
export const log = (...messages: any[]) => console.log(
gray(currentTime()),
lightCyan('[tsx]'),
...messages,
);
// From ansi-escapes
// https://github.com/sindresorhus/ansi-escapes/blob/2b3b59c56ff77a/index.js#L80
export const clearScreen = '\u001Bc';
export function debounce(
originalFunction: () => void,
duration: number,
) {
let timeout: NodeJS.Timeout | undefined;
return () => {
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(
() => originalFunction(),
duration,
);
};
}
export function isDependencyPath(
data: any,
): data is { type: 'dependency'; path: string } {
return (
data
&& typeof data === 'object'
&& data.type === 'dependency'
);
}