Skip to content

Commit

Permalink
using namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Oct 17, 2023
1 parent 273d138 commit c8b4782
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ export default class Cookie
*
* @return {void}
*/
constructor()
constructor(namespace = '')
{
//
this.namespace = namespace;
}

/**
Expand All @@ -22,6 +22,8 @@ export default class Cookie
*/
set(key, value, expires = null, path = '/', options = {})
{
key = this.namespace + key;

const pairs = Object.assign({
[key]: value,
expires: expires instanceof Date ? expires.toUTCString() : expires,
Expand All @@ -42,6 +44,8 @@ export default class Cookie
*/
get(key, value = null)
{
key = this.namespace + key;

const cookie = document.cookie.match(new RegExp('(^| )' + key + '=([^;]+)'));

return (cookie && cookie[2]) ? cookie[2] : value;
Expand All @@ -55,6 +59,8 @@ export default class Cookie
*/
isset(key)
{
key = this.namespace + key;

return document.cookie.match(new RegExp('(^| )' + key + '=([^;]+)')) !== null;
}

Expand All @@ -66,6 +72,8 @@ export default class Cookie
*/
remove(key)
{
key = this.namespace + key;

this.set(key, null, 'Thu, 01 Jan 1970 00:00:01 GMT');
}
}

0 comments on commit c8b4782

Please sign in to comment.