-
-
Notifications
You must be signed in to change notification settings - Fork 15
Description
Hello! Your DM suggested I share some thoughts on the library, but since it would be lengthy to fit into a single Twitter meessage, I put them into this issue. I think it might be too many to open one issue per item, so I've put them all here for you:
-
It would be great if subroutines could be defined separately from the regex body.
I could have defined them with variables outside and directly interpolated them without the use of subroutines, but consider:const dateRegex = regex`\d{4}-\d{2}-\d{2}`; // I want to but can't name the variable `date` const { groups: { date, time } } = regex`(?<date>${dateRegex})[T ](?<time>${timeRegexFromElsewhere})`.exec(str);
This causes pollution to the current scope, while
const { groups: { date, time } } = regex({ subroutines: { date: regex`\d{4}-\d{2}-\d{2}`, time: timeRegexFromElsewhere, }, })`(?<date>\g<date>)[T ](?<time>\g<time>)`.exec(str);
doesn't.
-
It might be out of scope, but you want to think about transforming Unicode properties that aren't yet supported in ECMAScript, i.e. those other than
General_Category,ScriptandScript_Extensions. The particularly useful ones areBlock(blk),East_Asian_Width(ea),Numeric_Type(nt) andVertical_Orientation(vo). (I once neededEast_Asian_Widthin my project, and ended up another dependency specific to it.) -
Consider allowing direct interpolation after
\u,\p,\Pand\qto get rid of the tricky{${…}}syntax. -
A subtle one, but let's wrap
regex.jsline 109 in atryblock such that the transformedRegExpis visible on error.
Some questions:
-
What is the point to use
patterns instead of directly interpolatingregexs inside aregex, given that flags can be altered andRegExps can be nested withregexbut not withpattern? -
Is there any particular reason not to use
[Symbol.match]and[Symbol.replace]but a(n optional) wrapper class? Is it because using them would be insufficient to cover all cases?