Skip to content

path.escapeGlob #61258

Description

@valler

What is the problem this feature will solve?

Would allow to dynamically create glob patterns from arbitrary paths.

Example:

const pattern = `${path.escapeGlob(import.meta.dirname)}/*`;

What is the feature you are proposing to solve the problem?

Something similar in functionality to this:

// Wraps symbols which open groups `{`, `[`, `(`, and
// those with semantics independent of groups `*`, `?`
path.escapeGlob = (x = "") => x.replace(/([*{[(?])/g, "[$1]");

And this:

// inverse path.escapeGlob
path.unescapeGlob = (x = "") => x.replace(/\[(.)\]/g, "$1");

I was using #58988 as a reference for special chars.

What alternatives have you considered?

Using a user land package everywhere dynamic glob creation is required, or even for everything glob related to keep things consistent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.

    Type

    No type

    Projects

    Status
    Awaiting Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions