Home Manual Reference Source Repository

src/utils/general.js

import Log from './Log';

/**
 * General-purpose utilties.
 */
class GeneralUtils {
    constructor() {
        /** @type {src/utils/Log.js~Log} */
        this.Log = Log;
    }


    /**
    * Executes the given callback on DOMContentLoaded.
    * @param {function(): void} callback
    */
    onLoad(callback) {
        if (document.readyState != 'loading') {
            callback();
        } else {
            document.addEventListener('DOMContentLoaded', () => {
                callback();
            });
        }
    }


    /**
     * Create a unique key suitable for storing in localStorage, etc.
     * @param {String}	namespace
     * @param {String}	key
     * @return {String}
     */
    safeStorageKey(namespace, key) {
        return '__'+namespace+'__'+key;
    }
}


/** @ignore */
export default new GeneralUtils;