This repository has been archived by the owner on Feb 24, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
marlon_trapp
committed
Nov 13, 2017
1 parent
11ee8ae
commit bc54513
Showing
3 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
|
||
import * as Cookies from "js-cookie"; | ||
|
||
/** @class */ | ||
export default class CookieStorage { | ||
|
||
/** | ||
* Constructs a new CookieStorage object | ||
* @param {object} data Creation options. | ||
* @param {string} data.domain Cookies domain (mandatory). | ||
* @param {string} data.path Cookies path (default: '/') | ||
* @param {integer} data.expires Cookie expiration (in days, default: 365) | ||
*/ | ||
constructor(data) { | ||
this.domain = data.domain; | ||
if (data.path) { | ||
this.path = data.path; | ||
} else { | ||
this.path = '/'; | ||
} | ||
if (data.expire){ | ||
this.expires = data.expires; | ||
} else { | ||
this.expires = 365; | ||
} | ||
} | ||
|
||
/** | ||
* This is used to set a specific item in storage | ||
* @param {string} key - the key for the item | ||
* @param {object} value - the value | ||
* @returns {string} value that was set | ||
*/ | ||
setItem(key, value) { | ||
Cookies.set(key, value, {path: this.path, expires: this.expires, domain: this.domain}); | ||
return Cookies.get(key); | ||
} | ||
|
||
/** | ||
* This is used to get a specific key from storage | ||
* @param {string} key - the key for the item | ||
* This is used to clear the storage | ||
* @returns {string} the data item | ||
*/ | ||
getItem(key) { | ||
return Cookies.get(key) | ||
} | ||
|
||
/** | ||
* This is used to remove an item from storage | ||
* @param {string} key - the key being set | ||
* @returns {string} value - value that was deleted | ||
*/ | ||
removeItem(key) { | ||
return Cookies.remove(key, { path: this.path, domain: this.domain, secure: true}); | ||
} | ||
|
||
/** | ||
* This is used to clear the storage | ||
* @returns {string} nothing | ||
*/ | ||
clear() { | ||
var cookies = Cookies.get(); | ||
var index; | ||
for (index = 0; index < cookies.length; ++index) { | ||
Cookies.remove(cookies[index]); | ||
} | ||
return {}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters