Skip to content

Commit

Permalink
docs: document and add examples of expandGlob (denoland/deno#6404)
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k authored and denobot committed Jan 31, 2021
1 parent 6416d6b commit d0055f4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
25 changes: 25 additions & 0 deletions fs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,28 @@ import {
writeFileStr("./target.dat", "file content"); // returns a promise
writeFileStrSync("./target.dat", "file content"); // void
```

### expandGlob

Expand the glob string from the specified `root` directory and yield each result
as a `WalkEntry` object.

```ts
import { expandGlob } from "https://deno.land/std/fs/mod.ts";

for await (const file of expandGlob("**/*.ts")) {
console.log(file);
}
```

### expandGlobSync

Synchronous version of `expandGlob()`.

```ts
import { expandGlobSync } from "https://deno.land/std/fs/mod.ts";

for (const file of expandGlobSync("**/*.ts")) {
console.log(file);
}
```
16 changes: 15 additions & 1 deletion fs/expand_glob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ function comparePath(a: WalkEntry, b: WalkEntry): number {
/**
* Expand the glob string from the specified `root` directory and yield each
* result as a `WalkEntry` object.
*
* Examples:
*
* for await (const file of expandGlob("**\/*.ts")) {
* console.log(file);
* }
*/
export async function* expandGlob(
glob: string,
Expand Down Expand Up @@ -161,7 +167,15 @@ export async function* expandGlob(
yield* currentMatches;
}

/** Synchronous version of `expandGlob()`. */
/**
* Synchronous version of `expandGlob()`.
*
* Examples:
*
* for (const file of expandGlobSync("**\/*.ts")) {
* console.log(file);
* }
*/
export function* expandGlobSync(
glob: string,
{
Expand Down

0 comments on commit d0055f4

Please sign in to comment.