-
Notifications
You must be signed in to change notification settings - Fork 621
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
449 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
import { globrex } from "./globrex.ts"; | ||
import { isAbsolute, join } from "./path/mod.ts"; | ||
import { WalkInfo, walk, walkSync } from "./walk.ts"; | ||
const { cwd } = Deno; | ||
|
||
export interface GlobOptions { | ||
// Allow ExtGlob features | ||
|
@@ -41,7 +44,11 @@ export interface GlobOptions { | |
* @returns A RegExp for the glob pattern | ||
*/ | ||
export function glob(glob: string, options: GlobOptions = {}): RegExp { | ||
return globrex(glob, options).regex; | ||
const result = globrex(glob, options); | ||
if (options.filepath) { | ||
return result.path!.regex; | ||
} | ||
return result.regex; | ||
} | ||
|
||
/** Test whether the given string is a glob */ | ||
|
@@ -76,3 +83,61 @@ export function isGlob(str: string): boolean { | |
|
||
return false; | ||
} | ||
|
||
export interface ExpandGlobOptions extends GlobOptions { | ||
root?: string; | ||
includeDirs?: boolean; | ||
} | ||
|
||
/** | ||
* Expand the glob string from the specified `root` directory and yield each | ||
* result as a `WalkInfo` object. | ||
*/ | ||
// TODO: Use a proper glob expansion algorithm. | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
nayeemrmn
Author
Contributor
|
||
// This is a very incomplete solution. The whole directory tree from `root` is | ||
// walked and parent paths are not supported. | ||
export async function* expandGlob( | ||
globString: string, | ||
{ | ||
root = cwd(), | ||
includeDirs = true, | ||
extended = false, | ||
globstar = false, | ||
strict = false, | ||
filepath = true, | ||
flags = "" | ||
}: ExpandGlobOptions = {} | ||
): AsyncIterableIterator<WalkInfo> { | ||
const absoluteGlob = isAbsolute(globString) | ||
? globString | ||
: join(root, globString); | ||
const globOptions = { extended, globstar, strict, filepath, flags }; | ||
yield* walk(root, { | ||
match: [glob(absoluteGlob, globOptions)], | ||
includeDirs | ||
}); | ||
} | ||
|
||
/** Synchronous version of `expandGlob()`. */ | ||
// TODO: As `expandGlob()`. | ||
export function* expandGlobSync( | ||
globString: string, | ||
{ | ||
root = cwd(), | ||
includeDirs = true, | ||
extended = false, | ||
globstar = false, | ||
strict = false, | ||
filepath = true, | ||
flags = "" | ||
}: ExpandGlobOptions = {} | ||
): IterableIterator<WalkInfo> { | ||
const absoluteGlob = isAbsolute(globString) | ||
? globString | ||
: join(root, globString); | ||
const globOptions = { extended, globstar, strict, filepath, flags }; | ||
yield* walkSync(root, { | ||
match: [glob(absoluteGlob, globOptions)], | ||
includeDirs | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
@nayeemrmn please open issues for these TODOs