nodejs / nodejs/node

`path.escapeGlob`

未关闭
#61,258 2 条评论 3 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

feature request
主要语言
JavaScript
星标
122k
派生
37.4k
平均合并
4 天 3 小时
30 天内合并 PR
272

描述

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, "[$&]");

And this:

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

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.

Edit: Shortened regex replacement from (...) -> $1 to ... -> $&.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先阅读 issue #58988 以及现有的 path API 文档和测试,以了解已经覆盖的特殊字符和平台行为。比较针对任意路径所提议的 escaping 和 unescaping 语义;完成的要求是达成一致的 API 契约,并提供相匹配的实现、测试和文档。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript
领域
api
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
冷清
描述清晰度
基本清楚
新手友好度
42/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。