Skip to content

Commit

Permalink
generate ignore regexes just once
Browse files Browse the repository at this point in the history
  • Loading branch information
rafapaezbas committed Jan 20, 2025
1 parent dbc88d6 commit e29ebc1
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,12 @@ module.exports = class Localdrive {
for await (const dirent of iterator) {
const key = unixPathResolve(keyname, dirent.name)

if (ignored(ignore, key)) continue
const regexes = ignore.map(e => {
const pattern = `^${e.replace(/\*/g, '[^/]+')}$`
return new RegExp(pattern)
})

if (ignored(regexes, key)) continue

let isDirectory = dirent.isDirectory()

Expand Down Expand Up @@ -370,10 +375,8 @@ async function isEmptyDirectory (drive, key) {
return true
}

function ignored (ignore, key) {
return ignore.some(e => {
const pattern = `^${e.replace(/\*/g, '[^/]+')}$`
const regex = new RegExp(pattern)
function ignored (regexes, key) {
return regexes.some(regex => {
return regex.test(key)
})
}

0 comments on commit e29ebc1

Please sign in to comment.