From d239710a593058a2762c3b18c44be07138d44f3c Mon Sep 17 00:00:00 2001 From: Richie Bendall Date: Tue, 28 Jun 2022 18:38:19 +1200 Subject: [PATCH 1/2] Throw when regex is not global Fixes #5 --- index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index.js b/index.js index a3628b0..b197983 100644 --- a/index.js +++ b/index.js @@ -41,6 +41,10 @@ export function firstMatch(regex, string, {timeout} = {}) { } export function matches(regex, string, {timeout = Number.POSITIVE_INFINITY, matchTimeout = Number.POSITIVE_INFINITY} = {}) { + if (!regex.global) { + throw new Error('RegExp must be global; otherwise use firstMatch instead'); + } + return { * [Symbol.iterator]() { try { From f48a8574c0238a756fa59dd5de9fb6a6b098638f Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Wed, 29 Jun 2022 02:50:38 +0200 Subject: [PATCH 2/2] Update index.js --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index b197983..d51938e 100644 --- a/index.js +++ b/index.js @@ -42,7 +42,7 @@ export function firstMatch(regex, string, {timeout} = {}) { export function matches(regex, string, {timeout = Number.POSITIVE_INFINITY, matchTimeout = Number.POSITIVE_INFINITY} = {}) { if (!regex.global) { - throw new Error('RegExp must be global; otherwise use firstMatch instead'); + throw new Error('The regex must have the global flag, otherwise, use `firstMatch()` instead'); } return {