
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Cross-platform glob expansions simplified. Input: file paths and glob expressions. Output: resolved file paths organised by type (file, directory and not-found).
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.
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);
});
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.
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.
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.
Cross-platform glob expansions simplified. Input: file paths and glob expressions. Output: resolved file paths organised by type (file, directory and not-found). It handles all the cross-platform issues associated with file paths.
Particularly useful for handling user input, for example a CLI utility which accepts a list of file paths and globs.
$ example-utility index.js * not/existing/*
The example-utility above could pass its user input into FileSet
. Call await .add(<string[]>)
as many times as necessary, adding more path/glob expressions each time.
import FileSet from 'file-set'
const fileSet = new FileSet()
await fileSet.add([ 'index.js', '*', 'not/existing/*' ])
console.log(fileSet)
The output has been organised into sets. Any duplicates caused by overlapping glob expressions are removed.
FileSet {
files: [ 'index.js', 'LICENSE', 'package.json', 'README.md' ],
dirs: [ 'jsdoc2md/', 'lib/', 'node_modules/', 'test/' ],
notExisting: [ 'not/existing/*' ]
}
© 2014-24 Lloyd Brookes <75pound@gmail.com>.
Tested by test-runner.
FAQs
Cross-platform glob expansions simplified. Input: file paths and glob expressions. Output: resolved file paths organised by type (file, directory and not-found).
The npm package file-set receives a total of 218,995 weekly downloads. As such, file-set popularity was classified as popular.
We found that file-set demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.