Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
The filelist npm package is a utility for managing and manipulating lists of file paths. It is commonly used in build systems and task runners to handle groups of files efficiently.
Creating a FileList
This feature allows you to create a new FileList instance and include files matching a specific pattern. In this example, all JavaScript files in the 'src' directory and its subdirectories are included.
const FileList = require('filelist').FileList;
const files = new FileList();
files.include('src/**/*.js');
console.log(files.toArray());
Excluding Files
This feature allows you to exclude specific files from the FileList. In this example, all JavaScript files in the 'src' directory are included except for those named 'test.js'.
const FileList = require('filelist').FileList;
const files = new FileList();
files.include('src/**/*.js');
files.exclude('src/**/test.js');
console.log(files.toArray());
Refreshing the FileList
This feature allows you to refresh the FileList to ensure it is up-to-date with the current file system state. This is useful when files are added or removed during the execution of a script.
const FileList = require('filelist').FileList;
const files = new FileList();
files.include('src/**/*.js');
files.refresh();
console.log(files.toArray());
The glob package is a popular utility for matching file paths using patterns. It is more focused on pattern matching and file searching compared to filelist, which also provides list management capabilities.
The minimatch package is a library for matching file paths against glob patterns. It is often used as a lower-level utility for pattern matching, whereas filelist provides higher-level list management features.
The fast-glob package is a high-performance globbing library for Node.js. It offers faster file matching and searching capabilities compared to filelist, but does not include list management features.
A FileList is a lazy-evaluated list of files. When given a list of glob patterns for possible files to be included in the file list, instead of searching the file structures to find the files, a FileList holds the pattern for latter use.
This allows you to define a FileList to match any number of files, but only search out the actual files when then FileList itself is actually used. The key is that the first time an element of the FileList/Array is requested, the pending patterns are resolved into a real list of file names.
Add files to the list with the include
method. You can add glob
patterns, individual files, or RegExp objects. When the Array
methods are invoked on the FileList, these items are resolved to
an actual list of files.
var fl = new FileList();
fl.include('test/*.js');
fl.exclude('test/helpers.js');
Use the exclude
method to override inclusions. You can use this
when your inclusions are too broad.
FileList has lazy-evaluated versions of most of the array methods, including the following:
When you call one of these methods, the items in the FileList will be resolved to the full list of files, and the method will be invoked on that result.
length
methodlength
: FileList includes a length method (instead of a
property) which returns the number of actual files in the list
once it's been resolved.
include
: Add a filename/glob/regex to the list
exclude
: Override inclusions by excluding a filename/glob/regex
resolve
: Resolve the items in the FileList to the full list of
files. This method is invoked automatically when one of the array
methods is called.
toArray
: Immediately resolves the list of items, and returns an
actual array of filepaths.
clearInclusions
: Clears any pending items -- must be used
before resolving the list.
clearExclusions
: Clears the list of exclusions rules.
FAQs
Lazy-evaluating list of files, based on globs or regex patterns
We found that filelist demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.