import { Log } from '@microsoft/sp-core-library' ; const LOG_SOURCE = 'Utilities' ; export default class Utilities { public static getFromSessionStorage ( key ) { let sessionValue = null ; try { if ( key !== undefined && key ) { sessionValue = window . sessionStorage . getItem ( key ) ; } } catch ( error ) { Log . error ( LOG_SOURCE , error ) ; } return sessionValue ; } public static updateSessionStorage ( key , value ) { try { if ( key && key !== undefined && value && value !== undefined ) { window . sessionStorage . setItem ( key , value ) ; } } catch ( error ) { Log . error ( LOG_SOURCE , error ) ; } } public static setCookie ( cName , cValue , exDays ) { try { let expires = "" ; if ( exDays ) { let d = new Date ( ) ; d . setTime ( d . getTime ( ) + ( exDays * 24 * 60 * 60 * 1000 ) ) ; expires = "expires=" + d . toUTCString ( ) ; } document . cookie = cName + "=" + cValue + ";" + expires + ";path=/" ; } catch ( error ) { Log . error ( LOG_SOURCE , error ) ; } } public static getCookie ( cName ) { try { let name = cName + "=" ; let decodedCookie = decodeURIComponent ( document . cookie ) ; let ca = decodedCookie . split ( ';' ) ; for ( let i = 0 ; i < ca . length ; i ++ ) { let c = ca [ i ] ; while ( c . charAt ( 0 ) == ' ' ) { c = c . substring ( 1 ) ; } if ( c . indexOf ( name ) == 0 ) { return c . substring ( name . length , c . length ) ; } } return "" ; } catch ( error ) { Log . error ( LOG_SOURCE , error ) ; } } }