All Projects → sindresorhus → Globby

sindresorhus / Globby

Licence: mit
User-friendly glob matching

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to Globby

dir-glob
Convert directories to glob compatible strings
Stars: ✭ 41 (-97.8%)
Mutual labels:  matching, glob, directories, globbing
delete-empty
Recursively delete all empty folders in a directory and child directories.
Stars: ✭ 38 (-97.96%)
Mutual labels:  files, glob, directories
glob-fs
file globbing for node.js. speedy and powerful alternative to node-glob. This library is experimental and does not work on windows!
Stars: ✭ 54 (-97.1%)
Mutual labels:  files, patterns, glob
globrex
Glob to regular expression with support for extended globs.
Stars: ✭ 52 (-97.21%)
Mutual labels:  glob, globbing
tartifacts
📦 Create artifacts for your assemblies
Stars: ✭ 20 (-98.93%)
Mutual labels:  patterns, glob
jquery.filebrowser
File browser jQuery plugin
Stars: ✭ 29 (-98.44%)
Mutual labels:  files, directories
koa-ip-filter
koa middleware to filter request IPs or custom ID with glob patterns, array, string, regexp or matcher function. Support custom 403 Forbidden message and custom ID.
Stars: ✭ 23 (-98.77%)
Mutual labels:  matching, glob
files
Useful methods to manage files and directories
Stars: ✭ 27 (-98.55%)
Mutual labels:  files, directories
txr
Send files super easily to other computers/servers using WebSockets.
Stars: ✭ 20 (-98.93%)
Mutual labels:  files, directories
bash-glob
Bash-powered globbing for node.js. Alternative to node-glob. Does not work on Windows 9 and lower.
Stars: ✭ 13 (-99.3%)
Mutual labels:  files, glob
replace-in-files
Replace text in one or more files or globs.
Stars: ✭ 21 (-98.87%)
Mutual labels:  files, glob
extglob
Extended globs. Add (almost) the expressive power of regular expressions to glob patterns.
Stars: ✭ 25 (-98.66%)
Mutual labels:  glob, globbing
expand-brackets
Expand POSIX bracket expressions (character classes) in glob patterns.
Stars: ✭ 26 (-98.61%)
Mutual labels:  glob, globbing
deglob
📂 Take a list of glob patterns and return an array of file locations, respecting `.gitignore` and allowing for ignore patterns via `package.json`.
Stars: ✭ 38 (-97.96%)
Mutual labels:  patterns, glob
Is Glob
If you use globs, this will make your code faster. Returns `true` if the given string looks like a glob pattern or an extglob pattern. This makes it easy to create code that only uses external modules like node-glob when necessary, resulting in much faster code execution and initialization time, and a better user experience. 55+ million downloads.
Stars: ✭ 63 (-96.62%)
Mutual labels:  matching, glob
Voila
Voila is a domain-specific language launched through CLI tool for operating with files and directories in massive amounts in a fast & reliable way.
Stars: ✭ 78 (-95.82%)
Mutual labels:  files, directories
Copy Webpack Plugin
Copy files and directories with webpack
Stars: ✭ 2,679 (+43.72%)
Mutual labels:  files, glob
matched
Glob matching with support for multiple patterns and negation. Use `~` in cwd to find files in user home, or `@` for global npm modules.
Stars: ✭ 25 (-98.66%)
Mutual labels:  files, glob
diskusage
FANTASTIC SPEED utility to find out top largest folders/files on the disk.
Stars: ✭ 64 (-96.57%)
Mutual labels:  files, directories
Tiny Glob
Super tiny and ~350% faster alternative to node-glob
Stars: ✭ 710 (-61.91%)
Mutual labels:  patterns, glob

globby

User-friendly glob matching

Based on fast-glob but adds a bunch of useful features.

Features

  • Promise API
  • Multiple patterns
  • Negated patterns: ['foo*', '!foobar']
  • Expands directories: foofoo/**/*
  • Supports .gitignore

Install

$ npm install globby

Usage

├── unicorn
├── cake
└── rainbow
import {globby} from 'globby';

const paths = await globby(['*', '!cake']);

console.log(paths);
//=> ['unicorn', 'rainbow']

API

Note that glob patterns can only contain forward-slashes, not backward-slashes, so if you want to construct a glob pattern from path components, you need to use path.posix.join() instead of path.join().

globby(patterns, options?)

Returns a Promise<string[]> of matching paths.

patterns

Type: string | string[]

See supported minimatch patterns.

options

Type: object

See the fast-glob options in addition to the ones below.

expandDirectories

Type: boolean | string[] | object
Default: true

If set to true, globby will automatically glob directories for you. If you define an Array it will only glob files that matches the patterns inside the Array. You can also define an object with files and extensions like below:

import {globby} from 'globby';

(async () => {
	const paths = await globby('images', {
		expandDirectories: {
			files: ['cat', 'unicorn', '*.jpg'],
			extensions: ['png']
		}
	});

	console.log(paths);
	//=> ['cat.png', 'unicorn.png', 'cow.jpg', 'rainbow.jpg']
})();

Note that if you set this option to false, you won't get back matched directories unless you set onlyFiles: false.

gitignore

Type: boolean
Default: false

Respect ignore patterns in .gitignore files that apply to the globbed files.

globbySync(patterns, options?)

Returns string[] of matching paths.

globbyStream(patterns, options?)

Returns a stream.Readable of matching paths.

Since Node.js 10, readable streams are iterable, so you can loop over glob matches in a for await...of loop like this:

import {globbyStream} from 'globby';

(async () => {
	for await (const path of globbyStream('*.tmp')) {
		console.log(path);
	}
})();

generateGlobTasks(patterns, options?)

Returns an object[] in the format {pattern: string, options: Object}, which can be passed as arguments to fast-glob. This is useful for other globbing-related packages.

Note that you should avoid running the same tasks multiple times as they contain a file system cache. Instead, run this method each time to ensure file system changes are taken into consideration.

isDynamicPattern(patterns, options?)

Returns a boolean of whether there are any special glob characters in the patterns.

Note that the options affect the results.

This function is backed by fast-glob.

isGitIgnored(options?)

Returns a Promise<(path: string) => boolean> indicating whether a given path is ignored via a .gitignore file.

Takes cwd?: string and ignore?: string[] as options. .gitignore files matched by the ignore config are not used for the resulting filter function.

import {isGitIgnored} from 'globby';

const isIgnored = await isGitIgnored();

console.log(isIgnored('some/file'));

isGitIgnoredSync(options?)

Returns a (path: string) => boolean indicating whether a given path is ignored via a .gitignore file.

Takes the same options as isGitIgnored.

Globbing patterns

Just a quick overview.

  • * matches any number of characters, but not /
  • ? matches a single character, but not /
  • ** matches any number of characters, including /, as long as it's the only thing in a path part
  • {} allows for a comma-separated list of "or" expressions
  • ! at the beginning of a pattern will negate the match

Various patterns and expected matches.

globby for enterprise

Available as part of the Tidelift Subscription.

The maintainers of globby and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.

Related

  • multimatch - Match against a list instead of the filesystem
  • matcher - Simple wildcard matching
  • del - Delete files and directories
  • make-dir - Make a directory and its parents if needed
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].