Comparing version 0.0.4 to 0.0.5
@@ -5,4 +5,4 @@ export interface IStorage { | ||
} | ||
export declare const clear: (storageKey: string, useSessionStorage?: boolean | undefined) => void; | ||
export declare const stash: (storageKey: string, data: any, useSessionStorage?: boolean | undefined) => void; | ||
export declare const retrieve: (storageKey: string, minutesToExpiration: number, useSessionStorage?: boolean | undefined) => any; | ||
export declare const clear: (storageKey: string, useSessionStorage?: boolean | undefined) => void; |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("stash",[],t):"object"==typeof exports?exports.stash=t():e.stash=t()}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";n.r(t),n.d(t,"stash",(function(){return u})),n.d(t,"retrieve",(function(){return i})),n.d(t,"clear",(function(){return f}));var r=function(e){return e?sessionStorage:localStorage},o=function(e){return"".concat(e).concat("_date")},u=function(e,t,n){var u=r(n),i=Math.floor((new Date).getTime()/1e3);u.setItem(e,JSON.stringify(t)),u.setItem(o(e),i.toString())},i=function(e,t,n){var u=r(n),i=+u.getItem(o(e)),c=u.getItem(e);if(c&&i)try{var a=+new Date,l=1e3*+new Date(i);Math.ceil(a-l/1e3/60)>t?(f(e,n),c=null):c=JSON.parse(c)}catch(e){}return c},f=function(e,t){var n=r(t);delete n[e],delete n[o(e)]}}]).default})); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("stash",[],t):"object"==typeof exports?exports.stash=t():e.stash=t()}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";n.r(t),n.d(t,"clear",(function(){return u})),n.d(t,"stash",(function(){return i})),n.d(t,"retrieve",(function(){return f}));var r=function(e){return e?sessionStorage:localStorage},o=function(e){return"".concat(e).concat("_date")},u=function(e,t){var n=r(t);delete n[e],delete n[o(e)]},i=function(e,t,n){var u=r(n),i=Math.floor((new Date).getTime()/1e3);u.setItem(e,JSON.stringify(t)),u.setItem(o(e),i.toString())},f=function(e,t,n){var i=r(n),f=+i.getItem(o(e)),c=f?i.getItem(e):null;if(c){var a=+new Date,l=1e3*+new Date(f);if(Math.ceil(a-l/1e3/60)>t)u(e,n),c=null;else try{c=JSON.parse(c)}catch(e){}}return c}}]).default})); | ||
//# sourceMappingURL=index.js.map |
@@ -6,2 +6,7 @@ // constants | ||
// exported methods | ||
export const clear = (storageKey, useSessionStorage) => { | ||
const storage = getStorage(useSessionStorage); | ||
delete storage[storageKey]; | ||
delete storage[getDateKey(storageKey)]; | ||
}; | ||
export const stash = (storageKey, data, useSessionStorage) => { | ||
@@ -16,25 +21,22 @@ const storage = getStorage(useSessionStorage); | ||
const storageDate = +storage.getItem(getDateKey(storageKey)); | ||
let data = storage.getItem(storageKey); | ||
if (!!data && !!storageDate) { | ||
try { | ||
const nowMs = +(new Date()); | ||
const storageMs = +(new Date(storageDate)) * 1000; | ||
const minutesOld = Math.ceil(nowMs - storageMs / 1000 / 60); | ||
if (minutesOld > minutesToExpiration) { | ||
clear(storageKey, useSessionStorage); | ||
data = null; | ||
} | ||
else { | ||
let data = !!storageDate | ||
? storage.getItem(storageKey) | ||
: null; | ||
if (!!data) { | ||
const nowMs = +(new Date()); | ||
const storageMs = +(new Date(storageDate)) * 1000; | ||
const minutesOld = Math.ceil(nowMs - storageMs / 1000 / 60); | ||
if (minutesOld > minutesToExpiration) { | ||
clear(storageKey, useSessionStorage); | ||
data = null; | ||
} | ||
else { | ||
try { | ||
data = JSON.parse(data); | ||
} | ||
catch (e) { } | ||
} | ||
catch (e) { } | ||
} | ||
return data; | ||
}; | ||
export const clear = (storageKey, useSessionStorage) => { | ||
const storage = getStorage(useSessionStorage); | ||
delete storage[storageKey]; | ||
delete storage[getDateKey(storageKey)]; | ||
}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "mini-stash", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "ES browser storage helper", | ||
@@ -5,0 +5,0 @@ "author": "Dean Verleger", |
@@ -43,5 +43,2 @@ # mini-stash | ||
// save to session storage | ||
stash(storageKey, data, false); | ||
// retrieve from local storage (discard if older than a day) | ||
@@ -48,0 +45,0 @@ let coords = retrieve(storageKey, 60 * 24); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
61
169082
95