Skip to main content
Home
This release is 1 version behind 1.0.9 — the latest version of @std/path. Jump to latest

Utilities for working with file system paths

This package works with Cloudflare Workers, Deno, Browsers
This package works with Cloudflare Workers
This package works with Deno
This package works with Browsers
JSR Score
100%
Published
6 months ago (1.0.8)
Package root>posix>join_globs.ts
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // This module is browser compatible. import type { GlobOptions } from "../_common/glob_to_reg_exp.ts"; import { join } from "./join.ts"; import { SEPARATOR } from "./constants.ts"; import { normalizeGlob } from "./normalize_glob.ts"; export type { GlobOptions }; /** * Like join(), but doesn't collapse "**\/.." when `globstar` is true. * * @example Usage * ```ts * import { joinGlobs } from "@std/path/posix/join-globs"; * import { assertEquals } from "@std/assert"; * * const path = joinGlobs(["foo", "bar", "**"], { globstar: true }); * assertEquals(path, "foo/bar/**"); * ``` * * @param globs The globs to join. * @param options The options to use. * @returns The joined path. */ export function joinGlobs( globs: string[], options: Pick<GlobOptions, "globstar"> = {}, ): string { const { globstar = false } = options; if (!globstar || globs.length === 0) { return join(...globs); } let joined: string | undefined; for (const glob of globs) { const path = glob; if (path.length > 0) { if (!joined) joined = path; else joined += `${SEPARATOR}${path}`; } } if (!joined) return "."; return normalizeGlob(joined, { globstar }); }