<commit_before>import { Module } from "../interfaces/iModule";
import { ModuleNames } from "./moduleNames";
import { _ } from "../utils";

export class ModuleRegistry {

    // having in a map a) removes duplicates and b) allows fast lookup
    private static modulesMap: { [name: string]: Module } = {};

    public static register(module: Module): void {
        this.modulesMap[module.moduleName] = module;
    }

    public static assertRegistered(moduleName: ModuleNames, reason: string): boolean {
        if (this.isRegistered(moduleName)) {
            return true;
        }

        const warningKey = reason + moduleName;
        const warningMessage = `ag-Grid: unable to use ${reason} as module ${moduleName} is not present. `
            + `You need to load the module with: import "${moduleName}"`;

        _.doOnce(() => { console.warn(warningMessage); }, warningKey);

        return false;
    }

    public static isRegistered(moduleName: ModuleNames): boolean {
        return !!this.modulesMap[moduleName];
    }

    public static getRegisteredModules(): Module[] {
        return _.values(this.modulesMap);
    }
}<commit_msg>AG-3603 Add ability to register modules globally<commit_after>import {Module} from "../interfaces/iModule";
import {ModuleNames} from "./moduleNames";
import {_} from "../utils";

export class ModuleRegistry {

    // having in a map a) removes duplicates and b) allows fast lookup
    private static modulesMap: { [name: string]: Module } = {};

    public static register(module: Module): void {
        ModuleRegistry.modulesMap[module.moduleName] = module;
    }

    public static registerModules(modules: Module[]): void {
        if(!modules) {
            return;
        }
        modules.forEach(ModuleRegistry.register);
    }

    public static assertRegistered(moduleName: ModuleNames, reason: string): boolean {
        if (this.isRegistered(moduleName)) {
            return true;
        }

        const warningKey = reason + moduleName;
        const warningMessage = `ag-Grid: unable to use ${reason} as module ${moduleName} is not present. `
            + `You need to load the module with: import "${moduleName}"`;

        _.doOnce(() => {
            console.warn(warningMessage);
        }, warningKey);

        return false;
    }

    public static isRegistered(moduleName: ModuleNames): boolean {
        return !!ModuleRegistry.modulesMap[moduleName];
    }

    public static getRegisteredModules(): Module[] {
        return _.values(ModuleRegistry.modulesMap);
    }
}
{'fraction_non_alphanumeric': 0.11529411764705882, 'fraction_numerical': 0.001568627450980392, 'mean_word_length': 2.8360902255639098, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5105584', 'n_tokens_mistral': 679, 'n_tokens_neox': 654, 'n_words': 202}