Socket
Socket
Sign inDemoInstall

to-absolute-glob

Package Overview
Dependencies
6
Maintainers
3
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    to-absolute-glob

Make a glob pattern absolute, ensuring that negative globs and patterns with trailing slashes are correctly handled.


Version published
Weekly downloads
2.1M
increased by5.61%
Maintainers
3
Install size
48.8 kB
Created
Weekly downloads
 

Package description

What is to-absolute-glob?

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.

What are to-absolute-glob's main functionalities?

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);

Other packages similar to to-absolute-glob

Readme

Source

to-absolute-glob NPM version NPM downloads Linux Build Status Windows Build Status

Make a glob pattern absolute, ensuring that negative globs and patterns with trailing slashes are correctly handled.

Install

Install with npm:

npm install to-absolute-glob

Or install with yarn:

yarn add to-absolute-glob

Usage

const toAbsGlob = require('to-absolute-glob');
toAbsGlob('a/*.js');
//=> '/dev/foo/a/*.js'

Examples

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'

About

  • has-glob: Returns true if an array has a glob pattern. | homepage
  • is-glob: Returns true if the given string looks like a glob pattern or an extglob pattern… more | homepage
  • is-valid-glob: Return true if a value is a valid glob pattern or patterns. | homepage

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Contributors

CommitsContributor
16doowb
15jonschlinkert
1phated
1erikkemperman

Building docs

(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

Running tests

Install dev dependencies:

$ npm install -d && npm test

Author

Jon Schlinkert

License

Copyright (c) Jon Schlinkert. Released under the MIT license.


This file was generated by verb-generate-readme, v3.0.0, on November 17, 2022.

Keywords

FAQs

Last updated on 18 Nov 2022

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc