Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ship a function to quote regular expressions. #37033

Closed
benjamingr opened this issue Jan 23, 2021 · 5 comments
Closed

Ship a function to quote regular expressions. #37033

benjamingr opened this issue Jan 23, 2021 · 5 comments
Labels
discuss Issues opened for discussions and feedbacks. lib / src Issues and PRs related to general changes in the lib or src directory. util Issues and PRs related to the built-in util module.

Comments

@benjamingr
Copy link
Member

Hey,

One of the most "obvious" missing features in Node.js regular expressions that every other platform ships is the ability to "escape" them. That is:

var str = prompt("Please enter a string");
str = escape(str);
const re = new RegExp(str, "g"); // handles reg exp special tokens with the replacement.

There are multiple packages doing this subtly incorrectly on NPM - lodash, escape-regexp and a few others.

I've worked on a TC39 proposal to add this API to the language and it is being considered again - but if the language committee rejects the proposal - the next best place is the platform.

My current plan is:

  • Try to request that the the language committee add this missing feature. Jordan has helpfully volunteered to raise this in the January TC39 meeting and possibly champion the proposal.
  • If TC39 shuts it down - make a PR to add a utility function to Node.js as suggested on that issue.

In regards to other languages and platforms - it seems that some ship this sort of API as part of the language and some do so as part of the platform.

I am opening this issue here for discussion of the plan.

An alternative suggested by some whatwg members is trying to coordinate this sort of API with them.

@benjamingr benjamingr added util Issues and PRs related to the built-in util module. lib / src Issues and PRs related to general changes in the lib or src directory. labels Jan 23, 2021
@benjamingr
Copy link
Member Author

Bikeshedding: util.escapeRegExpString which does the correct thing and keeps up to date with RegExp enhancements sound good to me.

@tniessen
Copy link
Member

Your TC39 proposal seems very reasonable to me! 👍

@tniessen tniessen added the discuss Issues opened for discussions and feedbacks. label Jan 27, 2021
@benjamingr
Copy link
Member Author

TC39 has agreed to promote the proposal to stage 1 - so I'd really rather pursue it there first.

@jasnell
Copy link
Member

jasnell commented Feb 22, 2021

@benjamingr ... any objections to converting this into a discussion rather than keeping it open as an issue?

@benjamingr
Copy link
Member Author

@jasnell sure

@targos targos closed this as completed Feb 23, 2021
@nodejs nodejs locked and limited conversation to collaborators Feb 23, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
discuss Issues opened for discussions and feedbacks. lib / src Issues and PRs related to general changes in the lib or src directory. util Issues and PRs related to the built-in util module.
Projects
None yet
Development

No branches or pull requests

4 participants