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