window.Cookies = (function () {
    let set = function (name, value, expiredDays=30, path='/') {
        var exp = new Date(); 
        if (expiredDays == undefined) {
            expiredDays = 30;
        }
        exp.setTime(exp.getTime() + expiredDays * 24 * 60 * 60 * 1000); 
        document.cookie = name + "="+ escape(value) + ";expires=" + exp.toGMTString() + ";path="+path; 
    },
    setObj = function (name, obj, expiredDays=30, path='/') {
        return set(name, JSON.stringify(obj), expiredDays, path);
    },
    get = function (name, defaultVal) {
        var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
        if(arr = document.cookie.match(reg))
            return unescape(arr[2]); 
        else 
            return defaultVal !== undefined ? defaultVal : null; 
    },
    getObj = function (name, defaultVal) {
        var r = null;
        return r = get(name), r ? JSON.parse(r) : defaultVal !== undefined ? defaultVal : null;
    },
    del = function(name) {
        this.set(name, "", -1);
    };
    return {
        set: set, setObj: setObj, get: get, getObj: getObj, del: del
    }
})();