Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function matchesFilter(filter: IgnoreFilter, basename: string, loc: string): boolean {
let filterByBasename = true;
if (filter.base && filter.base !== '.') {
loc = path.relative(filter.base, loc);
filterByBasename = false;
}
// the micromatch regex expects unix path separators
loc = loc.replace('\\', '/');
return (
filter.regex.test(loc) ||
filter.regex.test(`/${loc}`) ||
(filterByBasename && filter.regex.test(basename)) ||
mm.isMatch(loc, filter.pattern)
);
}
function testCriteria(criterion, index) {
var result;
switch (Object.prototype.toString.call(criterion)) {
case '[object String]':
result = string === criterion || altString && altString === criterion;
result = result || micromatch.isMatch(string, criterion);
break;
case '[object RegExp]':
result = criterion.test(string) || altString && criterion.test(altString);
break;
case '[object Function]':
result = criterion.apply(null, value);
result = result || altValue && criterion.apply(null, altValue);
break;
default:
result = false;
}
if (result) {
matchIndex = index + startIndex;
}
return result;
}
module.exports = function generateTOCNodes(
{ markdownNode, markdownAST },
{
include = [],
header = 'Table of Contents',
useExistingHeader = false,
orderedList = false,
mdastUtilTocOptions = {}
}
) {
const filePath = markdownNode.fileAbsolutePath
.split(process.cwd())
.pop()
.replace(/^\//, '');
const isIncluded = mm.isMatch(filePath, include);
if (!isIncluded) {
return;
}
const index = markdownAST.children.findIndex(node => {
if (useExistingHeader) {
if (node.type === 'heading') {
return node.children.findIndex(child => child.value === header) + 1;
}
return false;
}
return node.type !== 'yaml';
});
if (index < 0) {
module.exports = function any(fp, patterns, options) {
options = options || {};
var res = {is: [], isnt: []};
res.file = fp;
var len = patterns.length;
var i = -1;
while (++i < len) {
var pattern = patterns[i];
if (mm.isMatch(fp, pattern, {dot: true, contains: true})) {
res.is.push(pattern);
break;
} else {
res.isnt.push(pattern);
}
}
return res;
};
function buildFile(file, silent) {
const destPath = getBuildPath(file, BUILD_DIR);
mkdirp.sync(path.dirname(destPath));
if (micromatch.isMatch(file, IGNORE_PATTERN)) {
silent ||
process.stdout.write(
chalk.dim(' \u2022 ') +
path.relative(PACKAGES_DIR, file) +
' (ignore)\n'
);
} else if (!micromatch.isMatch(file, JS_FILES_PATTERN)) {
fs.createReadStream(file).pipe(fs.createWriteStream(destPath));
silent ||
process.stdout.write(
chalk.red(' \u2022 ') +
path.relative(PACKAGES_DIR, file) +
chalk.red(' \u21D2 ') +
path.relative(PACKAGES_DIR, destPath) +
' (copy)' +
'\n'
reason =>
!mm.isMatch(reason.clearName || reason.moduleName || "", ignore)
);
function hasSideEffects(filePath: FilePath, pkg: InternalPackageJSON) {
switch (typeof pkg.sideEffects) {
case 'boolean':
return pkg.sideEffects;
case 'string':
return micromatch.isMatch(
path.relative(pkg.pkgdir, filePath),
pkg.sideEffects,
{matchBase: true},
);
case 'object':
return pkg.sideEffects.some(sideEffects =>
hasSideEffects(filePath, {...pkg, sideEffects}),
);
}
return true;
}
if (passUrls.some(reg => mm.isMatch(req.url, reg))) {
next();
const modules = report.modules.filter(module => {
if (pattern && mm.isMatch(module.name, pattern, { format })) {
return true;
} else if (pattern) {
return false;
}
if (flags.filesOnly && module.type !== "file") return false;
if (flags.modulesOnly && module.type !== "module") return false;
if (flags.directOnly && module.depsType !== "direct") return false;
if (flags.transitiveOnly && module.depsType !== "transitive") return false;
if (flags.duplicatesOnly && (module.locations || []).length < 2)
return false;
return true;
});