@oazmi/build-tools
Version:
general deno build tool scripts which I practically use in all of my typescript repos
17 lines (16 loc) • 732 B
JavaScript
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.
import { normalize } from "./normalize.js";
import { SEPARATOR_PATTERN } from "./constants.js";
/** Like normalize(), but doesn't collapse "**\/.." when `globstar` is true. */
export function normalizeGlob(glob, { globstar = false } = {}) {
if (glob.match(/\0/g)) {
throw new Error(`Glob contains invalid characters: "${glob}"`);
}
if (!globstar) {
return normalize(glob);
}
const s = SEPARATOR_PATTERN.source;
const badParentPattern = new RegExp(`(?<=(${s}|^)\\*\\*${s})\\.\\.(?=${s}|$)`, "g");
return normalize(glob.replace(badParentPattern, "\0")).replace(/\0/g, "..");
}