Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ignorefs

Package Overview
Dependencies
Maintainers
1
Versions
138
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ignorefs - npm Package Compare versions

Comparing version 5.0.1 to 5.0.2-next.1704142943.fdef21ae7505a5ac059781804cf85c6def9421f7

147

edition-deno/index.ts
// builtin
import { basename as getBasename, isAbsolute } from 'node:path'
import { basename as getBasename, isAbsolute, sep } from 'node:path'

@@ -7,2 +7,14 @@ // external

/** Is the path relative? */
function isRelative(path: string): boolean {
if (!path) return false
return !isAbsolute(path)
}
/** Is the path a basename? */
function isBasename(path: string): boolean {
if (!path) return false
return !path.includes(sep)
}
/** A path to check its ignore status */

@@ -14,3 +26,3 @@ export interface Path {

relativePath?: string
/** If not provided, will be determined from {@link absolutePath}/{@link relativePath} */
/** If basename of the path, if any */
basename?: string

@@ -27,3 +39,3 @@ }

ignoreBasenames?: Array<string | RegExp>
/** @deprecated alias for {@link ignoreAbsolutePaths}, {@link ignoreRelativePaths}, and {@link ignoreBasenames} */
/** @deprecated alias for {@link isIgnoredPathCompatibility} that puts absolute paths in {@link ignoreAbsolutePaths}, relative paths in {@link ignoreRelativePaths}, and basenames in {@link ignoreBasenames} */
ignorePaths?: Array<string | RegExp>

@@ -33,3 +45,3 @@

ignoreHiddenBasenames?: boolean
/** @deprecated alias for {@link Options.ignoreHiddenBasenames} */
/** @deprecated aliases {@link Options.ignoreHiddenBasenames} for {@link isIgnoredPathCompatibility} */
ignoreHiddenFiles?: boolean

@@ -39,3 +51,3 @@

ignoreUndesiredBasenames?: boolean
/** @deprecated alias for {@link Options.ignoreUndesiredBasenames} */
/** @deprecated aliases {@link Options.ignoreUndesiredBasenames} for {@link isIgnoredPathCompatibility} */
ignoreCommonPatterns?: boolean

@@ -64,30 +76,21 @@

opts: Options = {
ignoreCommonPatterns: true,
ignoreUndesiredBasenames: 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 || []),
],
}
if (opts.ignoreHiddenFiles != null)
throw new Error(
'ignorefs: ignoreHiddenFiles is deprecated, use ignoreHiddenBasenames instead, otherwise use the default export for a compatibility layer'
)
if (opts.ignoreCommonPatterns != null)
throw new Error(
'ignorefs: ignoreCommonPatterns is deprecated, use ignoreUndesiredBasenames instead, otherwise use the default export for a compatibility layer'
)
if (opts.ignorePaths != null)
throw new Error(
'ignorefs: ignorePaths is deprecated, use ignoreAbsolutePaths, ignoreRelativePaths, and ignoreBasenames instead, otherwise use the default export for a compatibility layer'
)
// 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 }
// extract components of the path
const { absolutePath, relativePath, basename } = path

@@ -108,7 +111,3 @@ // custom callback

// custom?
if (
opts.ignoreCustomPatterns &&
opts.ignoreCustomPatterns.test(absolutePath)
)
return true
if (opts.ignoreCustomPatterns?.test(absolutePath)) return true
}

@@ -126,7 +125,3 @@

// custom?
if (
opts.ignoreCustomPatterns &&
opts.ignoreCustomPatterns.test(relativePath)
)
return true
if (opts.ignoreCustomPatterns?.test(relativePath)) return true
}

@@ -151,4 +146,3 @@

// custom?
if (opts.ignoreCustomPatterns && opts.ignoreCustomPatterns.test(basename))
return true
if (opts.ignoreCustomPatterns?.test(basename)) return true
}

@@ -160,8 +154,12 @@

/** Compatibility wrapper for {@link isIgnoredPath} */
/** Compatibility wrapper for {@link isIgnoredPath}, supporting path string, verifying path object and options, and handling option deprecations */
export default function isIgnoredPathCompatibility(
path: Path | string,
opts?: Options
opts: Options = {
ignoreUndesiredBasenames: true,
}
) {
// adjust path
if (typeof path === 'string') {
if (!path) throw new Error('ignorefs: path cannot be empty')
const result: Path = {}

@@ -171,6 +169,65 @@ if (isAbsolute(path)) result.absolutePath = path

result.basename = getBasename(path)
return isIgnoredPath(result, opts)
path = result
} else {
return isIgnoredPath(path, opts)
// verify
if (path.absolutePath && !isAbsolute(path.absolutePath))
throw new Error('ignorefs: path.absolutePath must be an absolute path')
if (path.relativePath && !isRelative(path.relativePath))
throw new Error('ignorefs: path.relativePath must be a relative path')
if (path.basename && !isBasename(path.basename))
throw new Error('ignorefs: path.basename must be a basename')
}
// handle deprecations
opts = Object.assign({}, opts)
if (opts.ignoreHiddenFiles != null) {
opts.ignoreHiddenBasenames = opts.ignoreHiddenFiles
delete opts.ignoreHiddenFiles
}
if (opts.ignoreCommonPatterns != null) {
opts.ignoreUndesiredBasenames = opts.ignoreCommonPatterns
delete opts.ignoreCommonPatterns
}
if (opts.ignorePaths) {
opts.ignoreAbsolutePaths = [
...(opts.ignoreAbsolutePaths || []).map((match) => {
if (typeof match === 'string' && !isAbsolute(match))
throw new Error(
'ignorefs: ignoreAbsolutePaths should only contain absolute paths and regular expressions'
)
return match
}),
...(opts.ignorePaths || []).filter((match) =>
typeof match === 'string' ? isAbsolute(match) : true
),
]
opts.ignoreRelativePaths = [
...(opts.ignoreRelativePaths || []).map((match) => {
if (typeof match === 'string' && !isRelative(match))
throw new Error(
'ignorefs: ignoreRelativePaths should only contain relative paths and regular expressions'
)
return match
}),
...(opts.ignorePaths || []).filter((match) =>
typeof match === 'string' ? isRelative(match) : true
),
]
opts.ignoreBasenames = [
...(opts.ignoreBasenames || []).map((match) => {
if (typeof match === 'string' && !isBasename(match))
throw new Error(
'ignorefs: ignoreBasenames should only contain basebanes and regular expressions'
)
return match
}),
...(opts.ignorePaths || []).filter((match) =>
typeof match === 'string' ? isBasename(sep) : true
),
]
delete opts.ignorePaths
}
// return result
return isIgnoredPath(path, opts)
}
// builtin
import { basename as getBasename, isAbsolute } from 'path';
import { basename as getBasename, isAbsolute, sep } from 'path';
// external
import undesiredBasenamesRegExp from 'ignorepatterns';
/** Is the path relative? */
function isRelative(path) {
if (!path)
return false;
return !isAbsolute(path);
}
/** Is the path a basename? */
function isBasename(path) {
if (!path)
return false;
return !path.includes(sep);
}
/** Tests the path against provided prefixes and regular expressions */

@@ -19,28 +31,13 @@ function matches(path, matches) {

export function isIgnoredPath(path, opts = {
ignoreCommonPatterns: true,
ignoreUndesiredBasenames: 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 };
if (opts.ignoreHiddenFiles != null)
throw new Error('ignorefs: ignoreHiddenFiles is deprecated, use ignoreHiddenBasenames instead, otherwise use the default export for a compatibility layer');
if (opts.ignoreCommonPatterns != null)
throw new Error('ignorefs: ignoreCommonPatterns is deprecated, use ignoreUndesiredBasenames instead, otherwise use the default export for a compatibility layer');
if (opts.ignorePaths != null)
throw new Error('ignorefs: ignorePaths is deprecated, use ignoreAbsolutePaths, ignoreRelativePaths, and ignoreBasenames instead, otherwise use the default export for a compatibility layer');
// extract components of the path
const { absolutePath, relativePath, basename } = path;
// custom callback

@@ -56,4 +53,3 @@ if (opts.ignoreCustomCallback && opts.ignoreCustomCallback(path) === true)

// custom?
if (opts.ignoreCustomPatterns &&
opts.ignoreCustomPatterns.test(absolutePath))
if (opts.ignoreCustomPatterns?.test(absolutePath))
return true;

@@ -68,4 +64,3 @@ }

// custom?
if (opts.ignoreCustomPatterns &&
opts.ignoreCustomPatterns.test(relativePath))
if (opts.ignoreCustomPatterns?.test(relativePath))
return true;

@@ -86,3 +81,3 @@ }

// custom?
if (opts.ignoreCustomPatterns && opts.ignoreCustomPatterns.test(basename))
if (opts.ignoreCustomPatterns?.test(basename))
return true;

@@ -93,5 +88,10 @@ }

}
/** Compatibility wrapper for {@link isIgnoredPath} */
export default function isIgnoredPathCompatibility(path, opts) {
/** Compatibility wrapper for {@link isIgnoredPath}, supporting path string, verifying path object and options, and handling option deprecations */
export default function isIgnoredPathCompatibility(path, opts = {
ignoreUndesiredBasenames: true,
}) {
// adjust path
if (typeof path === 'string') {
if (!path)
throw new Error('ignorefs: path cannot be empty');
const result = {};

@@ -103,7 +103,52 @@ if (isAbsolute(path))

result.basename = getBasename(path);
return isIgnoredPath(result, opts);
path = result;
}
else {
return isIgnoredPath(path, opts);
// verify
if (path.absolutePath && !isAbsolute(path.absolutePath))
throw new Error('ignorefs: path.absolutePath must be an absolute path');
if (path.relativePath && !isRelative(path.relativePath))
throw new Error('ignorefs: path.relativePath must be a relative path');
if (path.basename && !isBasename(path.basename))
throw new Error('ignorefs: path.basename must be a basename');
}
// handle deprecations
opts = Object.assign({}, opts);
if (opts.ignoreHiddenFiles != null) {
opts.ignoreHiddenBasenames = opts.ignoreHiddenFiles;
delete opts.ignoreHiddenFiles;
}
if (opts.ignoreCommonPatterns != null) {
opts.ignoreUndesiredBasenames = opts.ignoreCommonPatterns;
delete opts.ignoreCommonPatterns;
}
if (opts.ignorePaths) {
opts.ignoreAbsolutePaths = [
...(opts.ignoreAbsolutePaths || []).map((match) => {
if (typeof match === 'string' && !isAbsolute(match))
throw new Error('ignorefs: ignoreAbsolutePaths should only contain absolute paths and regular expressions');
return match;
}),
...(opts.ignorePaths || []).filter((match) => typeof match === 'string' ? isAbsolute(match) : true),
];
opts.ignoreRelativePaths = [
...(opts.ignoreRelativePaths || []).map((match) => {
if (typeof match === 'string' && !isRelative(match))
throw new Error('ignorefs: ignoreRelativePaths should only contain relative paths and regular expressions');
return match;
}),
...(opts.ignorePaths || []).filter((match) => typeof match === 'string' ? isRelative(match) : true),
];
opts.ignoreBasenames = [
...(opts.ignoreBasenames || []).map((match) => {
if (typeof match === 'string' && !isBasename(match))
throw new Error('ignorefs: ignoreBasenames should only contain basebanes and regular expressions');
return match;
}),
...(opts.ignorePaths || []).filter((match) => typeof match === 'string' ? isBasename(sep) : true),
];
delete opts.ignorePaths;
}
// return result
return isIgnoredPath(path, opts);
}

@@ -11,2 +11,14 @@ "use strict";

const ignorepatterns_1 = __importDefault(require("ignorepatterns"));
/** Is the path relative? */
function isRelative(path) {
if (!path)
return false;
return !(0, path_1.isAbsolute)(path);
}
/** Is the path a basename? */
function isBasename(path) {
if (!path)
return false;
return !path.includes(path_1.sep);
}
/** Tests the path against provided prefixes and regular expressions */

@@ -26,28 +38,13 @@ function matches(path, matches) {

function isIgnoredPath(path, opts = {
ignoreCommonPatterns: true,
ignoreUndesiredBasenames: 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 };
if (opts.ignoreHiddenFiles != null)
throw new Error('ignorefs: ignoreHiddenFiles is deprecated, use ignoreHiddenBasenames instead, otherwise use the default export for a compatibility layer');
if (opts.ignoreCommonPatterns != null)
throw new Error('ignorefs: ignoreCommonPatterns is deprecated, use ignoreUndesiredBasenames instead, otherwise use the default export for a compatibility layer');
if (opts.ignorePaths != null)
throw new Error('ignorefs: ignorePaths is deprecated, use ignoreAbsolutePaths, ignoreRelativePaths, and ignoreBasenames instead, otherwise use the default export for a compatibility layer');
// extract components of the path
const { absolutePath, relativePath, basename } = path;
// custom callback

@@ -63,4 +60,3 @@ if (opts.ignoreCustomCallback && opts.ignoreCustomCallback(path) === true)

// custom?
if (opts.ignoreCustomPatterns &&
opts.ignoreCustomPatterns.test(absolutePath))
if (opts.ignoreCustomPatterns?.test(absolutePath))
return true;

@@ -75,4 +71,3 @@ }

// custom?
if (opts.ignoreCustomPatterns &&
opts.ignoreCustomPatterns.test(relativePath))
if (opts.ignoreCustomPatterns?.test(relativePath))
return true;

@@ -93,3 +88,3 @@ }

// custom?
if (opts.ignoreCustomPatterns && opts.ignoreCustomPatterns.test(basename))
if (opts.ignoreCustomPatterns?.test(basename))
return true;

@@ -101,5 +96,10 @@ }

exports.isIgnoredPath = isIgnoredPath;
/** Compatibility wrapper for {@link isIgnoredPath} */
function isIgnoredPathCompatibility(path, opts) {
/** Compatibility wrapper for {@link isIgnoredPath}, supporting path string, verifying path object and options, and handling option deprecations */
function isIgnoredPathCompatibility(path, opts = {
ignoreUndesiredBasenames: true,
}) {
// adjust path
if (typeof path === 'string') {
if (!path)
throw new Error('ignorefs: path cannot be empty');
const result = {};

@@ -111,8 +111,53 @@ if ((0, path_1.isAbsolute)(path))

result.basename = (0, path_1.basename)(path);
return isIgnoredPath(result, opts);
path = result;
}
else {
return isIgnoredPath(path, opts);
// verify
if (path.absolutePath && !(0, path_1.isAbsolute)(path.absolutePath))
throw new Error('ignorefs: path.absolutePath must be an absolute path');
if (path.relativePath && !isRelative(path.relativePath))
throw new Error('ignorefs: path.relativePath must be a relative path');
if (path.basename && !isBasename(path.basename))
throw new Error('ignorefs: path.basename must be a basename');
}
// handle deprecations
opts = Object.assign({}, opts);
if (opts.ignoreHiddenFiles != null) {
opts.ignoreHiddenBasenames = opts.ignoreHiddenFiles;
delete opts.ignoreHiddenFiles;
}
if (opts.ignoreCommonPatterns != null) {
opts.ignoreUndesiredBasenames = opts.ignoreCommonPatterns;
delete opts.ignoreCommonPatterns;
}
if (opts.ignorePaths) {
opts.ignoreAbsolutePaths = [
...(opts.ignoreAbsolutePaths || []).map((match) => {
if (typeof match === 'string' && !(0, path_1.isAbsolute)(match))
throw new Error('ignorefs: ignoreAbsolutePaths should only contain absolute paths and regular expressions');
return match;
}),
...(opts.ignorePaths || []).filter((match) => typeof match === 'string' ? (0, path_1.isAbsolute)(match) : true),
];
opts.ignoreRelativePaths = [
...(opts.ignoreRelativePaths || []).map((match) => {
if (typeof match === 'string' && !isRelative(match))
throw new Error('ignorefs: ignoreRelativePaths should only contain relative paths and regular expressions');
return match;
}),
...(opts.ignorePaths || []).filter((match) => typeof match === 'string' ? isRelative(match) : true),
];
opts.ignoreBasenames = [
...(opts.ignoreBasenames || []).map((match) => {
if (typeof match === 'string' && !isBasename(match))
throw new Error('ignorefs: ignoreBasenames should only contain basebanes and regular expressions');
return match;
}),
...(opts.ignorePaths || []).filter((match) => typeof match === 'string' ? isBasename(path_1.sep) : true),
];
delete opts.ignorePaths;
}
// return result
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) {

@@ -58,2 +47,14 @@ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;

var ignorepatterns_1 = __importDefault(require("ignorepatterns"));
/** Is the path relative? */
function isRelative(path) {
if (!path)
return false;
return !(0, path_1.isAbsolute)(path);
}
/** Is the path a basename? */
function isBasename(path) {
if (!path)
return false;
return !path.includes(path_1.sep);
}
/** Tests the path against provided prefixes and regular expressions */

@@ -84,14 +85,15 @@ function matches(path, matches) {

function isIgnoredPath(path, opts) {
var _a, _b, _c;
var _a, _b, _c, _d, _e, _f;
if (opts === void 0) { opts = {
ignoreCommonPatterns: true,
ignoreUndesiredBasenames: 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 });
if (opts.ignoreHiddenFiles != null)
throw new Error('ignorefs: ignoreHiddenFiles is deprecated, use ignoreHiddenBasenames instead, otherwise use the default export for a compatibility layer');
if (opts.ignoreCommonPatterns != null)
throw new Error('ignorefs: ignoreCommonPatterns is deprecated, use ignoreUndesiredBasenames instead, otherwise use the default export for a compatibility layer');
if (opts.ignorePaths != null)
throw new Error('ignorefs: ignorePaths is deprecated, use ignoreAbsolutePaths, ignoreRelativePaths, and ignoreBasenames instead, otherwise use the default export for a compatibility layer');
// extract components of the path
var absolutePath = path.absolutePath, relativePath = path.relativePath, basename = path.basename;
// custom callback

@@ -107,4 +109,3 @@ if (opts.ignoreCustomCallback && opts.ignoreCustomCallback(path) === true)

// custom?
if (opts.ignoreCustomPatterns &&
opts.ignoreCustomPatterns.test(absolutePath))
if ((_b = opts.ignoreCustomPatterns) === null || _b === void 0 ? void 0 : _b.test(absolutePath))
return true;

@@ -115,8 +116,7 @@ }

// match
if (((_b = opts.ignoreRelativePaths) === null || _b === void 0 ? void 0 : _b.length) &&
if (((_c = opts.ignoreRelativePaths) === null || _c === void 0 ? void 0 : _c.length) &&
matches(relativePath, opts.ignoreRelativePaths))
return true;
// custom?
if (opts.ignoreCustomPatterns &&
opts.ignoreCustomPatterns.test(relativePath))
if ((_d = opts.ignoreCustomPatterns) === null || _d === void 0 ? void 0 : _d.test(relativePath))
return true;

@@ -127,3 +127,3 @@ }

// match
if (((_c = opts.ignoreBasenames) === null || _c === void 0 ? void 0 : _c.length) && matches(basename, opts.ignoreBasenames))
if (((_e = opts.ignoreBasenames) === null || _e === void 0 ? void 0 : _e.length) && matches(basename, opts.ignoreBasenames))
return true;

@@ -138,3 +138,3 @@ // hidden?

// custom?
if (opts.ignoreCustomPatterns && opts.ignoreCustomPatterns.test(basename))
if ((_f = opts.ignoreCustomPatterns) === null || _f === void 0 ? void 0 : _f.test(basename))
return true;

@@ -146,5 +146,11 @@ }

exports.isIgnoredPath = isIgnoredPath;
/** Compatibility wrapper for {@link isIgnoredPath} */
/** Compatibility wrapper for {@link isIgnoredPath}, supporting path string, verifying path object and options, and handling option deprecations */
function isIgnoredPathCompatibility(path, opts) {
if (opts === void 0) { opts = {
ignoreUndesiredBasenames: true,
}; }
// adjust path
if (typeof path === 'string') {
if (!path)
throw new Error('ignorefs: path cannot be empty');
var result = {};

@@ -156,8 +162,50 @@ if ((0, path_1.isAbsolute)(path))

result.basename = (0, path_1.basename)(path);
return isIgnoredPath(result, opts);
path = result;
}
else {
return isIgnoredPath(path, opts);
// verify
if (path.absolutePath && !(0, path_1.isAbsolute)(path.absolutePath))
throw new Error('ignorefs: path.absolutePath must be an absolute path');
if (path.relativePath && !isRelative(path.relativePath))
throw new Error('ignorefs: path.relativePath must be a relative path');
if (path.basename && !isBasename(path.basename))
throw new Error('ignorefs: path.basename must be a basename');
}
// handle deprecations
opts = Object.assign({}, opts);
if (opts.ignoreHiddenFiles != null) {
opts.ignoreHiddenBasenames = opts.ignoreHiddenFiles;
delete opts.ignoreHiddenFiles;
}
if (opts.ignoreCommonPatterns != null) {
opts.ignoreUndesiredBasenames = opts.ignoreCommonPatterns;
delete opts.ignoreCommonPatterns;
}
if (opts.ignorePaths) {
opts.ignoreAbsolutePaths = __spreadArray(__spreadArray([], __read((opts.ignoreAbsolutePaths || []).map(function (match) {
if (typeof match === 'string' && !(0, path_1.isAbsolute)(match))
throw new Error('ignorefs: ignoreAbsolutePaths should only contain absolute paths and regular expressions');
return match;
})), false), __read((opts.ignorePaths || []).filter(function (match) {
return typeof match === 'string' ? (0, path_1.isAbsolute)(match) : true;
})), false);
opts.ignoreRelativePaths = __spreadArray(__spreadArray([], __read((opts.ignoreRelativePaths || []).map(function (match) {
if (typeof match === 'string' && !isRelative(match))
throw new Error('ignorefs: ignoreRelativePaths should only contain relative paths and regular expressions');
return match;
})), false), __read((opts.ignorePaths || []).filter(function (match) {
return typeof match === 'string' ? isRelative(match) : true;
})), false);
opts.ignoreBasenames = __spreadArray(__spreadArray([], __read((opts.ignoreBasenames || []).map(function (match) {
if (typeof match === 'string' && !isBasename(match))
throw new Error('ignorefs: ignoreBasenames should only contain basebanes and regular expressions');
return match;
})), false), __read((opts.ignorePaths || []).filter(function (match) {
return typeof match === 'string' ? isBasename(path_1.sep) : true;
})), false);
delete opts.ignorePaths;
}
// return result
return isIgnoredPath(path, opts);
}
exports.default = isIgnoredPathCompatibility;

@@ -7,3 +7,3 @@ /** A path to check its ignore status */

relativePath?: string;
/** If not provided, will be determined from {@link absolutePath}/{@link relativePath} */
/** If basename of the path, if any */
basename?: string;

@@ -19,11 +19,11 @@ }

ignoreBasenames?: Array<string | RegExp>;
/** @deprecated alias for {@link ignoreAbsolutePaths}, {@link ignoreRelativePaths}, and {@link ignoreBasenames} */
/** @deprecated alias for {@link isIgnoredPathCompatibility} that puts absolute paths in {@link ignoreAbsolutePaths}, relative paths in {@link ignoreRelativePaths}, and basenames in {@link ignoreBasenames} */
ignorePaths?: Array<string | RegExp>;
/** Ignore basenames that begin with a `.` character */
ignoreHiddenBasenames?: boolean;
/** @deprecated alias for {@link Options.ignoreHiddenBasenames} */
/** @deprecated aliases {@link Options.ignoreHiddenBasenames} for {@link isIgnoredPathCompatibility} */
ignoreHiddenFiles?: boolean;
/** Ignore commonly undesirable basenames: https://github.com/bevry/ignorepatterns */
ignoreUndesiredBasenames?: boolean;
/** @deprecated alias for {@link Options.ignoreUndesiredBasenames} */
/** @deprecated aliases {@link Options.ignoreUndesiredBasenames} for {@link isIgnoredPathCompatibility} */
ignoreCommonPatterns?: boolean;

@@ -37,4 +37,4 @@ /** Test against each {@link Path} property */

export declare function isIgnoredPath(path: Path, opts?: Options): boolean;
/** Compatibility wrapper for {@link isIgnoredPath} */
/** Compatibility wrapper for {@link isIgnoredPath}, supporting path string, verifying path object and options, and handling option deprecations */
export default function isIgnoredPathCompatibility(path: Path | string, opts?: Options): boolean;
//# sourceMappingURL=index.d.ts.map
{
"title": "IgnoreFS",
"name": "ignorefs",
"version": "5.0.1",
"version": "5.0.2-next.1704142943.fdef21ae7505a5ac059781804cf85c6def9421f7",
"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@^5.0.1/edition-deno/index.ts'
import * as pkg from 'https://unpkg.com/ignorefs@^5.0.2/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.")

// builtin
import { basename as getBasename, isAbsolute } from 'path'
import { basename as getBasename, isAbsolute, sep } from 'path'

@@ -7,2 +7,14 @@ // external

/** Is the path relative? */
function isRelative(path: string): boolean {
if (!path) return false
return !isAbsolute(path)
}
/** Is the path a basename? */
function isBasename(path: string): boolean {
if (!path) return false
return !path.includes(sep)
}
/** A path to check its ignore status */

@@ -14,3 +26,3 @@ export interface Path {

relativePath?: string
/** If not provided, will be determined from {@link absolutePath}/{@link relativePath} */
/** If basename of the path, if any */
basename?: string

@@ -27,3 +39,3 @@ }

ignoreBasenames?: Array<string | RegExp>
/** @deprecated alias for {@link ignoreAbsolutePaths}, {@link ignoreRelativePaths}, and {@link ignoreBasenames} */
/** @deprecated alias for {@link isIgnoredPathCompatibility} that puts absolute paths in {@link ignoreAbsolutePaths}, relative paths in {@link ignoreRelativePaths}, and basenames in {@link ignoreBasenames} */
ignorePaths?: Array<string | RegExp>

@@ -33,3 +45,3 @@

ignoreHiddenBasenames?: boolean
/** @deprecated alias for {@link Options.ignoreHiddenBasenames} */
/** @deprecated aliases {@link Options.ignoreHiddenBasenames} for {@link isIgnoredPathCompatibility} */
ignoreHiddenFiles?: boolean

@@ -39,3 +51,3 @@

ignoreUndesiredBasenames?: boolean
/** @deprecated alias for {@link Options.ignoreUndesiredBasenames} */
/** @deprecated aliases {@link Options.ignoreUndesiredBasenames} for {@link isIgnoredPathCompatibility} */
ignoreCommonPatterns?: boolean

@@ -64,30 +76,21 @@

opts: Options = {
ignoreCommonPatterns: true,
ignoreUndesiredBasenames: 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 || []),
],
}
if (opts.ignoreHiddenFiles != null)
throw new Error(
'ignorefs: ignoreHiddenFiles is deprecated, use ignoreHiddenBasenames instead, otherwise use the default export for a compatibility layer'
)
if (opts.ignoreCommonPatterns != null)
throw new Error(
'ignorefs: ignoreCommonPatterns is deprecated, use ignoreUndesiredBasenames instead, otherwise use the default export for a compatibility layer'
)
if (opts.ignorePaths != null)
throw new Error(
'ignorefs: ignorePaths is deprecated, use ignoreAbsolutePaths, ignoreRelativePaths, and ignoreBasenames instead, otherwise use the default export for a compatibility layer'
)
// 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 }
// extract components of the path
const { absolutePath, relativePath, basename } = path

@@ -108,7 +111,3 @@ // custom callback

// custom?
if (
opts.ignoreCustomPatterns &&
opts.ignoreCustomPatterns.test(absolutePath)
)
return true
if (opts.ignoreCustomPatterns?.test(absolutePath)) return true
}

@@ -126,7 +125,3 @@

// custom?
if (
opts.ignoreCustomPatterns &&
opts.ignoreCustomPatterns.test(relativePath)
)
return true
if (opts.ignoreCustomPatterns?.test(relativePath)) return true
}

@@ -151,4 +146,3 @@

// custom?
if (opts.ignoreCustomPatterns && opts.ignoreCustomPatterns.test(basename))
return true
if (opts.ignoreCustomPatterns?.test(basename)) return true
}

@@ -160,8 +154,12 @@

/** Compatibility wrapper for {@link isIgnoredPath} */
/** Compatibility wrapper for {@link isIgnoredPath}, supporting path string, verifying path object and options, and handling option deprecations */
export default function isIgnoredPathCompatibility(
path: Path | string,
opts?: Options
opts: Options = {
ignoreUndesiredBasenames: true,
}
) {
// adjust path
if (typeof path === 'string') {
if (!path) throw new Error('ignorefs: path cannot be empty')
const result: Path = {}

@@ -171,6 +169,65 @@ if (isAbsolute(path)) result.absolutePath = path

result.basename = getBasename(path)
return isIgnoredPath(result, opts)
path = result
} else {
return isIgnoredPath(path, opts)
// verify
if (path.absolutePath && !isAbsolute(path.absolutePath))
throw new Error('ignorefs: path.absolutePath must be an absolute path')
if (path.relativePath && !isRelative(path.relativePath))
throw new Error('ignorefs: path.relativePath must be a relative path')
if (path.basename && !isBasename(path.basename))
throw new Error('ignorefs: path.basename must be a basename')
}
// handle deprecations
opts = Object.assign({}, opts)
if (opts.ignoreHiddenFiles != null) {
opts.ignoreHiddenBasenames = opts.ignoreHiddenFiles
delete opts.ignoreHiddenFiles
}
if (opts.ignoreCommonPatterns != null) {
opts.ignoreUndesiredBasenames = opts.ignoreCommonPatterns
delete opts.ignoreCommonPatterns
}
if (opts.ignorePaths) {
opts.ignoreAbsolutePaths = [
...(opts.ignoreAbsolutePaths || []).map((match) => {
if (typeof match === 'string' && !isAbsolute(match))
throw new Error(
'ignorefs: ignoreAbsolutePaths should only contain absolute paths and regular expressions'
)
return match
}),
...(opts.ignorePaths || []).filter((match) =>
typeof match === 'string' ? isAbsolute(match) : true
),
]
opts.ignoreRelativePaths = [
...(opts.ignoreRelativePaths || []).map((match) => {
if (typeof match === 'string' && !isRelative(match))
throw new Error(
'ignorefs: ignoreRelativePaths should only contain relative paths and regular expressions'
)
return match
}),
...(opts.ignorePaths || []).filter((match) =>
typeof match === 'string' ? isRelative(match) : true
),
]
opts.ignoreBasenames = [
...(opts.ignoreBasenames || []).map((match) => {
if (typeof match === 'string' && !isBasename(match))
throw new Error(
'ignorefs: ignoreBasenames should only contain basebanes and regular expressions'
)
return match
}),
...(opts.ignorePaths || []).filter((match) =>
typeof match === 'string' ? isBasename(sep) : true
),
]
delete opts.ignorePaths
}
// return result
return isIgnoredPath(path, opts)
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc