Comparing version 4.8.0 to 5.0.0
@@ -5,67 +5,160 @@ // builtin | ||
// external | ||
import ignorePatterns from 'https://unpkg.com/ignorepatterns@^5.6.0/edition-deno/index.ts' | ||
import undesiredBasenamesRegExp from 'https://unpkg.com/ignorepatterns@^5.6.0/edition-deno/index.ts' | ||
/** A path to check its ignore status */ | ||
export interface Path { | ||
/** The absolute path, if any */ | ||
absolutePath?: string | ||
/** The relative path, if any */ | ||
relativePath?: string | ||
/** If not provided, will be determined from {@link absolutePath}/{@link relativePath} */ | ||
basename?: string | ||
} | ||
/** Ignore Options */ | ||
export interface Options { | ||
/** An optional listing of full paths to ignore */ | ||
ignorePaths?: false | Array<string> | ||
/** Wether or not to ignore basenames beginning with a `.` character */ | ||
/** Absolute paths to ignore */ | ||
ignoreAbsolutePaths?: Array<string | RegExp> | ||
/** Relative paths to ignore */ | ||
ignoreRelativePaths?: Array<string | RegExp> | ||
/** Basenames to ignore */ | ||
ignoreBasenames?: Array<string | RegExp> | ||
/** @deprecated alias for {@link ignoreAbsolutePaths}, {@link ignoreRelativePaths}, and {@link ignoreBasenames} */ | ||
ignorePaths?: Array<string | RegExp> | ||
/** Ignore basenames that begin with a `.` character */ | ||
ignoreHiddenBasenames?: boolean | ||
/** @deprecated alias for {@link Options.ignoreHiddenBasenames} */ | ||
ignoreHiddenFiles?: boolean | ||
/** If true, will check the path and basename of the path against https://github.com/bevry/ignorepatterns */ | ||
ignoreCommonPatterns?: boolean | RegExp | ||
/** If a regular expression, will test the regular expression against the path and basename of the path */ | ||
ignoreCustomPatterns?: false | RegExp | ||
/** Ignore commonly undesirable basenames: https://github.com/bevry/ignorepatterns */ | ||
ignoreUndesiredBasenames?: boolean | ||
/** @deprecated alias for {@link Options.ignoreUndesiredBasenames} */ | ||
ignoreCommonPatterns?: boolean | ||
/** Test against each {@link Path} property */ | ||
ignoreCustomPatterns?: RegExp | ||
/** Your own ignore handler */ | ||
ignoreCustomCallback?: (path: Path) => boolean | void | ||
} | ||
/** | ||
* Is Ignored Path | ||
* Check to see if a path, either a full path or basename, should be ignored | ||
* @param path full path or basename of a file or directory | ||
* @param opts configuration options | ||
* @returns whether or not the path should be ignored | ||
*/ | ||
export function isIgnoredPath(path: string, opts: Options = {}) { | ||
// Prepare | ||
const basename = getBasename(path) | ||
/** Tests the path against provided prefixes and regular expressions */ | ||
function matches(path: string, matches: Array<string | RegExp>): boolean { | ||
for (const match of matches) { | ||
if (typeof match === 'string') { | ||
if (path.startsWith(match)) return true | ||
} else if (match.test(path)) return true | ||
} | ||
return false | ||
} | ||
// Test Paths | ||
if (opts.ignorePaths) { | ||
for (let i = 0; i < opts.ignorePaths.length; ++i) { | ||
const ignorePath = opts.ignorePaths[i] | ||
if (path.indexOf(ignorePath) === 0) { | ||
return true | ||
} | ||
} | ||
/** Tests whether the path should be ignored */ | ||
export function isIgnoredPath( | ||
path: Path, | ||
opts: Options = { | ||
ignoreCommonPatterns: true, | ||
} | ||
) { | ||
// handle deprecations | ||
opts = { | ||
ignoreHiddenBasenames: opts.ignoreHiddenFiles, | ||
ignoreUndesiredBasenames: opts.ignoreCommonPatterns, | ||
...opts, | ||
ignoreAbsolutePaths: [ | ||
...(opts.ignoreAbsolutePaths || []), | ||
...(opts.ignorePaths || []), | ||
], | ||
ignoreRelativePaths: [ | ||
...(opts.ignoreRelativePaths || []), | ||
...(opts.ignorePaths || []), | ||
], | ||
ignoreBasenames: [ | ||
...(opts.ignoreBasenames || []), | ||
...(opts.ignorePaths || []), | ||
], | ||
} | ||
// Test Hidden Files | ||
if (opts.ignoreHiddenFiles && basename[0] === '.') { | ||
// extract path, fallback basename, and reconstruct path with its custom properties if any (helpful for scandirectory) | ||
const { absolutePath, relativePath } = path | ||
let { basename } = path | ||
if (!basename && (absolutePath || relativePath)) | ||
basename = getBasename(absolutePath || relativePath || '') | ||
path = { ...path, basename } | ||
// custom callback | ||
if (opts.ignoreCustomCallback && opts.ignoreCustomCallback(path) === true) | ||
return true | ||
// absolute path checks | ||
if (absolutePath) { | ||
// match | ||
if ( | ||
opts.ignoreAbsolutePaths?.length && | ||
matches(absolutePath, opts.ignoreAbsolutePaths) | ||
) | ||
return true | ||
// custom? | ||
if ( | ||
opts.ignoreCustomPatterns && | ||
opts.ignoreCustomPatterns.test(absolutePath) | ||
) | ||
return true | ||
} | ||
// Test Common Patterns | ||
if (opts.ignoreCommonPatterns == null || opts.ignoreCommonPatterns === true) { | ||
return ( | ||
ignorePatterns.test(path) || | ||
(path !== basename && ignorePatterns.test(basename)) | ||
// relative path checks | ||
if (relativePath) { | ||
// match | ||
if ( | ||
opts.ignoreRelativePaths?.length && | ||
matches(relativePath, opts.ignoreRelativePaths) | ||
) | ||
} else if (opts.ignoreCommonPatterns) { | ||
const ignoreCommonPatterns /* :RegExp */ = opts.ignoreCommonPatterns | ||
return ( | ||
ignoreCommonPatterns.test(path) || | ||
(path !== basename && ignoreCommonPatterns.test(basename)) | ||
return true | ||
// custom? | ||
if ( | ||
opts.ignoreCustomPatterns && | ||
opts.ignoreCustomPatterns.test(relativePath) | ||
) | ||
return true | ||
} | ||
// Test Custom Patterns | ||
if (opts.ignoreCustomPatterns) { | ||
const ignoreCustomPatterns /* :RegExp */ = opts.ignoreCustomPatterns | ||
return ( | ||
ignoreCustomPatterns.test(path) || | ||
(path !== basename && ignoreCustomPatterns.test(basename)) | ||
// basename checks | ||
if (basename) { | ||
// match | ||
if (opts.ignoreBasenames?.length && matches(basename, opts.ignoreBasenames)) | ||
return true | ||
// hidden? | ||
if (opts.ignoreHiddenBasenames && basename[0] === '.') return true | ||
// common? | ||
if ( | ||
opts.ignoreUndesiredBasenames && | ||
undesiredBasenamesRegExp.test(basename) | ||
) | ||
return true | ||
// custom? | ||
if (opts.ignoreCustomPatterns && opts.ignoreCustomPatterns.test(basename)) | ||
return true | ||
} | ||
// Return | ||
// not ignored | ||
return false | ||
} | ||
/** Compatibility wrapper for {@link isIgnoredPath} */ | ||
export default function isIgnoredPathCompatibility( | ||
path: Path | string, | ||
opts?: Options | ||
) { | ||
if (typeof path === 'string') | ||
path = { | ||
absolutePath: path, | ||
relativePath: path, | ||
basename: getBasename(path), | ||
} | ||
return isIgnoredPath(path, opts) | ||
} |
// builtin | ||
import { basename as getBasename } from 'path'; | ||
// external | ||
import ignorePatterns from 'ignorepatterns'; | ||
/** | ||
* Is Ignored Path | ||
* Check to see if a path, either a full path or basename, should be ignored | ||
* @param path full path or basename of a file or directory | ||
* @param opts configuration options | ||
* @returns whether or not the path should be ignored | ||
*/ | ||
export function isIgnoredPath(path, opts = {}) { | ||
// Prepare | ||
const basename = getBasename(path); | ||
// Test Paths | ||
if (opts.ignorePaths) { | ||
for (let i = 0; i < opts.ignorePaths.length; ++i) { | ||
const ignorePath = opts.ignorePaths[i]; | ||
if (path.indexOf(ignorePath) === 0) { | ||
import undesiredBasenamesRegExp from 'ignorepatterns'; | ||
/** Tests the path against provided prefixes and regular expressions */ | ||
function matches(path, matches) { | ||
for (const match of matches) { | ||
if (typeof match === 'string') { | ||
if (path.startsWith(match)) | ||
return true; | ||
} | ||
} | ||
else if (match.test(path)) | ||
return true; | ||
} | ||
// Test Hidden Files | ||
if (opts.ignoreHiddenFiles && basename[0] === '.') { | ||
return false; | ||
} | ||
/** Tests whether the path should be ignored */ | ||
export function isIgnoredPath(path, opts = { | ||
ignoreCommonPatterns: true, | ||
}) { | ||
// handle deprecations | ||
opts = { | ||
ignoreHiddenBasenames: opts.ignoreHiddenFiles, | ||
ignoreUndesiredBasenames: opts.ignoreCommonPatterns, | ||
...opts, | ||
ignoreAbsolutePaths: [ | ||
...(opts.ignoreAbsolutePaths || []), | ||
...(opts.ignorePaths || []), | ||
], | ||
ignoreRelativePaths: [ | ||
...(opts.ignoreRelativePaths || []), | ||
...(opts.ignorePaths || []), | ||
], | ||
ignoreBasenames: [ | ||
...(opts.ignoreBasenames || []), | ||
...(opts.ignorePaths || []), | ||
], | ||
}; | ||
// extract path, fallback basename, and reconstruct path with its custom properties if any (helpful for scandirectory) | ||
const { absolutePath, relativePath } = path; | ||
let { basename } = path; | ||
if (!basename && (absolutePath || relativePath)) | ||
basename = getBasename(absolutePath || relativePath || ''); | ||
path = { ...path, basename }; | ||
// custom callback | ||
if (opts.ignoreCustomCallback && opts.ignoreCustomCallback(path) === true) | ||
return true; | ||
// absolute path checks | ||
if (absolutePath) { | ||
// match | ||
if (opts.ignoreAbsolutePaths?.length && | ||
matches(absolutePath, opts.ignoreAbsolutePaths)) | ||
return true; | ||
// custom? | ||
if (opts.ignoreCustomPatterns && | ||
opts.ignoreCustomPatterns.test(absolutePath)) | ||
return true; | ||
} | ||
// Test Common Patterns | ||
if (opts.ignoreCommonPatterns == null || opts.ignoreCommonPatterns === true) { | ||
return (ignorePatterns.test(path) || | ||
(path !== basename && ignorePatterns.test(basename))); | ||
// relative path checks | ||
if (relativePath) { | ||
// match | ||
if (opts.ignoreRelativePaths?.length && | ||
matches(relativePath, opts.ignoreRelativePaths)) | ||
return true; | ||
// custom? | ||
if (opts.ignoreCustomPatterns && | ||
opts.ignoreCustomPatterns.test(relativePath)) | ||
return true; | ||
} | ||
else if (opts.ignoreCommonPatterns) { | ||
const ignoreCommonPatterns /* :RegExp */ = opts.ignoreCommonPatterns; | ||
return (ignoreCommonPatterns.test(path) || | ||
(path !== basename && ignoreCommonPatterns.test(basename))); | ||
// basename checks | ||
if (basename) { | ||
// match | ||
if (opts.ignoreBasenames?.length && matches(basename, opts.ignoreBasenames)) | ||
return true; | ||
// hidden? | ||
if (opts.ignoreHiddenBasenames && basename[0] === '.') | ||
return true; | ||
// common? | ||
if (opts.ignoreUndesiredBasenames && | ||
undesiredBasenamesRegExp.test(basename)) | ||
return true; | ||
// custom? | ||
if (opts.ignoreCustomPatterns && opts.ignoreCustomPatterns.test(basename)) | ||
return true; | ||
} | ||
// Test Custom Patterns | ||
if (opts.ignoreCustomPatterns) { | ||
const ignoreCustomPatterns /* :RegExp */ = opts.ignoreCustomPatterns; | ||
return (ignoreCustomPatterns.test(path) || | ||
(path !== basename && ignoreCustomPatterns.test(basename))); | ||
} | ||
// Return | ||
// not ignored | ||
return false; | ||
} | ||
/** Compatibility wrapper for {@link isIgnoredPath} */ | ||
export default function isIgnoredPathCompatibility(path, opts) { | ||
if (typeof path === 'string') | ||
path = { | ||
absolutePath: path, | ||
relativePath: path, | ||
basename: getBasename(path), | ||
}; | ||
return isIgnoredPath(path, opts); | ||
} |
@@ -11,44 +11,97 @@ "use strict"; | ||
const ignorepatterns_1 = __importDefault(require("ignorepatterns")); | ||
/** | ||
* Is Ignored Path | ||
* Check to see if a path, either a full path or basename, should be ignored | ||
* @param path full path or basename of a file or directory | ||
* @param opts configuration options | ||
* @returns whether or not the path should be ignored | ||
*/ | ||
function isIgnoredPath(path, opts = {}) { | ||
// Prepare | ||
const basename = (0, path_1.basename)(path); | ||
// Test Paths | ||
if (opts.ignorePaths) { | ||
for (let i = 0; i < opts.ignorePaths.length; ++i) { | ||
const ignorePath = opts.ignorePaths[i]; | ||
if (path.indexOf(ignorePath) === 0) { | ||
/** Tests the path against provided prefixes and regular expressions */ | ||
function matches(path, matches) { | ||
for (const match of matches) { | ||
if (typeof match === 'string') { | ||
if (path.startsWith(match)) | ||
return true; | ||
} | ||
} | ||
else if (match.test(path)) | ||
return true; | ||
} | ||
// Test Hidden Files | ||
if (opts.ignoreHiddenFiles && basename[0] === '.') { | ||
return false; | ||
} | ||
/** Tests whether the path should be ignored */ | ||
function isIgnoredPath(path, opts = { | ||
ignoreCommonPatterns: true, | ||
}) { | ||
// handle deprecations | ||
opts = { | ||
ignoreHiddenBasenames: opts.ignoreHiddenFiles, | ||
ignoreUndesiredBasenames: opts.ignoreCommonPatterns, | ||
...opts, | ||
ignoreAbsolutePaths: [ | ||
...(opts.ignoreAbsolutePaths || []), | ||
...(opts.ignorePaths || []), | ||
], | ||
ignoreRelativePaths: [ | ||
...(opts.ignoreRelativePaths || []), | ||
...(opts.ignorePaths || []), | ||
], | ||
ignoreBasenames: [ | ||
...(opts.ignoreBasenames || []), | ||
...(opts.ignorePaths || []), | ||
], | ||
}; | ||
// extract path, fallback basename, and reconstruct path with its custom properties if any (helpful for scandirectory) | ||
const { absolutePath, relativePath } = path; | ||
let { basename } = path; | ||
if (!basename && (absolutePath || relativePath)) | ||
basename = (0, path_1.basename)(absolutePath || relativePath || ''); | ||
path = { ...path, basename }; | ||
// custom callback | ||
if (opts.ignoreCustomCallback && opts.ignoreCustomCallback(path) === true) | ||
return true; | ||
// absolute path checks | ||
if (absolutePath) { | ||
// match | ||
if (opts.ignoreAbsolutePaths?.length && | ||
matches(absolutePath, opts.ignoreAbsolutePaths)) | ||
return true; | ||
// custom? | ||
if (opts.ignoreCustomPatterns && | ||
opts.ignoreCustomPatterns.test(absolutePath)) | ||
return true; | ||
} | ||
// Test Common Patterns | ||
if (opts.ignoreCommonPatterns == null || opts.ignoreCommonPatterns === true) { | ||
return (ignorepatterns_1.default.test(path) || | ||
(path !== basename && ignorepatterns_1.default.test(basename))); | ||
// relative path checks | ||
if (relativePath) { | ||
// match | ||
if (opts.ignoreRelativePaths?.length && | ||
matches(relativePath, opts.ignoreRelativePaths)) | ||
return true; | ||
// custom? | ||
if (opts.ignoreCustomPatterns && | ||
opts.ignoreCustomPatterns.test(relativePath)) | ||
return true; | ||
} | ||
else if (opts.ignoreCommonPatterns) { | ||
const ignoreCommonPatterns /* :RegExp */ = opts.ignoreCommonPatterns; | ||
return (ignoreCommonPatterns.test(path) || | ||
(path !== basename && ignoreCommonPatterns.test(basename))); | ||
// basename checks | ||
if (basename) { | ||
// match | ||
if (opts.ignoreBasenames?.length && matches(basename, opts.ignoreBasenames)) | ||
return true; | ||
// hidden? | ||
if (opts.ignoreHiddenBasenames && basename[0] === '.') | ||
return true; | ||
// common? | ||
if (opts.ignoreUndesiredBasenames && | ||
ignorepatterns_1.default.test(basename)) | ||
return true; | ||
// custom? | ||
if (opts.ignoreCustomPatterns && opts.ignoreCustomPatterns.test(basename)) | ||
return true; | ||
} | ||
// Test Custom Patterns | ||
if (opts.ignoreCustomPatterns) { | ||
const ignoreCustomPatterns /* :RegExp */ = opts.ignoreCustomPatterns; | ||
return (ignoreCustomPatterns.test(path) || | ||
(path !== basename && ignoreCustomPatterns.test(basename))); | ||
} | ||
// Return | ||
// not ignored | ||
return false; | ||
} | ||
exports.isIgnoredPath = isIgnoredPath; | ||
/** Compatibility wrapper for {@link isIgnoredPath} */ | ||
function isIgnoredPathCompatibility(path, opts) { | ||
if (typeof path === 'string') | ||
path = { | ||
absolutePath: path, | ||
relativePath: path, | ||
basename: (0, path_1.basename)(path), | ||
}; | ||
return isIgnoredPath(path, opts); | ||
} | ||
exports.default = isIgnoredPathCompatibility; |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __values = (this && this.__values) || function(o) { | ||
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; | ||
if (m) return m.call(o); | ||
if (o && typeof o.length === "number") return { | ||
next: function () { | ||
if (o && i >= o.length) o = void 0; | ||
return { value: o && o[i++], done: !o }; | ||
} | ||
}; | ||
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); | ||
}; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -11,45 +58,94 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
var ignorepatterns_1 = __importDefault(require("ignorepatterns")); | ||
/** | ||
* Is Ignored Path | ||
* Check to see if a path, either a full path or basename, should be ignored | ||
* @param path full path or basename of a file or directory | ||
* @param opts configuration options | ||
* @returns whether or not the path should be ignored | ||
*/ | ||
function isIgnoredPath(path, opts) { | ||
if (opts === void 0) { opts = {}; } | ||
// Prepare | ||
var basename = (0, path_1.basename)(path); | ||
// Test Paths | ||
if (opts.ignorePaths) { | ||
for (var i = 0; i < opts.ignorePaths.length; ++i) { | ||
var ignorePath = opts.ignorePaths[i]; | ||
if (path.indexOf(ignorePath) === 0) { | ||
/** Tests the path against provided prefixes and regular expressions */ | ||
function matches(path, matches) { | ||
var e_1, _a; | ||
try { | ||
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) { | ||
var match = matches_1_1.value; | ||
if (typeof match === 'string') { | ||
if (path.startsWith(match)) | ||
return true; | ||
} | ||
else if (match.test(path)) | ||
return true; | ||
} | ||
} | ||
} | ||
// Test Hidden Files | ||
if (opts.ignoreHiddenFiles && basename[0] === '.') { | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
return false; | ||
} | ||
/** Tests whether the path should be ignored */ | ||
function isIgnoredPath(path, opts) { | ||
var _a, _b, _c; | ||
if (opts === void 0) { opts = { | ||
ignoreCommonPatterns: true, | ||
}; } | ||
// handle deprecations | ||
opts = __assign(__assign({ ignoreHiddenBasenames: opts.ignoreHiddenFiles, ignoreUndesiredBasenames: opts.ignoreCommonPatterns }, opts), { ignoreAbsolutePaths: __spreadArray(__spreadArray([], __read((opts.ignoreAbsolutePaths || [])), false), __read((opts.ignorePaths || [])), false), ignoreRelativePaths: __spreadArray(__spreadArray([], __read((opts.ignoreRelativePaths || [])), false), __read((opts.ignorePaths || [])), false), ignoreBasenames: __spreadArray(__spreadArray([], __read((opts.ignoreBasenames || [])), false), __read((opts.ignorePaths || [])), false) }); | ||
// extract path, fallback basename, and reconstruct path with its custom properties if any (helpful for scandirectory) | ||
var absolutePath = path.absolutePath, relativePath = path.relativePath; | ||
var basename = path.basename; | ||
if (!basename && (absolutePath || relativePath)) | ||
basename = (0, path_1.basename)(absolutePath || relativePath || ''); | ||
path = __assign(__assign({}, path), { basename: basename }); | ||
// custom callback | ||
if (opts.ignoreCustomCallback && opts.ignoreCustomCallback(path) === true) | ||
return true; | ||
// absolute path checks | ||
if (absolutePath) { | ||
// match | ||
if (((_a = opts.ignoreAbsolutePaths) === null || _a === void 0 ? void 0 : _a.length) && | ||
matches(absolutePath, opts.ignoreAbsolutePaths)) | ||
return true; | ||
// custom? | ||
if (opts.ignoreCustomPatterns && | ||
opts.ignoreCustomPatterns.test(absolutePath)) | ||
return true; | ||
} | ||
// Test Common Patterns | ||
if (opts.ignoreCommonPatterns == null || opts.ignoreCommonPatterns === true) { | ||
return (ignorepatterns_1.default.test(path) || | ||
(path !== basename && ignorepatterns_1.default.test(basename))); | ||
// relative path checks | ||
if (relativePath) { | ||
// match | ||
if (((_b = opts.ignoreRelativePaths) === null || _b === void 0 ? void 0 : _b.length) && | ||
matches(relativePath, opts.ignoreRelativePaths)) | ||
return true; | ||
// custom? | ||
if (opts.ignoreCustomPatterns && | ||
opts.ignoreCustomPatterns.test(relativePath)) | ||
return true; | ||
} | ||
else if (opts.ignoreCommonPatterns) { | ||
var ignoreCommonPatterns /* :RegExp */ = opts.ignoreCommonPatterns; | ||
return (ignoreCommonPatterns.test(path) || | ||
(path !== basename && ignoreCommonPatterns.test(basename))); | ||
// basename checks | ||
if (basename) { | ||
// match | ||
if (((_c = opts.ignoreBasenames) === null || _c === void 0 ? void 0 : _c.length) && matches(basename, opts.ignoreBasenames)) | ||
return true; | ||
// hidden? | ||
if (opts.ignoreHiddenBasenames && basename[0] === '.') | ||
return true; | ||
// common? | ||
if (opts.ignoreUndesiredBasenames && | ||
ignorepatterns_1.default.test(basename)) | ||
return true; | ||
// custom? | ||
if (opts.ignoreCustomPatterns && opts.ignoreCustomPatterns.test(basename)) | ||
return true; | ||
} | ||
// Test Custom Patterns | ||
if (opts.ignoreCustomPatterns) { | ||
var ignoreCustomPatterns /* :RegExp */ = opts.ignoreCustomPatterns; | ||
return (ignoreCustomPatterns.test(path) || | ||
(path !== basename && ignoreCustomPatterns.test(basename))); | ||
} | ||
// Return | ||
// not ignored | ||
return false; | ||
} | ||
exports.isIgnoredPath = isIgnoredPath; | ||
/** Compatibility wrapper for {@link isIgnoredPath} */ | ||
function isIgnoredPathCompatibility(path, opts) { | ||
if (typeof path === 'string') | ||
path = { | ||
absolutePath: path, | ||
relativePath: path, | ||
basename: (0, path_1.basename)(path), | ||
}; | ||
return isIgnoredPath(path, opts); | ||
} | ||
exports.default = isIgnoredPathCompatibility; |
@@ -0,20 +1,37 @@ | ||
/** A path to check its ignore status */ | ||
export interface Path { | ||
/** The absolute path, if any */ | ||
absolutePath?: string; | ||
/** The relative path, if any */ | ||
relativePath?: string; | ||
/** If not provided, will be determined from {@link absolutePath}/{@link relativePath} */ | ||
basename?: string; | ||
} | ||
/** Ignore Options */ | ||
export interface Options { | ||
/** An optional listing of full paths to ignore */ | ||
ignorePaths?: false | Array<string>; | ||
/** Wether or not to ignore basenames beginning with a `.` character */ | ||
/** Absolute paths to ignore */ | ||
ignoreAbsolutePaths?: Array<string | RegExp>; | ||
/** Relative paths to ignore */ | ||
ignoreRelativePaths?: Array<string | RegExp>; | ||
/** Basenames to ignore */ | ||
ignoreBasenames?: Array<string | RegExp>; | ||
/** @deprecated alias for {@link ignoreAbsolutePaths}, {@link ignoreRelativePaths}, and {@link ignoreBasenames} */ | ||
ignorePaths?: Array<string | RegExp>; | ||
/** Ignore basenames that begin with a `.` character */ | ||
ignoreHiddenBasenames?: boolean; | ||
/** @deprecated alias for {@link Options.ignoreHiddenBasenames} */ | ||
ignoreHiddenFiles?: boolean; | ||
/** If true, will check the path and basename of the path against https://github.com/bevry/ignorepatterns */ | ||
ignoreCommonPatterns?: boolean | RegExp; | ||
/** If a regular expression, will test the regular expression against the path and basename of the path */ | ||
ignoreCustomPatterns?: false | RegExp; | ||
/** Ignore commonly undesirable basenames: https://github.com/bevry/ignorepatterns */ | ||
ignoreUndesiredBasenames?: boolean; | ||
/** @deprecated alias for {@link Options.ignoreUndesiredBasenames} */ | ||
ignoreCommonPatterns?: boolean; | ||
/** Test against each {@link Path} property */ | ||
ignoreCustomPatterns?: RegExp; | ||
/** Your own ignore handler */ | ||
ignoreCustomCallback?: (path: Path) => boolean | void; | ||
} | ||
/** | ||
* Is Ignored Path | ||
* Check to see if a path, either a full path or basename, should be ignored | ||
* @param path full path or basename of a file or directory | ||
* @param opts configuration options | ||
* @returns whether or not the path should be ignored | ||
*/ | ||
export declare function isIgnoredPath(path: string, opts?: Options): boolean; | ||
/** Tests whether the path should be ignored */ | ||
export declare function isIgnoredPath(path: Path, opts?: Options): boolean; | ||
/** Compatibility wrapper for {@link isIgnoredPath} */ | ||
export default function isIgnoredPathCompatibility(path: Path | string, opts?: Options): boolean; | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"title": "IgnoreFS", | ||
"name": "ignorefs", | ||
"version": "4.8.0", | ||
"version": "5.0.0", | ||
"license": "Artistic-2.0", | ||
@@ -6,0 +6,0 @@ "description": "Ignore common and custom patterns of the file system", |
@@ -51,3 +51,3 @@ <!-- TITLE/ --> | ||
``` typescript | ||
import * as pkg from 'https://unpkg.com/ignorefs@^4.8.0/edition-deno/index.ts' | ||
import * as pkg from 'https://unpkg.com/ignorefs@^5.0.0/edition-deno/index.ts' | ||
``` | ||
@@ -54,0 +54,0 @@ ### [Editions](https://editions.bevry.me "Editions are the best way to produce and consume packages you care about.") |
@@ -5,67 +5,160 @@ // builtin | ||
// external | ||
import ignorePatterns from 'ignorepatterns' | ||
import undesiredBasenamesRegExp from 'ignorepatterns' | ||
/** A path to check its ignore status */ | ||
export interface Path { | ||
/** The absolute path, if any */ | ||
absolutePath?: string | ||
/** The relative path, if any */ | ||
relativePath?: string | ||
/** If not provided, will be determined from {@link absolutePath}/{@link relativePath} */ | ||
basename?: string | ||
} | ||
/** Ignore Options */ | ||
export interface Options { | ||
/** An optional listing of full paths to ignore */ | ||
ignorePaths?: false | Array<string> | ||
/** Wether or not to ignore basenames beginning with a `.` character */ | ||
/** Absolute paths to ignore */ | ||
ignoreAbsolutePaths?: Array<string | RegExp> | ||
/** Relative paths to ignore */ | ||
ignoreRelativePaths?: Array<string | RegExp> | ||
/** Basenames to ignore */ | ||
ignoreBasenames?: Array<string | RegExp> | ||
/** @deprecated alias for {@link ignoreAbsolutePaths}, {@link ignoreRelativePaths}, and {@link ignoreBasenames} */ | ||
ignorePaths?: Array<string | RegExp> | ||
/** Ignore basenames that begin with a `.` character */ | ||
ignoreHiddenBasenames?: boolean | ||
/** @deprecated alias for {@link Options.ignoreHiddenBasenames} */ | ||
ignoreHiddenFiles?: boolean | ||
/** If true, will check the path and basename of the path against https://github.com/bevry/ignorepatterns */ | ||
ignoreCommonPatterns?: boolean | RegExp | ||
/** If a regular expression, will test the regular expression against the path and basename of the path */ | ||
ignoreCustomPatterns?: false | RegExp | ||
/** Ignore commonly undesirable basenames: https://github.com/bevry/ignorepatterns */ | ||
ignoreUndesiredBasenames?: boolean | ||
/** @deprecated alias for {@link Options.ignoreUndesiredBasenames} */ | ||
ignoreCommonPatterns?: boolean | ||
/** Test against each {@link Path} property */ | ||
ignoreCustomPatterns?: RegExp | ||
/** Your own ignore handler */ | ||
ignoreCustomCallback?: (path: Path) => boolean | void | ||
} | ||
/** | ||
* Is Ignored Path | ||
* Check to see if a path, either a full path or basename, should be ignored | ||
* @param path full path or basename of a file or directory | ||
* @param opts configuration options | ||
* @returns whether or not the path should be ignored | ||
*/ | ||
export function isIgnoredPath(path: string, opts: Options = {}) { | ||
// Prepare | ||
const basename = getBasename(path) | ||
/** Tests the path against provided prefixes and regular expressions */ | ||
function matches(path: string, matches: Array<string | RegExp>): boolean { | ||
for (const match of matches) { | ||
if (typeof match === 'string') { | ||
if (path.startsWith(match)) return true | ||
} else if (match.test(path)) return true | ||
} | ||
return false | ||
} | ||
// Test Paths | ||
if (opts.ignorePaths) { | ||
for (let i = 0; i < opts.ignorePaths.length; ++i) { | ||
const ignorePath = opts.ignorePaths[i] | ||
if (path.indexOf(ignorePath) === 0) { | ||
return true | ||
} | ||
} | ||
/** Tests whether the path should be ignored */ | ||
export function isIgnoredPath( | ||
path: Path, | ||
opts: Options = { | ||
ignoreCommonPatterns: true, | ||
} | ||
) { | ||
// handle deprecations | ||
opts = { | ||
ignoreHiddenBasenames: opts.ignoreHiddenFiles, | ||
ignoreUndesiredBasenames: opts.ignoreCommonPatterns, | ||
...opts, | ||
ignoreAbsolutePaths: [ | ||
...(opts.ignoreAbsolutePaths || []), | ||
...(opts.ignorePaths || []), | ||
], | ||
ignoreRelativePaths: [ | ||
...(opts.ignoreRelativePaths || []), | ||
...(opts.ignorePaths || []), | ||
], | ||
ignoreBasenames: [ | ||
...(opts.ignoreBasenames || []), | ||
...(opts.ignorePaths || []), | ||
], | ||
} | ||
// Test Hidden Files | ||
if (opts.ignoreHiddenFiles && basename[0] === '.') { | ||
// extract path, fallback basename, and reconstruct path with its custom properties if any (helpful for scandirectory) | ||
const { absolutePath, relativePath } = path | ||
let { basename } = path | ||
if (!basename && (absolutePath || relativePath)) | ||
basename = getBasename(absolutePath || relativePath || '') | ||
path = { ...path, basename } | ||
// custom callback | ||
if (opts.ignoreCustomCallback && opts.ignoreCustomCallback(path) === true) | ||
return true | ||
// absolute path checks | ||
if (absolutePath) { | ||
// match | ||
if ( | ||
opts.ignoreAbsolutePaths?.length && | ||
matches(absolutePath, opts.ignoreAbsolutePaths) | ||
) | ||
return true | ||
// custom? | ||
if ( | ||
opts.ignoreCustomPatterns && | ||
opts.ignoreCustomPatterns.test(absolutePath) | ||
) | ||
return true | ||
} | ||
// Test Common Patterns | ||
if (opts.ignoreCommonPatterns == null || opts.ignoreCommonPatterns === true) { | ||
return ( | ||
ignorePatterns.test(path) || | ||
(path !== basename && ignorePatterns.test(basename)) | ||
// relative path checks | ||
if (relativePath) { | ||
// match | ||
if ( | ||
opts.ignoreRelativePaths?.length && | ||
matches(relativePath, opts.ignoreRelativePaths) | ||
) | ||
} else if (opts.ignoreCommonPatterns) { | ||
const ignoreCommonPatterns /* :RegExp */ = opts.ignoreCommonPatterns | ||
return ( | ||
ignoreCommonPatterns.test(path) || | ||
(path !== basename && ignoreCommonPatterns.test(basename)) | ||
return true | ||
// custom? | ||
if ( | ||
opts.ignoreCustomPatterns && | ||
opts.ignoreCustomPatterns.test(relativePath) | ||
) | ||
return true | ||
} | ||
// Test Custom Patterns | ||
if (opts.ignoreCustomPatterns) { | ||
const ignoreCustomPatterns /* :RegExp */ = opts.ignoreCustomPatterns | ||
return ( | ||
ignoreCustomPatterns.test(path) || | ||
(path !== basename && ignoreCustomPatterns.test(basename)) | ||
// basename checks | ||
if (basename) { | ||
// match | ||
if (opts.ignoreBasenames?.length && matches(basename, opts.ignoreBasenames)) | ||
return true | ||
// hidden? | ||
if (opts.ignoreHiddenBasenames && basename[0] === '.') return true | ||
// common? | ||
if ( | ||
opts.ignoreUndesiredBasenames && | ||
undesiredBasenamesRegExp.test(basename) | ||
) | ||
return true | ||
// custom? | ||
if (opts.ignoreCustomPatterns && opts.ignoreCustomPatterns.test(basename)) | ||
return true | ||
} | ||
// Return | ||
// not ignored | ||
return false | ||
} | ||
/** Compatibility wrapper for {@link isIgnoredPath} */ | ||
export default function isIgnoredPathCompatibility( | ||
path: Path | string, | ||
opts?: Options | ||
) { | ||
if (typeof path === 'string') | ||
path = { | ||
absolutePath: path, | ||
relativePath: path, | ||
basename: getBasename(path), | ||
} | ||
return isIgnoredPath(path, opts) | ||
} |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
59076
693
1