forked from timbrandin/i18next-async-storage-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
i18nextAsyncStorageBackend.min.js
1 lines (1 loc) · 1.8 KB
/
i18nextAsyncStorageBackend.min.js
1
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):e.i18nextAsyncStorageBackend=n()}(this,function(){"use strict";function e(e){return o.call(r.call(arguments,1),function(n){if(n)for(var t in n)void 0===e[t]&&(e[t]=n[t])}),e}function n(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}function t(){return{prefix:"i18next_res_",expirationTime:6048e5,versions:{}}}var i=[],o=i.forEach,r=i.slice,s=function(){function e(e,n){for(var t=0;t<n.length;t++){var i=n[t];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(n,t,i){return t&&e(n.prototype,t),i&&e(n,i),n}}(),a=require("@react-native-async-storage/async-storage")||{},u={setItem:function(e,n){if(a)return a.setItem(e,n)},getItem:function(e,n){if(a)return a.getItem(e,n)}},f=function(){function i(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};n(this,i),this.init(e,t),this.type="backend"}return s(i,[{key:"init",value:function(n){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.services=n,this.options=e(i,this.options||{},t())}},{key:"read",value:function(e,n,t){var i=this,o=(new Date).getTime();if(!a)return t(null,null);u.getItem(""+this.options.prefix+e+"-"+n).then(function(n){if(n&&(n=JSON.parse(n),n.i18nStamp&&n.i18nStamp+i.options.expirationTime>o&&i.options.versions[e]===n.i18nVersion))return delete n.i18nVersion,delete n.i18nStamp,t(null,n);t(null,null)}).catch(function(e){console.warn(e),t(null,null)})}},{key:"save",value:function(e,n,t){a&&(t.i18nStamp=(new Date).getTime(),this.options.versions[e]&&(t.i18nVersion=this.options.versions[e]),u.setItem(""+this.options.prefix+e+"-"+n,JSON.stringify(t)))}}]),i}();return f.type="backend",f});