Skip to content

MMSB-MOBI/glob-spwan

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

glob-spwan

A Wrapper of the glob package in a multiprocess environment. This package deals with file system searches by spawning process foreach search. Within a process, npm glob is used to perform the search. The present package exposes the search results through a simple async/await API

installation

npm i glob-spawn

Usage

Just pass a valid glob pattern to the find function.

import { find } from 'glob-spawn';
 try {
    const files = await find('src/**/*.ts');
    console.log(files);
} catch(e) {
    console.log(e);
}
/* Will display
[
  'src/dto.ts',
  'src/index.ts',
  'src/test/find_arg_opt.ts',
  'src/test/find_arg.ts',
  'src/worker.ts'
]
*/

Options

Use the optional second argument to specify the working directory for the search. Matching files paths will be relative to this directory.

import { find } from 'glob-spawn';
 try {
    const files = await find('**/*.ts', { cwd : 'src'});
    console.log(files);
} catch(e) {
    console.log(e);
}
/* will display
[
  'dto.ts',
  'index.ts',
  'test/find_arg_opt.ts',
  'test/find_arg.ts',
  'worker.ts'
]
*/

Pattern matching (taken from official glob package)

Before parsing the path part patterns, braced sections are expanded into a set. Braced sections start with { and end with }, with any number of comma-delimited sections within. Braced sections may contain slash characters, so a{/b/c,bcd} would expand into a/b/c and abcd.

The following characters have special magic meaning when used in a path portion:

* Matches 0 or more characters in a single path portion

? Matches 1 character
[...] Matches a range of characters, similar to a RegExp range. If the first character of the range is ! or ^ then it matches any character not in the range.

!(pattern|pattern|pattern) Matches anything that does not match any of the patterns provided.

?(pattern|pattern|pattern) Matches zero or one occurrence of the patterns provided.

+(pattern|pattern|pattern) Matches one or more occurrences of the patterns provided.

*(a|b|c) Matches zero or more occurrences of the patterns provided

@(pattern|pat*|pat?erN) Matches exactly one of the patterns provided

** If a "globstar" is alone in a path portion, then it matches zero or more directories and subdirectories searching for matches. It does not crawl symlinked directories.

About

Wrapping glob package in mutliprocess

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published