-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlocizeLastUsed.min.js
1 lines (1 loc) · 6.75 KB
/
locizeLastUsed.min.js
1
!function(e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).locizeLastUsed=e()}(function(){return function n(i,s,r){function c(t,e){if(!s[t]){if(!i[t]){var o="function"==typeof require&&require;if(!e&&o)return o(t,!0);if(u)return u(t,!0);throw(e=new Error("Cannot find module '"+t+"'")).code="MODULE_NOT_FOUND",e}o=s[t]={exports:{}},i[t][0].call(o.exports,function(e){return c(i[t][1][e]||e)},o,o.exports,n,i,s,r)}return s[t].exports}for(var u="function"==typeof require&&require,e=0;e<r.length;e++)c(r[e]);return c}({1:[function(e,t,o){Object.defineProperty(o,"__esModule",{value:!0}),o.default=void 0;var s=e("./utils.js"),r=(e=e("./request.js"))&&e.__esModule?e:{default:e};function n(){return{lastUsedPath:"https://api.locize.app/used/{{projectId}}/{{version}}/{{lng}}/{{ns}}",referenceLng:"en",crossDomain:!0,setContentTypeJSON:!1,version:"latest",debounceSubmit:9e4,allowedHosts:["localhost"]}}e={init:function(e){var t=e.t&&"function"==typeof e.t,o=(t&&!e.options.locizeLastUsed.projectId&&e.options.backend.projectId&&(e.options.locizeLastUsed.projectId=e.options.backend.projectId),t&&!e.options.locizeLastUsed.version&&e.options.backend.version&&(e.options.locizeLastUsed.version=e.options.backend.version),t&&!e.options.locizeLastUsed.apiKey&&e.options.backend.apiKey&&(e.options.locizeLastUsed.apiKey=e.options.backend.apiKey),t&&!e.options.locizeLastUsed.referenceLng&&e.options.backend.referenceLng&&(e.options.locizeLastUsed.referenceLng=e.options.backend.referenceLng),t&&!e.options.locizeLastUsed.referenceLng&&e.options.fallbackLng&&Array.isArray(e.options.fallbackLng)&&"dev"!==e.options.fallbackLng[0]&&(e.options.locizeLastUsed.referenceLng=e.options.fallbackLng[0]),this.options=t?(0,s.defaults)(e.options.locizeLastUsed,this.options||{},n()):(0,s.defaults)(e,this.options||{},n()),"undefined"!=typeof window&&window.location&&window.location.hostname);this.isAllowed=!o||-1<this.options.allowedHosts.indexOf(o),this.submitting=null,this.pending={},this.done={},this.submit=(0,s.debounce)(this.submit,this.options.debounceSubmit),t&&this.interceptI18next(e)},interceptI18next:function(i){var s=this,r=i.services.resourceStore.getResource;i.services.resourceStore.getResource=function(e,t,o,n){return o&&s.used(t,o),r.call(i.services.resourceStore,e,t,o,n)}},used:function(t,o,e){var n=this;["pending","done"].forEach(function(e){n.done[t]&&n.done[t][o]||(n[e][t]||(n[e][t]={}),n[e][t][o]=!0)}),this.submit(e)},submit:function(t){var o=this;if(!this.isAllowed)return t&&t(new Error("not allowed"));if(this.submitting)return this.submit(t);var e=(0,s.isMissingOption)(this.options,["projectId","version","apiKey","referenceLng"]);if(e)return t&&t(new Error(e));this.submitting=this.pending,this.pending={};function n(e){--i||(o.submitting=null,t&&t(e))}var e=Object.keys(this.submitting),i=e.length;e.forEach(function(e){var t=Object.keys(o.submitting[e]),e=(0,s.replaceIn)(o.options.lastUsedPath,["projectId","version","lng","ns"],(0,s.defaults)({lng:o.options.referenceLng,ns:e},o.options));t.length?(0,r.default)((0,s.defaults)({authorize:!0},o.options),e,t,n):n()})},type:"3rdParty"};o.default=e;t.exports=o.default},{"./request.js":2,"./utils.js":3}],2:[function(e,t,o){!function(s){!function(){function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}Object.defineProperty(o,"__esModule",{value:!0}),o.default=void 0;var c,u,f="function"==typeof fetch?fetch:void 0;if(void 0!==s&&s.fetch?f=s.fetch:"undefined"!=typeof window&&window.fetch&&(f=window.fetch),"function"!=typeof XMLHttpRequest&&"object"!==("undefined"==typeof XMLHttpRequest?"undefined":r(XMLHttpRequest))||(void 0!==s&&s.XMLHttpRequest?c=s.XMLHttpRequest:"undefined"!=typeof window&&window.XMLHttpRequest&&(c=window.XMLHttpRequest)),"function"==typeof ActiveXObject&&(void 0!==s&&s.ActiveXObject?u=s.ActiveXObject:"undefined"!=typeof window&&window.ActiveXObject&&(u=window.ActiveXObject)),!(f="function"!=typeof f?void 0:f)&&!c&&!u)try{f=e("cross-fetch")}catch(e){}function a(e,t,o,n){function i(t){var o=t.headers&&"Error from cloudfront"===t.headers.get("x-cache");if(!t.ok)return n(t.statusText||"Error",{status:t.status,resourceNotExisting:o});t.text().then(function(e){n(null,{status:t.status,data:e,resourceNotExisting:o})}).catch(n)}e={Authorization:e.authorize&&e.apiKey?e.apiKey:void 0,"Content-Type":"application/json"},"undefined"==typeof window&&void 0!==s&&void 0!==s.process&&s.process.versions&&s.process.versions.node&&(e["User-Agent"]="locize-lastused (node/".concat(s.process.version,"; ").concat(s.process.platform," ").concat(s.process.arch,")")),("function"==typeof fetch?fetch:f)(t,{method:o?"POST":"GET",body:o?JSON.stringify(o):void 0,headers:e}).then(i).catch(n)}o.default=function(e,t,o,n){if("function"==typeof o&&(n=o,o=void 0),n=n||function(){},f)return a(e,t,o,n);if("function"==typeof XMLHttpRequest||"object"===("undefined"==typeof XMLHttpRequest?"undefined":r(XMLHttpRequest))||"function"==typeof ActiveXObject){var i=n;try{var s=c?new c:new u("MSXML2.XMLHTTP.3.0");s.open(o?"POST":"GET",t,1),e.crossDomain||s.setRequestHeader("X-Requested-With","XMLHttpRequest"),e.authorize&&e.apiKey&&s.setRequestHeader("Authorization",e.apiKey),(o||e.setContentTypeJSON)&&s.setRequestHeader("Content-Type","application/json"),s.onreadystatechange=function(){var e="Error from cloudfront"===s.getResponseHeader("x-cache");3<s.readyState&&i(400<=s.status?s.statusText:null,{status:s.status,data:s.responseText,resourceNotExisting:e})},s.send(JSON.stringify(o))}catch(e){console&&console.log(e)}}else n(new Error("No fetch and no xhr implementation found!"))};t.exports=o.default}.call(this)}.call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"cross-fetch":4}],3:[function(e,t,o){Object.defineProperty(o,"__esModule",{value:!0}),o.debounce=function(n,i,s){var r;return function(){var e=this,t=arguments,o=s&&!r;clearTimeout(r),r=setTimeout(function(){r=null,s||n.apply(e,t)},i),o&&n.apply(e,t)}},o.defaults=function(o){return n.call(i.call(arguments,1),function(e){if(e)for(var t in e)void 0===o[t]&&(o[t]=e[t])}),o},o.isMissingOption=function(o,e){return e.reduce(function(e,t){return e||(!o||!o[t]||"string"!=typeof o[t]||!o[t].toLowerCase()===t.toLowerCase())&&(e='i18next-lastused :: got "'.concat(o[t],'" in options for ').concat(t," which is invalid."),console.warn(e),e)},!1)},o.replaceIn=function(e,t,o){var n=e;return t.forEach(function(e){var t=new RegExp("{{".concat(e,"}}"),"g");n=n.replace(t,o[e])}),n};var o=[],n=o.forEach,i=o.slice},{}],4:[function(e,t,o){},{}]},{},[1])(1)});