taglib-wasm
Version:
TagLib-Wasm is the universal tagging library for TypeScript/JavaScript platforms: Browsers, Node.js, Deno, Bun, Cloudflare Workers, and Electron apps
36 lines (35 loc) • 1.05 kB
JavaScript
import { DEFAULT_AUDIO_EXTENSIONS } from "./types.js";
import { getPlatformIO } from "../runtime/platform-io.js";
import { joinPath as join } from "../utils/path.js";
function extname(path) {
const lastDot = path.lastIndexOf(".");
if (lastDot === -1 || lastDot === path.length - 1) return "";
return path.slice(lastDot);
}
async function* processDirectoryEntry(path, entryName, isDirectory, isFile, options) {
const { recursive = true, extensions = DEFAULT_AUDIO_EXTENSIONS } = options;
const fullPath = join(path, entryName);
if (isDirectory && recursive) {
yield* walkDirectory(fullPath, options);
} else if (isFile) {
const ext = extname(entryName).toLowerCase();
if (extensions.includes(ext)) {
yield fullPath;
}
}
}
async function* walkDirectory(path, options = {}) {
const io = getPlatformIO();
for await (const entry of io.readDir(path)) {
yield* processDirectoryEntry(
path,
entry.name,
entry.isDirectory,
entry.isFile,
options
);
}
}
export {
walkDirectory
};