forked from zhmushan/dev_server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.ts
More file actions
28 lines (25 loc) · 620 Bytes
/
util.ts
File metadata and controls
28 lines (25 loc) · 620 Bytes
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
import type { DirMetadata } from "./types.ts";
import { path } from "./deps.ts";
const { readDir } = Deno;
const { join } = path;
export async function resolveDir(p: string): Promise<DirMetadata> {
const m: DirMetadata = {};
for await (const entry of readDir(p)) {
m[entry.name] = entry.isDirectory
? await resolveDir(join(p, entry.name))
: 1;
}
return m;
}
export function debounce<T extends unknown[]>(
cb: (...args: T) => void,
ms: number,
) {
let timer: number;
return (...args: T) => {
clearTimeout(timer);
timer = setTimeout(() => {
cb(...args);
}, ms);
};
}