1- import { TestInput } from "@/types/TestInput" ;
2- import { TestOutput } from "@/types/TestOutput" ;
3-
41type PortableCodes = "ignorecase" | "multiline" | "comments" | "dotall" ;
52
63export type RegexOption = {
74 code : string ;
8- legacyCode ?: string ; // for the original RegexPlanet backends
9- portableCode ?: PortableCodes ; // for translating this code when switching to other engines
10- numericCode ?: number ; // the value for engines that use a numeric bitmask for options
5+ legacyCode ?: string ; // for the original RegexPlanet backends
6+ portableCode ?: PortableCodes ; // for translating this code when switching to other engines
7+ numericCode ?: number ; // the value for engines that use a numeric bitmask for options
118 description : string ;
129} ;
1310
@@ -19,7 +16,7 @@ export type RegexExtraInput = {
1916 defaultValue : string ; // the default value to use if the user doesn't provide one
2017} ;
2118
22- type RegexEngine = {
19+ export type RegexEngine = {
2320 description : string ; // library or module name (do not include `short_name`)
2421 enabled : boolean ; // always true for now
2522 extra_inputs ?: RegexExtraInput [ ] ; // A list of extra inputs to gather from the user
@@ -39,29 +36,3 @@ type RegexEngine = {
3936 status_url ?: string ; // URL of the status endpoint
4037 test_url ?: string ; // URL of the test endpoint
4138} ;
42-
43- type TestFn = ( testInput : TestInput ) => Promise < TestOutput > ;
44-
45- function generateRemoteTestFn ( test_url : string ) : TestFn {
46-
47- return async ( testInput : TestInput ) : Promise < TestOutput > => {
48- // this is a bogus 'as', but next build insists on it
49- const postData =
50- `regex=${ encodeURIComponent ( testInput . regex ) } ` +
51- `&replacement=${ encodeURIComponent ( testInput . replacement ) } ` +
52- `&${ testInput . option . map ( ( option ) => `option=${ option } ` ) . join ( "&" ) } ` +
53- `&${ testInput . inputs . map ( ( input ) => `input=${ input } ` ) . join ( "&" ) } ` ;
54- const response = await fetch ( test_url , {
55- method : "POST" ,
56- body : postData ,
57- headers : {
58- "Content-Type" : "application/x-www-form-urlencoded" ,
59- } ,
60- } ) ;
61- const data = await response . json ( ) ;
62-
63- return data as TestOutput ;
64- }
65- }
66-
67- export { generateRemoteTestFn , type RegexEngine , type TestFn } ;
0 commit comments