From c0ea9a99c0dc21faf46f73dca481361853e914fa Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Sun, 21 Jun 2020 03:34:28 +0900 Subject: [PATCH] docs: document and add examples of expandGlob (#6404) --- std/fs/README.md | 25 +++++++++++++++++++++++++ std/fs/expand_glob.ts | 16 +++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/std/fs/README.md b/std/fs/README.md index e0f0d85ce0..612b1393fd 100644 --- a/std/fs/README.md +++ b/std/fs/README.md @@ -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); +} +``` diff --git a/std/fs/expand_glob.ts b/std/fs/expand_glob.ts index 949f58f921..8a4b0ed03d 100644 --- a/std/fs/expand_glob.ts +++ b/std/fs/expand_glob.ts @@ -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, @@ -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, {