Security News
The Dark Side of Open Source
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
dir-glob
Advanced tools
Package description
The dir-glob npm package is designed to convert directory paths into glob patterns, which can then be used with other tools that work with globs, such as file system search utilities. This can be particularly useful for including or excluding entire directories when working with file patterns.
Convert directories to glob patterns
This feature allows you to convert an array of directory paths into glob patterns that match all files within those directories. The example demonstrates converting two directory paths into their corresponding glob patterns.
const dirGlob = require('dir-glob');
(async () => {
const paths = await dirGlob(['assets', 'uploads']);
console.log(paths);
//=> ['assets/**', 'uploads/**']
})();
Include file extensions in glob patterns
This feature extends the basic directory-to-glob conversion by allowing you to specify file extensions. This results in glob patterns that match only files with the specified extensions within the given directories. The example shows how to generate glob patterns for jpg and png files only.
const dirGlob = require('dir-glob');
(async () => {
const paths = await dirGlob(['assets', 'uploads'], {extensions: ['jpg', 'png']});
console.log(paths);
//=> ['assets/**/*.jpg', 'assets/**/*.png', 'uploads/**/*.jpg', 'uploads/**/*.png']
})();
The 'glob' package provides pattern matching functionality for file paths. While 'glob' itself focuses on matching patterns against existing file structures, 'dir-glob' specifically converts directory paths into glob patterns. 'glob' can be used in conjunction with 'dir-glob' to first generate glob patterns for directories and then match those patterns against files.
Similar to 'glob', 'fast-glob' is an optimized version that provides a faster and more efficient way to match glob patterns against file systems. It offers a similar functionality to 'dir-glob' in terms of working with glob patterns, but it does not specifically focus on converting directories to globs. Instead, it's more about performing the matching operation itself, potentially using patterns generated by 'dir-glob'.
Readme
Convert directories to glob compatible strings
$ npm install dir-glob
const dirGlob = require('dir-glob');
(async () => {
console.log(await dirGlob(['index.js', 'test.js', 'fixtures']));
//=> ['index.js', 'test.js', 'fixtures/**']
console.log(await dirGlob(['index.js', 'inner_folder'], {cwd: 'fixtures'}));
//=> ['index.js', 'inner_folder/**']
console.log(await dirGlob(['lib/**', 'fixtures'], {
files: ['test', 'unicorn']
extensions: ['js']
}));
//=> ['lib/**', 'fixtures/**/test.js', 'fixtures/**/unicorn.js']
console.log(await dirGlob(['lib/**', 'fixtures'], {
files: ['test', 'unicorn', '*.jsx'],
extensions: ['js', 'png']
}));
//=> ['lib/**', 'fixtures/**/test.{js,png}', 'fixtures/**/unicorn.{js,png}', 'fixtures/**/*.jsx']
})();
Returns a Promise<string[]>
with globs.
Returns a string[]
with globs.
Type: string | string[]
Paths.
Type: object
Type: string[]
Append extensions to the end of your globs.
Type: string[]
Only glob for certain files.
Type: string[]
Test in specific directory.
FAQs
Convert directories to glob compatible strings
The npm package dir-glob receives a total of 28,905,041 weekly downloads. As such, dir-glob popularity was classified as popular.
We found that dir-glob demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
Research
Security News
The Socket Research team found this npm package includes code for collecting sensitive developer information, including your operating system username, Git username, and Git email.
Security News
OpenJS is warning of social engineering takeovers targeting open source projects after receiving a credible attempt on the foundation.