diff options
Diffstat (limited to 'src/gleam_stdlib.js')
-rw-r--r-- | src/gleam_stdlib.js | 18 |
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) + ); + } +} |