+ },
+
+ /**
+ * Perform a substring search across the JavaScript and CSS source code
+ * of all loaded modules and return an array of the names of the
+ * modules that matched.
+ *
+ * @param {string|RegExp} pattern String or regexp to match.
+ * @return {Array} Array of the names of modules that matched.
+ */
+ grep: function ( pattern ) {
+ if ( typeof pattern.test !== 'function' ) {
+ // Based on Y.Escape.regex from YUI v3.15.0
+ pattern = new RegExp( pattern.replace( /[\-$\^*()+\[\]{}|\\,.?\s]/g, '\\$&' ), 'g' );
+ }
+
+ return $.grep( inspect.getLoadedModules(), function ( moduleName ) {
+ var module = mw.loader.moduleRegistry[moduleName];
+
+ // Grep module's JavaScript
+ if ( $.isFunction( module.script ) && pattern.test( module.script.toString() ) ) {
+ return true;
+ }
+
+ // Grep module's CSS
+ if (
+ $.isPlainObject( module.style ) && $.isArray( module.style.css )
+ && pattern.test( module.style.css.join( '' ) )
+ ) {
+ // Module's CSS source matches
+ return true;
+ }
+
+ return false;
+ } );