Security News
The Dark Side of Open Source
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
to-absolute-glob
Advanced tools
Package description
The to-absolute-glob package is used to convert glob patterns into absolute paths. This is particularly useful when working with file system operations that require absolute paths. The package ensures that the glob patterns are resolved to absolute paths based on the process's current working directory or a specified base directory.
Convert relative glob to absolute
This feature allows you to convert a relative glob pattern into an absolute path glob pattern. The 'cwd' option specifies the base directory from which the glob should be resolved.
const toAbsoluteGlob = require('to-absolute-glob');
const absoluteGlob = toAbsoluteGlob('*.js', { cwd: '/some/dir' });
console.log(absoluteGlob);
Handle negation patterns
The package can also handle negation patterns (patterns that start with '!') and convert them into absolute paths while preserving the negation.
const toAbsoluteGlob = require('to-absolute-glob');
const absoluteGlob = toAbsoluteGlob('!*.js', { cwd: '/some/dir' });
console.log(absoluteGlob);
Globby is a user-friendly glob matching library that supports multiple patterns. It is built on top of the 'glob' and 'fast-glob' packages and provides a simpler API for matching files. It can also convert relative paths to absolute paths, similar to to-absolute-glob, but offers more features like expanding directories and array of patterns.
Fast-glob is a fast implementation of node's glob module that provides a similar functionality to to-absolute-glob. It supports absolute path resolution but is more focused on performance and additional features like stream API, error tolerance, and more extensive pattern matching capabilities.
Readme
Make a glob pattern absolute, ensuring that negative globs and patterns with trailing slashes are correctly handled.
Install with npm:
npm install to-absolute-glob
Or install with yarn:
yarn add to-absolute-glob
const toAbsGlob = require('to-absolute-glob');
toAbsGlob('a/*.js');
//=> '/dev/foo/a/*.js'
Given the current project folder (cwd) is /dev/foo/
:
makes a path absolute
toAbsGlob('a');
//=> '/dev/foo/a'
makes a glob absolute
toAbsGlob('a/*.js');
//=> '/dev/foo/a/*.js'
retains trailing slashes
toAbsGlob('a/*/');
//=> '/dev/foo/a/*/'
retains trailing slashes with cwd
toAbsGlob('./fixtures/whatsgoingon/*/', {cwd: __dirname});
//=> '/dev/foo/'
makes a negative glob absolute
toAbsGlob('!a/*.js');
//=> '!/dev/foo/a/*.js'
from a cwd
toAbsGlob('a/*.js', {cwd: 'foo'});
//=> '/dev/foo/foo/a/*.js'
makes a negative glob absolute from a cwd
toAbsGlob('!a/*.js', {cwd: 'foo'});
//=> '!/dev/foo/foo/a/*.js'
from a root path
toAbsGlob('/a/*.js', {root: 'baz'});
//=> '/dev/foo/baz/a/*.js'
from a root slash
toAbsGlob('/a/*.js', {root: '/'});
//=> '/dev/foo/a/*.js'
from a negative root path
toAbsGlob('!/a/*.js', {root: 'baz'});
//=> '!/dev/foo/baz/a/*.js'
from a negative root slash
toAbsGlob('!/a/*.js', {root: '/'});
//=> '!/dev/foo/a/*.js'
true
if an array has a glob pattern. | homepagetrue
if the given string looks like a glob pattern or an extglob pattern… more | homepagePull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Commits | Contributor |
---|---|
16 | doowb |
15 | jonschlinkert |
1 | phated |
1 | erikkemperman |
(This document was generated by verb-generate-readme (a verb generator), please don't edit the readme directly. Any changes to the readme must be made in .verb.md.)
To generate the readme and API documentation with verb:
$ npm install -g verb verb-generate-readme && verb
Install dev dependencies:
$ npm install -d && npm test
Jon Schlinkert
Copyright (c) Jon Schlinkert. Released under the MIT license.
This file was generated by verb-generate-readme, v3.0.0, on November 17, 2022.
FAQs
Make a glob pattern absolute, ensuring that negative globs and patterns with trailing slashes are correctly handled.
The npm package to-absolute-glob receives a total of 1,980,558 weekly downloads. As such, to-absolute-glob popularity was classified as popular.
We found that to-absolute-glob demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 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
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
Research
Security News
The Socket Research team found this npm package includes code for collecting sensitive developer information, including your operating system username, Git username, and Git email.
Security News
OpenJS is warning of social engineering takeovers targeting open source projects after receiving a credible attempt on the foundation.