-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathi18nextLocalStorageCache.min.js
1 lines (1 loc) · 2.11 KB
/
i18nextLocalStorageCache.min.js
1
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.i18nextLocalStorageCache=t()}(this,function(){"use strict";function e(e){return r.call(a.call(arguments,1),function(t){if(t)for(var n in t)void 0===e[n]&&(e[n]=t[n])}),e}function t(e,t,n){var i;return function(){var o=this,r=arguments,a=function(){i=null,n||e.apply(o,r)},c=n&&!i;clearTimeout(i),i=setTimeout(a,t),c&&e.apply(o,r)}}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(){return{enabled:!1,prefix:"i18next_res_",expirationTime:6048e5,versions:{}}}var o=[],r=o.forEach,a=o.slice,c=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),s={setItem:function(e,t){if(window.localStorage)try{window.localStorage.setItem(e,t)}catch(e){}},getItem:function(e,t){if(window.localStorage)try{return window.localStorage.getItem(e,t)}catch(e){}}},u=function(){function o(e){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};n(this,o),this.init(e,i),this.type="cache",this.debouncedStore=t(this.store,1e4)}return c(o,[{key:"init",value:function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.services=t,this.options=e(n,this.options||{},i())}},{key:"load",value:function(e,t){var n=this,i={},o=(new Date).getTime();if(!window.localStorage||!e.length)return t(null,null);var r=e.length;e.forEach(function(e){var a=s.getItem(n.options.prefix+e);a&&(a=JSON.parse(a),a.i18nStamp&&a.i18nStamp+n.options.expirationTime>o&&n.options.versions[e]===a.i18nVersion&&(delete a.i18nVersion,i[e]=a)),r-=1,0===r&&t(null,i)})}},{key:"store",value:function e(t){var e=t;if(window.localStorage)for(var n in e)e[n].i18nStamp=(new Date).getTime(),this.options.versions[n]&&(e[n].i18nVersion=this.options.versions[n]),s.setItem(this.options.prefix+n,JSON.stringify(e[n]))}},{key:"save",value:function(e){this.debouncedStore(e)}}]),o}();return u.type="cache",u});