function isNonEmptyString ( s ) { return isString ( s ) && s !== '' ; } function isString ( o ) { return typeof o === 'string' ; } function set ( key , value , options = { } ) { const d = new Date ( ) ; const expires = options . expires ; const domain = options . domain ; const path = options . path ; let text = `${ key }=${ value }` ; let date = expires ; if ( typeof date === 'number' ) { date = new Date ( ) ; date . setDate ( date . getDate ( ) + expires ) ; } if ( date instanceof Date ) { text += '; expires=' + date . toUTCString ( ) ; } if ( isNonEmptyString ( domain ) ) { text += '; domain=' + domain ; } if ( isNonEmptyString ( path ) ) { text += '; path=' + path ; } if ( options . secure ) { text += '; secure' ; } document . cookie = text ; return text ; } function get ( key ) { const value = `${ key }=` ; const cookies = document . cookie . split ( ';' ) ; let i = 0 ; for ( const cookie of cookies ) { const c = cookie . trim ( ) ; if ( c . indexOf ( value ) === 0 ) { return c . substring ( value . length , c . length ) ; } i ++ ; } return '' ; } function remove ( key , options = { } ) { options . expires = new Date ( 0 ) ; return set ( key , '' , options ) ; } export { get , remove , set } ;