Socket
Socket
Sign inDemoInstall

dir-glob

Package Overview
Dependencies
1
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    dir-glob

Convert directories to glob compatible strings


Version published
Maintainers
2
Install size
12.6 kB
Created

Package description

What is dir-glob?

The dir-glob npm package is designed to convert directory paths into glob patterns, which can then be used with other tools that work with globs, such as file system search utilities. This can be particularly useful for including or excluding entire directories when working with file patterns.

What are dir-glob's main functionalities?

Convert directories to glob patterns

This feature allows you to convert an array of directory paths into glob patterns that match all files within those directories. The example demonstrates converting two directory paths into their corresponding glob patterns.

const dirGlob = require('dir-glob');

(async () => {
    const paths = await dirGlob(['assets', 'uploads']);
    console.log(paths);
    //=> ['assets/**', 'uploads/**']
})();

Include file extensions in glob patterns

This feature extends the basic directory-to-glob conversion by allowing you to specify file extensions. This results in glob patterns that match only files with the specified extensions within the given directories. The example shows how to generate glob patterns for jpg and png files only.

const dirGlob = require('dir-glob');

(async () => {
    const paths = await dirGlob(['assets', 'uploads'], {extensions: ['jpg', 'png']});
    console.log(paths);
    //=> ['assets/**/*.jpg', 'assets/**/*.png', 'uploads/**/*.jpg', 'uploads/**/*.png']
})();

Other packages similar to dir-glob

Readme

Source

dir-glob Build Status

Convert directories to glob compatible strings

Install

$ npm install dir-glob

Usage

const dirGlob = require('dir-glob');

(async () => {
	console.log(await dirGlob(['index.js', 'test.js', 'fixtures']));
	//=> ['index.js', 'test.js', 'fixtures/**']

	console.log(await dirGlob(['index.js', 'inner_folder'], {cwd: 'fixtures'}));
	//=> ['index.js', 'inner_folder/**']

	console.log(await dirGlob(['lib/**', 'fixtures'], {
		files: ['test', 'unicorn']
		extensions: ['js']
	}));
	//=> ['lib/**', 'fixtures/**/test.js', 'fixtures/**/unicorn.js']

	console.log(await dirGlob(['lib/**', 'fixtures'], {
		files: ['test', 'unicorn', '*.jsx'],
		extensions: ['js', 'png']
	}));
	//=> ['lib/**', 'fixtures/**/test.{js,png}', 'fixtures/**/unicorn.{js,png}', 'fixtures/**/*.jsx']
})();

API

dirGlob(input, options?)

Returns a Promise<string[]> with globs.

dirGlob.sync(input, options?)

Returns a string[] with globs.

input

Type: string | string[]

Paths.

options

Type: object

extensions

Type: string[]

Append extensions to the end of your globs.

files

Type: string[]

Only glob for certain files.

cwd

Type: string[]

Test in specific directory.

Keywords

FAQs

Last updated on 29 Jun 2019

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