What is @gulpjs/to-absolute-glob?
@gulpjs/to-absolute-glob is an npm package that converts a given glob pattern to an absolute glob pattern. This is particularly useful in build systems and task runners like Gulp, where you need to work with file paths in a consistent manner.
What are @gulpjs/to-absolute-glob's main functionalities?
Convert relative glob to absolute glob
This feature allows you to convert a relative glob pattern to an absolute glob pattern. The `cwd` option specifies the current working directory to resolve the relative path.
const toAbsoluteGlob = require('@gulpjs/to-absolute-glob');
const absoluteGlob = toAbsoluteGlob('./src/**/*.js', { cwd: process.cwd() });
console.log(absoluteGlob);
Handle negated globs
This feature supports negated glob patterns, which are used to exclude files from a set of matched files. The `!` character at the beginning of the glob pattern indicates negation.
const toAbsoluteGlob = require('@gulpjs/to-absolute-glob');
const absoluteGlob = toAbsoluteGlob('!./src/**/*.test.js', { cwd: process.cwd() });
console.log(absoluteGlob);
Options for handling different path formats
This feature allows you to specify additional options like `root` to handle different path formats. This can be useful when working in environments with different directory structures.
const toAbsoluteGlob = require('@gulpjs/to-absolute-glob');
const absoluteGlob = toAbsoluteGlob('./src/**/*.js', { cwd: process.cwd(), root: '/' });
console.log(absoluteGlob);
Other packages similar to @gulpjs/to-absolute-glob
glob
The `glob` package is a popular library for matching files using glob patterns. It provides extensive functionality for pattern matching and file searching, but it does not specifically focus on converting relative globs to absolute globs like @gulpjs/to-absolute-glob.
fast-glob
The `fast-glob` package is a high-performance glob library that supports advanced features like concurrency and caching. While it excels in performance and flexibility, it does not provide a direct method for converting relative globs to absolute globs.
minimatch
The `minimatch` package is a minimalistic library for matching file paths against glob patterns. It is often used as a dependency in other glob-related packages. However, it does not offer functionality for converting relative globs to absolute globs.
@gulpjs/to-absolute-glob
Make a glob pattern absolute, ensuring that negative globs and patterns with trailing slashes are correctly handled.
Usage
var toAbsoluteGlob = require('@gulpjs/to-absolute-glob');
toAbsoluteGlob('a/*.js') === '/dev/foo/a/*.js';
toAbsoluteGlob('a') === '/dev/foo/a';
toAbsoluteGlob('a/*/') === '/dev/foo/a/*/';
toAbsoluteGlob('!a/*.js') === '!/dev/foo/a/*.js';
toAbsoluteGlob('a/*.js', { cwd: 'foo' }) === '/dev/foo/foo/a/*.js';
toAbsoluteGlob('/a/*.js', { root: 'baz' }) === '/dev/foo/baz/a/*.js';
API
toAbsoluteGlob(glob, [options])
Takes a glob
string and an optional options
object and produces an absolute glob. If the glob is relative, the root
or cwd
option (or process.cwd()
if neither specified) will be used as the base of the glob.
License
MIT