@didavid61202 @danielroe , As I was working on issue #7, two issues/points of clarification for the API came to mind.
Allowing for custom regex patterns
Unless there is a function that I don't know of, a user can't add to an expression using custom regex unless it is exported as one of the helpers for specific RegExp characters such as digit
, whitespace
, letter
, etc. For example, using the current API there is no way to include the following regex pattern [1-9]
without it being passed to exactly()
and ending up as \[1-9\]
.
import { exactly } from "magic-regexp";
const test = exactly("foo").and("[1-9]"); // foo\[1-9\]
Note: the regex pattern was passed to exactly()
here
When working within the package, we can create these arbitrary regex patterns using createInput()
; however, this function isn't exported to end users.
Possible Solutions
- export an alias for
createInput
named one of the following input
, rawInput
,regex
, or some other suggestion
- leave as is and don't allow users to use custom regex patterns (I don't think this is an end goal of the package)
Providing an alias to createInput
would allow for patterns such as:
import { exactly, input } from "magic-regexp";
const test = exactly("foo").and(input("[1-9]")); // foo[1-9]
anyOf
@didavid61202 @danielroe, the anyOf
function states that it takes an array of inputs, but it doesn't really take an array; it takes an arbitrary number of arguments. The function documentation stating it takes an array can lead to confusion, and in fact, it confused me when I first started using this package.
Consider the following examples:
import { anyOf } from "magic-regexp";
const test1 = anyOf(...["a", "b", "c"]); //(?:a|b|c)
const test2 = anyOf("a", "b", "c"); //(?:a|b|c)
const test3 = anyOf(["a", "b", "c"]); //(?:a,b,c)
const test4 = anyOf("abc"); //(?:abc)
Possible Solutions
- leave as is, and change the documentation
- accept arrays, and do the array unpacking within the function
- overload the function to allow for the passing of arrays