recursive-path-finder-regexp
Version:
Search for files or folders by regular expression in the directory where Node was started.
1 lines • 888 B
JavaScript
const fs=require("fs"),path=require("path");module.exports=find=function(t,e){try{let i=process.cwd(),o=void 0,n=void 0,a=[];return"object"==typeof e&&("string"==typeof e.basePath&&(i="/"===e.basePath[0]?e.basePath:path.join(i,e.basePath)),"boolean"==typeof e.isAbsoluteResultsPath&&(o=e.isAbsoluteResultsPath),"boolean"==typeof e.isFile&&(n=e.isFile),Array.isArray(e.exclude)&&(a=a.concat(e.exclude))),findPath(t,i,".",o,n,a)}catch(t){return}},findPath=function(t,e,i,o,n,a){let r=[],s=fs.readdirSync(path.join(e,i),{withFileTypes:!0});return 0===s.length?[]:(s.filter(function(t){let e=path.join(i,t.name);return!a.some(function(t){return t.test(e)})}).forEach(function(s){let h=path.join(i,s.name);if(("boolean"==typeof n&&n!==s.isDirectory()||void 0===n)&&t.test(h)){let t=i;o&&(t=path.join(e,i)),r.push(path.join(t,s.name))}s.isDirectory()&&(r=[...r,...findPath(t,e,h,o,n,a)])}),r)};