From 8a4d7a88ae6cdc89e4a794751307423d26892a69 Mon Sep 17 00:00:00 2001 From: Steven Levithan Date: Fri, 25 Oct 2024 13:13:59 +0200 Subject: [PATCH] Demo: toRegExp > compile --- demo/demo.js | 6 ++++-- demo/index.html | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/demo/demo.js b/demo/demo.js index 61c89d6..bf18e1d 100644 --- a/demo/demo.js +++ b/demo/demo.js @@ -22,13 +22,15 @@ function showOutput(el) { outputEl.classList.remove('error'); let output = ''; try { - const re = toRegExp(input, flags, { + // Don't actually run `toRegExp` in case the selected `target` includes features that don't + // work in the user's browser + const re = compile(input, flags, { allowBestEffort: optionAllowBestEffortValue, maxRecursionDepth: optionMaxRecursionDepthValue === '' ? null : +optionMaxRecursionDepthValue, optimize: optionOptimizeValue, target: optionTargetValue, }); - output = String(re); + output = `/${re.pattern ? re.pattern : '(?:)'}/${re.flags}`; } catch (e) { outputEl.classList.add('error'); output = `Error: ${e.message}`; diff --git a/demo/index.html b/demo/index.html index 1e292c5..0ae4cf8 100644 --- a/demo/index.html +++ b/demo/index.html @@ -59,13 +59,13 @@

Try it


-    

The output shows the result of calling toRegExp. Oniguruma-To-ES includes functions to generate additional formats: compile (returns an object with pattern and flags strings), toOnigurumaAst, and toRegexAst (for an AST based on regex). You can run all of these from the console on this page. compile and toRegExp accept pattern and flags strings and an options object. toOnigurumaAst and toRegexAst accept a pattern and flags. You can also pass ASTs to printAst.

+

The output shows the result of calling toRegExp. Oniguruma-To-ES includes functions to generate additional formats: compile (returns an object with pattern and flags strings), toOnigurumaAst, and toRegexAst (for an AST based on regex). You can run all of these from the console on this page. compile and toRegExp accept pattern and flags strings and an options object. toOnigurumaAst and toRegexAst accept a pattern and flags. You can also pass AST results to printAst.