aboutsummaryrefslogtreecommitdiff
path: root/src/utils.js
blob: e0a4c768d7f1cd701c26598cb65ef8ae8cd9d6cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var UTILS = {
    getLocalStorage: function(key) {
        var localData = localStorage.getItem(key);
        var parsedData = JSON.parse(localData);

        return parsedData;
    },

    setLocalStorage: function(storageKey, data) {
        var stringifiedData = JSON.stringify(data);
        localStorage.setItem(storageKey, stringifiedData);
    },

    toJSON: function(data) {
        if (_.isObject(data)) {
            return data;
        }
        try {
            var o = JSON.parse(data);
            if (o && typeof o === "object") {
                return o;
            }
        } catch (e) {
            console.log(e);
        }

        return false;
    },
    isEmail: function(email) {
        var regex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,4}))$/;
        return regex.test(email);
    },
    isTag: function(content) {
        if (content.match(/<(\w+)((?:\s+\w+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/)) {
            return true;
        }
    }
}