{"size": 2450, "ext": "js", "max_stars_repo_path": "frontend/helpers/_utils/session-storage-util.js", "max_stars_repo_name": "VolneiTonato/aggileDistribuidora", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "frontend/helpers/_utils/session-storage-util.js", "max_issues_repo_name": "VolneiTonato/aggileDistribuidora", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "frontend/helpers/_utils/session-storage-util.js", "max_forks_repo_name": "VolneiTonato/aggileDistribuidora", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.0196078431, "max_line_length": 107, "alphanum_fraction": 0.5530612245}
class SessionStorageUtil{

    static isSessionStorage(){
        return window['sessionStorage'] && (window['sessionStorage'] !== null)
    }


    
    static getStorage(key = '', isJson = true){
        if(!SessionStorageUtil.isSessionStorage())
            return null

        let now = Date.now()

        try{
            key = key.replace(/"/ig,'')
        }catch(err){
            
        }
        
        let expiresIn = window['sessionStorage'].getItem(`__cache__${key}_expiresIn`)
        if (expiresIn===undefined || expiresIn===null) { expiresIn = 0 }
    
        if (expiresIn < now) {
            SessionStorageUtil.removeStorage(`__cache__${key}`)
            SessionStorageUtil.removeStorage(`__cache__${key}_expiresIn`)
            return null
        }

        let data = window['sessionStorage'].getItem(`__cache__${key}`)

        if(data == null || ( data[0] == null ))
            return null

        


        return isJson == true ? JSON.parse(data) : data
    }


    static isStorageItem(key){
        if(!SessionStorageUtil.isSessionStorage())
            return false

        let data = SessionStorageUtil.getStorage(`__cache__${key}`, false)        
       
        return data !== null && (data.length > 0)
    }

    static setStorage(key, value, expires = (24*60*60*5) , isJson = true){
        if(!SessionStorageUtil.isSessionStorage())
            return null

        key = key.replace(/"/ig,'')
        
        window['sessionStorage'].setItem(`__cache__${key}`, isJson == true ? JSON.stringify(value) : value)

        if(expires){

            expires = Math.abs(expires)
            let now = Date.now()  //millisecs since epoch time, lets deal only with integer
            let schedule = now + expires * 1000
            window['sessionStorage'].setItem(`__cache__${key}_expiresIn`, schedule)
        }


        
    }

    static clear(){
        if(!SessionStorageUtil.isSessionStorage())
            return null

        window['sessionStorage'].clear()
    }

    static removeStorage(key){

        if(!key)
            return null


        if(!SessionStorageUtil.isSessionStorage())
            return null


        try{
            key = key.replace(/"/ig,'')
        }catch(err){

        }
        
        window['sessionStorage'].removeItem(`__cache__${key}`)
        window['sessionStorage'].removeItem(`__cache__${key}_expiresIn`)
    }

    
}


module.exports = SessionStorageUtil