2024-02-23 23:48:03 +01:00
import { Operator } from "../functions" ;
import i18next from "i18next" ;
2024-02-27 21:51:03 +01:00
const compileTimeOperatorList : string [ ] = [ "impose" ] ; import . meta . compileTime ( "./listOperatorsInDir.ts" ) ; // The will compile to ["impose", "extractPages", etc...]
2024-02-23 23:48:03 +01:00
export async function getOperatorByName ( name : string ) : Promise < typeof Operator | undefined > {
// Check if exists
2024-02-27 21:51:03 +01:00
if ( ! compileTimeOperatorList . includes ( name ) ) return ;
2024-02-23 23:48:03 +01:00
i18next . loadNamespaces ( name , ( err , t ) = > { if ( err ) throw err ; } ) ;
2024-02-27 21:51:03 +01:00
const loadedModule = await import ( "../functions/" + name + ".ts" ) ;
return loadedModule [ capitalizeFirstLetter ( name ) ] ;
2024-02-23 23:48:03 +01:00
}
export function listOperatorNames ( ) : string [ ] {
2024-02-27 21:51:03 +01:00
const availableOperators = compileTimeOperatorList ;
2024-02-23 23:48:03 +01:00
// TODO: Implement this
return availableOperators ;
}
function capitalizeFirstLetter ( string : String ) {
return string . charAt ( 0 ) . toUpperCase ( ) + string . slice ( 1 ) ;
}