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.
21 lines
536 B
TypeScript
21 lines
536 B
TypeScript
import { readdir } from "fs/promises";
|
|
import { resolve } from "path";
|
|
|
|
export async function* walkFiles(dir: string): AsyncGenerator<string> {
|
|
const dirents = await readdir(dir, { withFileTypes: true });
|
|
|
|
for (const dirent of dirents) {
|
|
const res = resolve(dir, dirent.name);
|
|
if (!dirent.name.startsWith(".")) {
|
|
if (dirent.isDirectory()) {
|
|
yield res;
|
|
yield* walkFiles(res);
|
|
} else {
|
|
yield res;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
export const removeExt = (str: string) => str.replace(/\.[^/.]+$/, "");
|