### Install moduleRaid via npm Source: https://github.com/pedroslopez/moduleraid/blob/main/README.md This snippet shows how to install the moduleRaid package using npm, the Node Package Manager. This is the standard way to add the library to a JavaScript project for use with bundlers like Webpack or Parcel. ```bash $ npm install @pedroslopez/moduleRaid ``` -------------------------------- ### Testing WhatsApp Web Modules with Puppeteer and moduleraid Source: https://context7.com/pedroslopez/moduleraid/llms.txt This snippet demonstrates how to use Puppeteer to launch a browser, navigate to WhatsApp Web, inject and initialize moduleraid, and then extract module information. It shows how to get the total number of loaded modules and search for specific modules, such as the 'Chat' model. ```javascript const puppeteer = require('puppeteer'); const moduleRaid = require('@pedroslopez/moduleraid'); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.goto('https://web.whatsapp.com/', { waitUntil: 'load' }); // Inject moduleRaid into the page const modules = await page.evaluate((moduleRaidStr) => { window.eval('var moduleRaid = ' + moduleRaidStr); window.mR = moduleRaid(); return Object.keys(window.mR.modules); }, moduleRaid.toString()); console.log(`Loaded ${modules.length} modules`); // Search for specific modules const results = await page.evaluate(() => { return window.mR.findModule(m => m.default && m.default.modelName === 'Chat' ); }); console.log('Found Chat model modules:', results); await browser.close(); })(); ``` -------------------------------- ### Install moduleRaid via npm Source: https://context7.com/pedroslopez/moduleraid/llms.txt This command installs the moduleRaid library as a project dependency using npm. It ensures the library is available for use in Node.js environments or for bundling with client-side applications. ```bash npm install @pedroslopez/moduleraid ``` -------------------------------- ### Get All Modules using moduleRaid API Source: https://context7.com/pedroslopez/moduleraid/llms.txt This JavaScript code demonstrates how to retrieve all webpack modules managed by moduleRaid after initialization. It accesses the raw `modules` object and provides an example of iterating through all modules. ```javascript const mR = moduleRaid(); // Access raw modules object const allModules = mR.modules; console.log(Object.keys(allModules)); // ['123', '456', '789', ...] // Example: Iterate through all modules Object.keys(allModules).forEach(moduleId => { const module = allModules[moduleId]; console.log(`Module ${moduleId}:`, module); }); ``` -------------------------------- ### Get Module by ID using moduleRaid API Source: https://context7.com/pedroslopez/moduleraid/llms.txt This JavaScript code shows how to retrieve a specific webpack module using its unique ID with the `get` method of moduleRaid. It includes error handling for cases where the module is not found and demonstrates accessing module exports. ```javascript const mR = moduleRaid(); // Retrieve specific module by its webpack ID const module = mR.get('12345'); if (module) { console.log('Found module:', module); // Access module exports console.log('Module exports:', module.default); } else { console.log('Module not found'); } // Example: Get and use a specific module const chatModule = mR.get('789'); if (chatModule && chatModule.sendMessage) { chatModule.sendMessage('Hello!'); } ``` -------------------------------- ### Find Module by Function (Custom Query) with moduleRaid Source: https://context7.com/pedroslopez/moduleraid/llms.txt This JavaScript code illustrates how to use the `findModule` method with a custom function predicate to search for modules matching complex criteria. Examples include finding modules with specific function exports, property values, React component characteristics, and multiple conditions. ```javascript const mR = moduleRaid(); // Search using custom function predicate const results = mR.findModule(module => { return module.default && typeof module.default.sendMessage === 'function' && module.default.version === '2.0'; }); console.log('Modules matching criteria:', results); // Example: Find modules with specific property values const configModules = mR.findModule(m => m.default && m.default.apiEndpoint && m.default.apiEndpoint.includes('whatsapp.com') ); configModules.forEach(mod => { console.log('API Endpoint:', mod.default.apiEndpoint); }); // Example: Find React components const reactComponents = mR.findModule(m => m.default && m.default.prototype && m.default.prototype.isReactComponent ); console.log(`Found ${reactComponents.length} React components`); // Example: Find modules with multiple conditions const targetModule = mR.findModule(m => { if (!m.default) return false; return m.default.name === 'ChatController' && typeof m.default.getChats === 'function'; }); if (targetModule.length > 0) { const chats = targetModule[0].default.getChats(); console.log('Retrieved chats:', chats); } ``` -------------------------------- ### Initialize moduleRaid in JavaScript Source: https://github.com/pedroslopez/moduleraid/blob/main/README.md This JavaScript snippet shows the basic usage of moduleRaid. It requires the module and then assigns the returned instance to a global variable `mR` for easy access in the browser's global scope. This assumes a module-based environment like Node.js or a bundler. ```javascript const moduleRaid = require('moduleraid') window.mR = moduleRaid() ``` -------------------------------- ### Include moduleRaid via Script Tag Source: https://github.com/pedroslopez/moduleraid/blob/main/README.md This snippet demonstrates how to include the moduleRaid library directly in an HTML file using a script tag. This method is suitable for directly using the library in the browser without a build process, making it available globally. ```html ``` -------------------------------- ### Initialize moduleRaid in Node.js/Module Environment Source: https://context7.com/pedroslopez/moduleraid/llms.txt This JavaScript code shows how to import and initialize moduleRaid in a Node.js or module-based environment. It assigns the initialized moduleRaid instance to `window.mR` for global access and logs the total module count. ```javascript const moduleRaid = require('@pedroslopez/moduleraid'); // Initialize and attach to window window.mR = moduleRaid(); // Access the module object console.log(Object.keys(window.mR.modules).length); // Shows total module count ``` -------------------------------- ### Initialize moduleRaid in Browser Console Source: https://context7.com/pedroslopez/moduleraid/llms.txt This JavaScript snippet illustrates how moduleRaid is automatically initialized as `window.mR` when loaded via a script tag or pasted into the browser's developer console. It then shows how to access the `modules` object. ```javascript // When loaded as script tag or manually pasted into console // moduleRaid automatically initializes as window.mR console.log(window.mR.modules); // Object containing all webpack modules ``` -------------------------------- ### Advanced moduleraid Usage: Chaining, Caching, and Indexing Source: https://context7.com/pedroslopez/moduleraid/llms.txt This snippet explores advanced patterns for using moduleraid. It includes chaining multiple `findModule` calls to narrow down search results, implementing a caching mechanism for frequently accessed modules to improve performance, and building a custom index of modules categorized by functionality (chat, auth, UI). ```javascript // Pattern 1: Chain searches to narrow results const mR = moduleRaid(); const chatModules = mR.findModule(m => m.default && m.default.type === 'chat' ); const messagingModule = chatModules.find(m => m.default.sendMessage && m.default.receiveMessage ); console.log('Messaging module found:', messagingModule); // Pattern 2: Cache frequently accessed modules const moduleCache = {}; function getCachedModule(id) { if (!moduleCache[id]) { moduleCache[id] = mR.get(id); } return moduleCache[id]; } const cachedModule = getCachedModule('12345'); // Pattern 3: Build module index by functionality const moduleIndex = { chat: [], auth: [], ui: [] }; Object.keys(mR.modules).forEach(id => { const mod = mR.modules[id]; if (mod.sendMessage || mod.receiveMessage) { moduleIndex.chat.push({ id, module: mod }); } if (mod.authenticate || mod.login) { moduleIndex.auth.push({ id, module: mod }); } if (mod.render || mod.Component) { moduleIndex.ui.push({ id, module: mod }); } }); console.log('Chat modules:', moduleIndex.chat.length); console.log('Auth modules:', moduleIndex.auth.length); console.log('UI modules:', moduleIndex.ui.length); ``` -------------------------------- ### Error Handling and Safe Module Retrieval with moduleraid Source: https://context7.com/pedroslopez/moduleraid/llms.txt This code illustrates robust error handling when using moduleraid. It shows how to catch errors from invalid module search queries (e.g., passing a number instead of a string or function) and demonstrates safe functions for retrieving modules by ID and searching for modules, returning null or empty arrays respectively in case of errors. ```javascript const mR = moduleRaid(); try { // Invalid query type will throw TypeError const results = mR.findModule(12345); } catch (error) { console.error('Error:', error.message); // Error: findModule can only find via string and function, number was passed } // Safe module retrieval function safeGetModule(id) { try { const module = mR.get(id); return module || null; } catch (error) { console.error(`Failed to get module ${id}:`, error); return null; } } // Safe module search function safeSearch(query) { try { const results = mR.findModule(query); return results.length > 0 ? results : []; } catch (error) { console.error('Search failed:', error); return []; } } const module = safeGetModule('12345'); const searchResults = safeSearch('sendMessage'); ``` -------------------------------- ### Enable moduleRaid Debug Mode Source: https://github.com/pedroslopez/moduleraid/blob/main/README.md This JavaScript snippet illustrates how to enable debug mode for moduleRaid. By setting `window.mRdebug` to `true` before the script is loaded or executed, you can enable suppressed error messages and additional logging, which is useful for troubleshooting. ```javascript window.mRdebug = true ``` -------------------------------- ### Find Module by Property Name (String Query) with moduleRaid Source: https://context7.com/pedroslopez/moduleraid/llms.txt This JavaScript code demonstrates how to find modules that export a specific property name using the `findModule` method with a string query. It returns an array of matching modules and shows how to check for the property in default or direct exports. ```javascript const mR = moduleRaid(); // Search for modules that export a specific property const results = mR.findModule('sendMessage'); console.log(`Found ${results.length} modules with 'sendMessage' property`); // Results is an array of matching modules results.forEach(mod => { console.log('Module with sendMessage:', mod); // Check if property is in default export if (mod.default && mod.default.sendMessage) { console.log('Found in default export'); } // Check if property is direct export if (mod.sendMessage) { console.log('Found as direct export'); } }); // Example: Find authentication module const authModules = mR.findModule('isAuthenticated'); if (authModules.length > 0) { const authStatus = authModules[0].isAuthenticated(); console.log('User authenticated:', authStatus); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.