Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

match-test-replace: modify match range #2

Open
azu opened this issue Nov 4, 2017 · 1 comment
Open

match-test-replace: modify match range #2

azu opened this issue Nov 4, 2017 · 1 comment

Comments

@azu
Copy link
Owner

azu commented Nov 4, 2017

Currently, first match range is final range.
We want to change the range at runtime.

@azu
Copy link
Owner Author

azu commented Nov 4, 2017

diff --git a/packages/match-test-replace/src/match-test-replace.ts b/packages/match-test-replace/src/match-test-replace.ts
index 0347700..10ca9a8 100644
--- a/packages/match-test-replace/src/match-test-replace.ts
+++ b/packages/match-test-replace/src/match-test-replace.ts
@@ -15,6 +15,8 @@ export interface TestMatchReplaceReturnDict {
     // match pattern
     // if the result of match `pattern` is falsy, return { ok: false }
     pattern: RegExp;
+    // sub match range
+    match?: (args: PatternMatchDictArgs) => RegExp;
     // test the result of match
     // if the result of `test` is true, allow to replace if needed
     test?: (args: PatternMatchDictArgs) => boolean;
@@ -130,6 +132,10 @@ export const matchTestReplace = (text: string, dict: TestMatchReplaceReturnDict)
             captures,
             all
         };
+        if(typeof dict.match === "function"){
+            dict.match(dictArgs);
+            // re replace and test
+        }
         if (typeof dict.test === "function") {
             isReplaceOK = dict.test(dictArgs);
         }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant