@claspo/common 7.0.3-rc1 → 7.0.3-rc2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@claspo/common",
3
- "version": "7.0.3-rc1",
3
+ "version": "7.0.3-rc2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "engines": {
@@ -1,12 +1,8 @@
1
1
  import BaseCachingStorage from './BaseCachingStorage';
2
- interface CookieOptionsI {
3
- path?: string;
4
- expires?: Date | string;
5
- [key: string]: string | Date | boolean | undefined;
6
- }
2
+ import { CookieOptionsI } from './setCookie';
7
3
  declare class CachingCookieStorage extends BaseCachingStorage {
8
4
  get(name: string): string | null;
9
- set(name: string, value: string, options?: CookieOptionsI): void;
5
+ set(name: string, value: string | object, options?: CookieOptionsI): void;
10
6
  remove(name: string): void;
11
7
  }
12
8
  declare const _default: CachingCookieStorage;
@@ -1 +1 @@
1
- import BaseCachingStorage from"./BaseCachingStorage";class CachingCookieStorage extends BaseCachingStorage{get(e){const o=this._getFromCache(e);return null!==o?o:this._process(()=>{let o=document.cookie.match(new RegExp("(?:^|; )"+e.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g,"\\$1")+"=([^;]*)"));const t=o?decodeURIComponent(o[1]):null;return this._setToCache(e,t),t})}set(e,o,t={}){const n=Object.assign({path:"/",expires:new Date((new Date).getFullYear()+5,0)},t);n.expires instanceof Date&&(n.expires=n.expires.toUTCString());let s=encodeURIComponent(e)+"="+encodeURIComponent(o);for(const e in n){s+="; "+e;const o=n[e];!0!==o&&(s+="="+o)}const c="string"==typeof o?o:this._process(()=>JSON.stringify(o));this._setToCache(e,c),this._process(()=>(document.cookie=s,null))}remove(e){this._removeFromCache(e),this._process(()=>(document.cookie=encodeURIComponent(e)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/",null))}}export default new CachingCookieStorage;
1
+ import BaseCachingStorage from"./BaseCachingStorage";import getCookie from"./getCookie";import setCookie from"./setCookie";class CachingCookieStorage extends BaseCachingStorage{get(e){const o=this._getFromCache(e);return null!==o?o:this._process(()=>{var o;const t=null!==(o=getCookie(e))&&void 0!==o?o:null;return this._setToCache(e,t),t})}set(e,o,t={}){const s="string"==typeof o?o:this._process(()=>JSON.stringify(o));this._setToCache(e,s),this._process(()=>(setCookie(e,s,t),null))}remove(e){this._removeFromCache(e),this._process(()=>(setCookie(e,"",{expires:new Date(0)}),null))}}export default new CachingCookieStorage;
@@ -0,0 +1 @@
1
+ export default function getCookie(name: string): string | undefined;
@@ -0,0 +1 @@
1
+ export default function getCookie(e){try{const o=document.cookie.match(new RegExp("(?:^|; )"+e.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g,"\\$1")+"=([^;]*)"));return o?decodeURIComponent(o[1]):void 0}catch(e){return}}
@@ -0,0 +1,6 @@
1
+ export interface CookieOptionsI {
2
+ path?: string;
3
+ expires?: Date | string;
4
+ [key: string]: string | Date | boolean | undefined;
5
+ }
6
+ export default function setCookie(name: string, value: string | null, options?: CookieOptionsI): void;
@@ -0,0 +1 @@
1
+ import getCookie from"./getCookie";export default function setCookie(o,e,t={}){var n;const i=Object.assign({path:"/",expires:new Date((new Date).getFullYear()+5,0)},t);i.expires instanceof Date&&(i.expires=i.expires.toUTCString());let c=encodeURIComponent(o)+"="+encodeURIComponent(String(e));for(const o in i){c+="; "+o;const e=i[o];!0!==e&&(c+="="+e)}try{const t=null!==(n=location.host)&&void 0!==n?n:"localhost";if(1===t.split(".").length)return void(document.cookie=c+"; path=/");const i=t.split(".");i.shift();let s="."+i.join(".");document.cookie=c+"; path=/; domain="+s,null!=getCookie(o)&&getCookie(o)===String(e)||(s="."+t,document.cookie=c+"; path=/; domain="+s)}catch(o){}}