* Converts a `DEBUG`-style namespace pattern into an anchored regex. * Regex metacharacters are escaped to match literally, and `*` is translated * into `.*?` so it behaves as a glob wildcard.
(namespace: string)
| 50 | * into `.*?` so it behaves as a glob wildcard. |
| 51 | */ |
| 52 | function namespaceToRegExp(namespace: string): RegExp { |
| 53 | const escaped = namespace |
| 54 | .replace(/[.+?^${}()|[\]\\]/g, "\\$&") |
| 55 | .replace(/\*/g, ".*?"); |
| 56 | |
| 57 | return new RegExp(`^${escaped}$`); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Checks whether a namespace is enabled under the given `DEBUG` pattern string. |