Comparing version 10.1.2 to 10.1.3
27
index.js
@@ -16,4 +16,2 @@ import {readdir, stat, lstat} from "node:fs/promises"; | ||
const escRe = str => str.replace(/[|\\{}()[\]^$+*?.-]/g, "\\$&"); | ||
function makePath(entry, dir, encoding) { | ||
@@ -36,12 +34,21 @@ if (encoding === "buffer") { | ||
export function pathGlobToRegex(glob, {flags = undefined, sep = "/"} = {flags: undefined, sep: "/"}) { | ||
if (sep === "\\") sep = "\\\\"; | ||
return new RegExp(`${glob | ||
.replace(/[|\\{}()[\]^$+.-]/g, "\\$&") | ||
.replace(new RegExp(`\\*\\*${sep}\\*`, "g"), ".*") | ||
.replace(/^\*\*/g, ".*") | ||
.replace(new RegExp(`${sep}?\\*\\*$`, "g"), ".*") | ||
.replace(new RegExp(`(${sep})\\*\\*(${sep})`, "g"), (_, p1, p2) => `${p1}.*${p2}`) | ||
.replace(/([^.])\*/g, (_, p1) => `${p1}[^${sep}]*`) | ||
.replaceAll("**", "*") | ||
.replaceAll("?", ".") | ||
}$`, flags); | ||
} | ||
function makeMatcher(filters, flags) { | ||
const res = filters.map(f => { | ||
return new RegExp(`${escRe(f) | ||
.replace(/\\\*+/g, ".*") | ||
.replace(/\/\.\*/, ".*") | ||
.replace(/(\.\*){2,}/, ".*")}$`, flags); | ||
}); | ||
const regexes = filters.map(filter => pathGlobToRegex(filter, {flags, sep})); | ||
return str => { | ||
for (const re of res) { | ||
if (re.test(str)) return true; | ||
for (const regex of regexes) { | ||
if (regex.test(str)) return true; | ||
} | ||
@@ -48,0 +55,0 @@ return false; |
{ | ||
"name": "rrdir", | ||
"version": "10.1.2", | ||
"version": "10.1.3", | ||
"description": "Recursive directory reader with a delightful API", | ||
@@ -5,0 +5,0 @@ "author": "silverwind <me@silverwind.io>", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11547
186