UNPKG

use-fs-access

Version:

A React hook that builds on top of the File System Access API to enable easy file and directory operations in modern browsers.

38 lines (37 loc) 1.14 kB
import ignore from "ignore"; export const gitIgnoreFilter = async () => { const ig = ignore({ allowRelativePaths: true, }); let isGitIgnoreLoaded = false; return { ignore: async (path, handle) => { if (path.endsWith(".gitignore") && !isGitIgnoreLoaded && handle.kind === "file") { const file = await handle.getFile(); const text = await file.text(); ig.add(text); isGitIgnoreLoaded = true; return false; } if (handle.kind === "directory" && (path.endsWith(".git") || path.endsWith(".git/"))) { return false; } const { ignored } = ig.test(path); return ignored; }, }; }; export const gitFolderFilter = async () => { return { ignore: async (path, handle) => { if (handle.kind === "directory" && (path.endsWith(".git") || path.endsWith(".git/"))) { return true; } return false; }, }; };