var md5 = require('md5');

/*
 * JavaScript utilities.
 */
export default class Utils {
    /*
     * Formats a Date() object into a string.
     */
    static formatDateTime(date) {
        return moment(date).format('LLLL');
    }

    /*
     * Returns a Date() object from a string in the same format
     * as formatDateTime();
     */
    static dateFromString(dateTimeString) {
        if (typeof dateTimeString === 'object') {
            // Assume that dateTimeString is a Date() object
            // and reurn that.
            return dateTimeString;
        }

        return new Date(dateTimeString.replace(' ', 'T').replace('Z', ''));
    }

    /*
     * Get the Rails authenticity token.
     */
    static getAuthenticityToken() {
        return document.querySelector('meta[name=csrf-token').getAttribute('content');
    }

    static getGravatarUrl(email) {
        var hashedEmail = md5(email.trim().toLowerCase());
        return `https://www.gravatar.com/avatar/${hashedEmail}.jpg?s=32&d=mm`;
    }
}
var md5 = require('md5');

/*
 * JavaScript utilities.
 */
export default class Utils {
    /*
     * Formats a Date() object into a string.
     */
    static formatDateTime(date) {
        return moment(date).format('LLLL');
    }

    /*
     * Returns a Date() object from a string in the same format
     * as formatDateTime();
     */
    static dateFromString(dateTimeString) {
        if (typeof dateTimeString === 'object') {
            // Assume that dateTimeString is a Date() object
            // and reurn that.
            return dateTimeString;
        }

        return new Date(dateTimeString.replace(' ', 'T').replace('Z', ''));
    }

    /*
     * Get the Rails authenticity token.
     */
    static getAuthenticityToken() {
        return document.querySelector('meta[name=csrf-token]')
            .getAttribute('content');
    }

    static getGravatarUrl(email) {
        var hashedEmail = md5(email.trim().toLowerCase());
        return `https://www.gravatar.com/avatar/${hashedEmail}.jpg?s=32&d=mm`;
    }
}
Fix multiple JavaScript functions not working in Safari.
Fix multiple JavaScript functions not working in Safari.

Things such as adding attendees and agendums weren't working in
Safari. It seems that I was missing a closing brace in a query
selector, which Safari was strict on, causing Ajax requests to
fail because the CSRF token wasn't beening submitted.

Although the following link is for jQuery specifically, it lead
me in the right direction: https://stackoverflow.com/a/43209100
