abi.js
Version:
[![typescript-icon]][typescript-link] [![license-icon]][license-link] [![status-icon]][status-link] [![ci-icon]][ci-link] [![twitter-icon]][twitter-link]
41 lines (40 loc) • 1.21 kB
JavaScript
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.
import { join } from "./join.js";
import { SEPARATOR } from "./constants.js";
import { normalizeGlob } from "./normalize_glob.js";
/**
* Like join(), but doesn't collapse "**\/.." when `globstar` is true.
*
* @example Usage
*
* ```ts
* import { joinGlobs } from "@std/path/windows/join-globs";
* import { assertEquals } from "@std/assert";
*
* const joined = joinGlobs(["foo", "**", "bar"], { globstar: true });
* assertEquals(joined, "foo\\**\\bar");
* ```
*
* @param globs The globs to join.
* @param options The options for glob pattern.
* @returns The joined glob pattern.
*/
export function joinGlobs(globs, { extended = true, globstar = false } = {}) {
if (!globstar || globs.length === 0) {
return join(...globs);
}
let joined;
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, { extended, globstar });
}