aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLouis Pilfold <louis@lpil.uk>2021-08-26 22:33:03 +0100
committerLouis Pilfold <louis@lpil.uk>2021-08-27 00:37:15 +0100
commitcb80cf508ac0990038ec6ee6cd90cb61eaeabe5c (patch)
tree1de16fb5230d355ab2e1518ca90be3efba6e7b65 /src
parent794f0740fa98a218bb210da1d96f39409e5907c6 (diff)
downloadgleam_stdlib-cb80cf508ac0990038ec6ee6cd90cb61eaeabe5c.tar.gz
gleam_stdlib-cb80cf508ac0990038ec6ee6cd90cb61eaeabe5c.zip
Regex compile and check
Diffstat (limited to 'src')
-rw-r--r--src/gleam_stdlib.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/gleam_stdlib.js b/src/gleam_stdlib.js
index c7db142..d2454ba 100644
--- a/src/gleam_stdlib.js
+++ b/src/gleam_stdlib.js
@@ -7,6 +7,7 @@ import {
toBitString,
stringBits,
} from "./gleam.js";
+import { CompileError as RegexCompileError } from "./gleam/regex.js";
const Nil = undefined;
@@ -228,3 +229,20 @@ export function bit_string_slice(bits, position, length) {
export function codepoint(int) {
return new UtfCodepoint(int);
}
+
+export function regex_check(regex, string) {
+ return regex.test(string);
+}
+
+export function compile_regex(pattern, options) {
+ try {
+ let flags = "";
+ if (options.case_insensitive) flags += "i";
+ if (options.multi_line) flags += "m";
+ return new Ok(new RegExp(pattern, flags));
+ } catch (error) {
+ return new Error(
+ new RegexCompileError(error.message, error.columnNumber || 0)
+ );
+ }
+}