UNPKG

scandog

Version:
22 lines 823 B
import fs from 'node:fs'; import { parse } from 'node:path'; import * as globby from 'globby'; export const isTargetPath = (suffix) => (path) => { const { name } = parse(path); return !name.endsWith(suffix); }; export function getWithSuffix(path, suffix) { const { dir, name, ext } = parse(path); if (dir === '') return `${name}${suffix}${ext}`; return `${dir}/${name}${suffix}${ext}`; } const scan = (suffix, patterns, options, globbySync = globby.globbySync, existsSync = fs.existsSync) => { const paths = globbySync(patterns, options).filter(isTargetPath(suffix)); return paths.map((path) => { const withSuffix = getWithSuffix(path, suffix); return { path, withSuffix, exists: existsSync(withSuffix) }; }); }; export default scan; //# sourceMappingURL=index.js.map