import { AnyFunction , ConstructorModuleTuple , DefaultModuleLike , ModuleLike , ModuleList , ModuleRaidParameters , WebpackArgument , WebpackRequire , WebpackRequireFunction , } from './types' ; declare function webpackJsonp ( ... args ) ; /**
 * Main moduleRaid class
 */ export class ModuleRaid { default private entrypoint : string ; default private debug : boolean ; /**
     * A random generated module ID we use for injecting into Webpack
     */ private moduleID : string = Math . random ( ) . toString ( 36 ) . substring ( 7 ) ; internal private functionArguments : WebpackArgument [ ] = [ [ [ 0 ] , [ ( _e , _t , i ) => { const mCac = i . c ; Object . keys ( mCac ) . forEach ( ( mod ) => { this . modules [ mod ] = mCac [ mod ] . exports ; } ) ; this . constructors = i . m as AnyFunction [ ] ; this . get = i as unknown as WebpackRequireFunction ; } , ] , ] , [ [ 1e3 ] , { [ this . moduleID ] : ( _e , _t , i ) => { const mCac = i . c ; Object . keys ( mCac ) . forEach ( ( mod ) => { this . modules [ mod ] = mCac [ mod ] . exports ; } ) ; this . constructors = i . m as AnyFunction [ ] ; this . get = i as unknown as WebpackRequireFunction ; } , } , [ [ this . moduleID ] ] , ] , ] ; internal private arrayArguments : WebpackArgument [ ] = [ this . functionArguments [ 1 ] , [ [ this . moduleID ] , { } , ( e ) => { const mCac = e . m ; Object . keys ( mCac ) . forEach ( ( mod ) => { try { this . modules [ mod ] = ( e as unknown as WebpackRequireFunction ) ( mod ) ; } catch ( err ) { this . log ( `[arrayArguments/1] Failed to require(${ mod }) with error:\n${ err }\n${ err . stack }` ) ; } } ) ; this . get = e as unknown as WebpackRequireFunction ; } , ] , ] ; /**
     * Storage for the modules we extracted from Webpack
     */ public modules : ModuleList = { } ; /**
     * Storage for the constructors we extracted from Webpack
     */ public constructors : AnyFunction [ ] = [ ] ; /**
     * Intermediary storage for __webpack_require__ if we were able to extract it
     */ public get : WebpackRequireFunction | null = null ; example param opts constructor ( opts ? ) { let options = { entrypoint : 'webpackJsonp' , debug : false , } ; if ( typeof opts === 'object' ) { options = { ... options , ... opts , } ; } else if ( typeof opts === 'boolean' ) { console . warn ( `[moduleRaid] Using a single boolean argument is deprecated, please use 'new ModuleRaid({ debug: true })'` ) ; options . debug = opts ; } this . entrypoint = options . entrypoint ; this . debug = options . debug ; this . fillModules ( ) ; this . replaceGet ( ) ; } /**
     * Debug logging method, outputs to the console when  ModuleRaid . debug is true
     *
     *  param { * } message internal private log ( message ) { if ( this . debug ) { console . warn ( `[moduleRaid] ${ message }` ) ; } } internal private replaceGet ( ) { if ( this . get === null ) { this . get = ( key ) => this . modules [ key ] ; } } internal private fillModules ( ) { if ( typeof webpackJsonp === 'function' ) { this . functionArguments . forEach ( ( argument , index ) => { try { window [ this . entrypoint ] ( ... argument ) ; } catch ( err ) { this . log ( `moduleRaid.functionArguments[${ index }] failed:\n${ err }\n${ err . stack }` ) ; } } ) ; } else { this . arrayArguments . forEach ( ( argument , index ) => { try { ( window [ this . entrypoint ] as ModuleLike [ ] ) . push ( argument ) ; if ( this . modules && Object . keys ( this . modules ) . length > 0 ) return ; } catch ( err ) { this . log ( `Pushing moduleRaid.arrayArguments[${ index }] into ${ this . entrypoint } failed:\n${ err }\n${ err . stack }` ) ; } } ) ; } if ( this . modules && Object . keys ( this . modules ) . length == 0 ) { let moduleEnd = false ; let moduleIterator = 0 ; if ( ! window [ this . entrypoint ] ( [ ] , [ ] , [ moduleIterator ] ) ) { throw Error ( 'Unknown Webpack structure' ) ; } while ( ! moduleEnd ) { try { this . modules [ moduleIterator ] = window [ this . entrypoint ] ( [ ] , [ ] , [ moduleIterator ] ) ; moduleIterator ++ ; } catch ( err ) { moduleEnd = true ; } } } } example param query return public findModule ( query ) { const results = [ ] ; const modules = Object . keys ( this . modules ) ; if ( modules . length === 0 ) { throw new Error ( 'There are no modules to search through!' ) ; } modules . forEach ( ( key ) => { const module = this . modules [ key ] ; try { if ( typeof query === 'string' ) { query = query . toLowerCase ( ) ; switch ( typeof module ) { case 'string' : if ( module . includes ( query ) ) results . push ( module ) ; break ; case 'function' : if ( module . toString ( ) . toLowerCase ( ) . includes ( query ) ) results . push ( module ) ; break ; case 'object' : if ( typeof ( module as DefaultModuleLike ) . default === 'object' ) { for ( key in ( module as DefaultModuleLike ) . default ) { if ( key . toLowerCase ( ) === query ) results . push ( module ) ; } } for ( key in module ) { if ( key . toLowerCase ( ) === query ) results . push ( module ) ; } break ; } } else if ( typeof query === 'function' ) { if ( query ( module ) ) results . push ( module ) ; } else { throw new TypeError ( `findModule can only find via string and function, ${ typeof query } was passed` ) ; } } catch ( err ) { this . log ( `There was an error while searching through module '${ key }':\n${ err }\n${ err . stack }` ) ; } } ) ; return results ; } example param query returns public findConstructor ( query ) { const results = [ ] ; const constructors = Object . keys ( this . constructors ) ; if ( constructors . length === 0 ) { throw new Error ( 'There are no constructors to search through!' ) ; } constructors . forEach ( ( key ) => { const constructor = this . constructors [ key ] ; try { if ( typeof query === 'string' ) { query = query . toLowerCase ( ) ; if ( constructor . toString ( ) . toLowerCase ( ) . includes ( query ) ) results . push ( [ this . constructors [ key ] , this . modules [ key ] ] ) ; } else if ( typeof query === 'function' ) { if ( query ( constructor ) ) results . push ( [ this . constructors [ key ] , this . modules [ key ] ] ) ; } } catch ( err ) { this . log ( `There was an error while searching through constructor '${ key }':\n${ err }\n${ err . stack }` ) ; } } ) ; return results ; } }