Code snippet management and execution system for reusable debugging code. The Snippets tool provides a way to store and execute frequently used code snippets for debugging and testing purposes.
Create, manage, and execute reusable code snippets.
/**
* Add code snippet
* @param name - Snippet name for identification
* @param fn - Function to execute when snippet is run
* @param desc - Description text for the snippet
* @returns Snippets instance for chaining
*/
add(name: string, fn: Function, desc: string): Snippets;
/**
* Remove snippet by name
* @param name - Snippet name to remove
* @returns Snippets instance for chaining
*/
remove(name: string): Snippets;
/**
* Execute snippet by name
* @param name - Snippet name to run
* @returns Snippets instance for chaining
*/
run(name: string): Snippets;
/**
* Remove all snippets
* @returns Snippets instance for chaining
*/
clear(): Snippets;Usage Examples:
const snippets = eruda.get('snippets');
// Add debugging snippets
snippets.add('Clear Console', () => {
console.clear();
}, 'Clear the console output');
snippets.add('Page Info', () => {
console.log('Title:', document.title);
console.log('URL:', window.location.href);
console.log('User Agent:', navigator.userAgent);
}, 'Display basic page information');
snippets.add('Performance Check', () => {
if (performance.memory) {
console.log('Memory Usage:', {
used: Math.round(performance.memory.usedJSHeapSize / 1024 / 1024) + 'MB',
total: Math.round(performance.memory.totalJSHeapSize / 1024 / 1024) + 'MB'
});
}
console.log('Load Time:', performance.timing.loadEventEnd - performance.timing.navigationStart + 'ms');
}, 'Check page performance metrics');
// Execute snippets
snippets.run('Page Info');
snippets.run('Performance Check');
// Remove snippet
snippets.remove('Clear Console');The Snippets tool comes with several built-in utility snippets and allows developers to create custom debugging functions for repeated use.