What is file-set?
The file-set npm package allows you to easily include and exclude files using glob patterns. It is useful for tasks such as file manipulation, filtering, and organizing files based on specific patterns.
What are file-set's main functionalities?
Include Files
This feature allows you to include files that match a specific glob pattern. In this example, all JavaScript files in the 'src' directory and its subdirectories are included.
const fileSet = require('file-set');
fileSet('src/**/*.js', function(err, files) {
if (err) throw err;
console.log(files);
});
Exclude Files
This feature allows you to exclude files that match a specific glob pattern. In this example, all JavaScript files in the 'src' directory and its subdirectories are included, except for files named 'test.js'.
const fileSet = require('file-set');
fileSet(['src/**/*.js', '!src/**/test.js'], function(err, files) {
if (err) throw err;
console.log(files);
});
Multiple Patterns
This feature allows you to include files from multiple patterns. In this example, all JavaScript files in both the 'src' and 'lib' directories and their subdirectories are included.
const fileSet = require('file-set');
fileSet(['src/**/*.js', 'lib/**/*.js'], function(err, files) {
if (err) throw err;
console.log(files);
});
Other packages similar to file-set
glob
The 'glob' package is a popular library for matching files using glob patterns. It is more flexible and powerful than file-set, but requires more configuration and does not support exclusion patterns as easily.
fast-glob
The 'fast-glob' package is a high-performance alternative to 'glob'. It supports advanced features like negative patterns for exclusion and is faster, making it suitable for large projects with many files.
multimatch
The 'multimatch' package allows you to match files against multiple glob patterns, including support for exclusion patterns. It is similar to file-set but offers more advanced pattern matching capabilities.
file-set
Exports a contructor taking a list of file patterns as input, returning a file-set
instance containing the expanded patterns split into separate lists of files
, dirs
and notExisting
.
Example
const FileSet = require('file-set')
Install
$ npm install file-set --save
Usage
> const FileSet = require('file-set');
> new FileSet([ '*', 'not/existing/*' ])
FileSet {
files: [ 'LICENSE', 'package.json', 'README.md' ],
dirs: [ 'jsdoc2md/', 'lib/', 'node_modules/', 'test/' ],
notExisting: [ 'not/existing/*' ] }
API
Exports a contructor taking a list of file patterns as input, returning a file-set
instance containing the expanded patterns split into separate lists of files
, dirs
and notExisting
.
Example
const FileSet = require('file-set')
FileSet ⏏
Expands file patterns, returning the matched and unmatched files and directories
Kind: Exported class
new FileSet(patternList)
Param | Type | Description |
---|
patternList | string | Array.<string> | A pattern, or array of patterns to expand |
fileSet.files : Array.<string>
The existing files found
Kind: instance property of FileSet
fileSet.dirs : Array.<string>
The existing directories found
Kind: instance property of FileSet
fileSet.notExisting : Array.<string>
Paths which were not found
Kind: instance property of FileSet
fileSet.add(files)
add file patterns to the set
Kind: instance method of FileSet
Param | Type | Description |
---|
files | string | Array.<string> | A pattern, or array of patterns to expand |
© 2014-16 Lloyd Brookes <75pound@gmail.com>. Documented by jsdoc-to-markdown.