Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Take a list of glob patterns and return an array of file locations, respecting `.gitignore` and allowing for ignore patterns via `package.json`.
The deglob npm package is used to expand glob patterns into an array of file paths, with options to ignore certain patterns and to use specific file extensions. It is particularly useful for tools that need to process files based on patterns, such as linters or build systems.
Basic Usage
This feature allows you to expand a glob pattern into an array of file paths. In this example, it will find all JavaScript files in the current directory and its subdirectories.
const deglob = require('deglob');
deglob(['**/*.js'], (err, files) => {
if (err) {
console.error(err);
return;
}
console.log(files);
});
Ignoring Patterns
This feature allows you to specify patterns to ignore. In this example, it will find all JavaScript files but ignore those in the 'node_modules' and 'dist' directories.
const deglob = require('deglob');
deglob(['**/*.js'], { ignore: ['node_modules/**', 'dist/**'] }, (err, files) => {
if (err) {
console.error(err);
return;
}
console.log(files);
});
Using Specific File Extensions
This feature allows you to specify multiple file extensions in the glob pattern. In this example, it will find all JavaScript and JSX files.
const deglob = require('deglob');
deglob(['**/*.{js,jsx}'], (err, files) => {
if (err) {
console.error(err);
return;
}
console.log(files);
});
The 'glob' package is a low-level library for matching files using glob patterns. It is more flexible but requires more configuration compared to deglob.
The 'fast-glob' package is a high-performance alternative to 'glob'. It is faster and more efficient, especially for large sets of files, but does not include built-in support for ignoring patterns like deglob.
The 'globby' package is a higher-level wrapper around 'glob' and 'fast-glob' that provides a simpler API and additional features like ignoring patterns and multiple file extensions, similar to deglob.
Take a list of glob patterns and return an array of file locations, respecting .gitignore
and allowing for ignore patterns via package.json
.
Giant swaths of this code were extracted from standard. It seems useful outside of that tool, so I've attempted to extract it! :)
npm install --save deglob
var deglob = require('deglob')
deglob(['**/*.js'], function(err, files) {
files.forEach(function(file) {
console.log('found file ' + file)
})
})
// pass in some options to customize!
var path = require('path')
var opts = {
cwd: path.join(__dirname, 'someDir'),
useGitIgnore: false,
usePackageJson: false
}
deglob(['**/*.js'], opts, function(err, files) {
files.forEach(function(file) {
console.log('found file ' + file)
})
})
deglob
will look for a package.json
file by default and use any ignore patterns defined.
To define patterns in package.json add somthing like this:
"config": {
"ignore": ['**/*.bad']
}
If you do not fancy the config
key, provide a different one using the configKey
option.
Option | Default | Description |
---|---|---|
useGitIgnore | true | Turn on/off allowing ignore patterns via .gitignore |
usePackageJson | true | Turn on/off allowing ignore patterns via package.json config. |
configKey | 'config' | This is the parent key in package.json to look for the ignore attribute. |
gitIgnoreFile | '.gitignore' | Name of the .gitignore file look for (probably best to leave it default) |
ignore | [] | List of additional ignore patterns to use |
cwd | process.cwd() | This is the working directory to start the deglobbing |
Contributions welcome! Please read the contributing guidelines first.
FAQs
Take a list of glob patterns and return an array of file locations, respecting `.gitignore` and allowing for ignore patterns via `package.json`.
We found that deglob demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 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
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.