!function(n,e){"function"==typeof define&&define.amd?define([],e):"undefined"!=typeof module&&module.exports?module.exports=e():n.lscache=e()}(this,function(){var n,e,t="lscache-",r="-cacheexpiration",o=10,i=6e4,c=_(i),u="",a=!1;function f(){var e="__lscachetest__";if(void 0!==n)return n;try{if(!localStorage)return!1}catch(n){return!1}try{p(e,"__lscachetest__"),m(e),n=!0}catch(e){n=!(!l(e)||!localStorage.length)}return n}function l(n){return n&&("QUOTA_EXCEEDED_ERR"===n.name||"NS_ERROR_DOM_QUOTA_REACHED"===n.name||"QuotaExceededError"===n.name)}function s(){return void 0===e&&(e=null!=window.JSON),e}function h(n){return n+r}function d(){return Math.floor((new Date).getTime()/i)}function g(n){return localStorage.getItem(t+u+n)}function p(n,e){localStorage.removeItem(t+u+n),localStorage.setItem(t+u+n,e)}function m(n){localStorage.removeItem(t+u+n)}function w(n){for(var e=new RegExp("^"+t+u.replace(/[[\]{}()*+?.\\^$|]/g,"\\$&")+"(.*)"),o=localStorage.length-1;o>=0;--o){var i=localStorage.key(o);(i=(i=i&&i.match(e))&&i[1])&&i.indexOf(r)<0&&n(i,h(i))}}function y(n){var e=h(n);m(n),m(e)}function v(n){var e=h(n),t=g(e);if(t){var r=parseInt(t,o);if(d()>=r)return m(n),m(e),!0}}function E(n,e){a&&"console"in window&&"function"==typeof window.console.warn&&(window.console.warn("lscache - "+n),e&&window.console.warn("lscache - The error was: "+e.message))}function _(n){return Math.floor(864e13/n)}return{set:function(n,e,t){if(!f())return!1;if(!s())return!1;try{e=JSON.stringify(e)}catch(n){return!1}try{p(n,e)}catch(t){if(!l(t))return E("Could not add item with key '"+n+"'",t),!1;var r,i=[];w(function(n,e){var t=g(e);t=t?parseInt(t,o):c,i.push({key:n,size:(g(n)||"").length,expiration:t})}),i.sort(function(n,e){return e.expiration-n.expiration});for(var u=(e||"").length;i.length&&u>0;)r=i.pop(),E("Cache is full, removing item with key '"+n+"'"),y(r.key),u-=r.size;try{p(n,e)}catch(e){return E("Could not add item with key '"+n+"', perhaps it's too big?",e),!1}}return t?p(h(n),(d()+t).toString(o)):m(h(n)),!0},get:function(n){if(!f())return null;if(v(n))return null;var e=g(n);if(!e||!s())return e;try{return JSON.parse(e)}catch(n){return e}},remove:function(n){f()&&y(n)},supported:function(){return f()},flush:function(){f()&&w(function(n){y(n)})},flushExpired:function(){f()&&w(function(n){v(n)})},setBucket:function(n){u=n},resetBucket:function(){u=""},getExpiryMilliseconds:function(){return i},setExpiryMilliseconds:function(n){c=_(i=n)},enableWarnings:function(n){a=n}}});