i18next-browser-languagedetector-async
Advanced tools
Comparing version
@@ -9,2 +9,6 @@ 'use strict'; | ||
require('babel-core/register'); | ||
require('babel-polyfill'); | ||
var _utils = require('./utils.js'); | ||
@@ -11,0 +15,0 @@ |
@@ -7,2 +7,4 @@ var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
import 'babel-core/register'; | ||
import 'babel-polyfill'; | ||
import * as utils from './utils.js'; | ||
@@ -9,0 +11,0 @@ import cookie from './browserLookups/cookie.js'; |
@@ -7,2 +7,33 @@ (function (global, factory) { | ||
/* eslint max-len: 0 */ | ||
// TODO: eventually deprecate this console.trace("use the `babel-register` package instead of `babel-core/register`"); | ||
module.exports = require("babel-register"); | ||
require("core-js/shim"); | ||
require("regenerator-runtime/runtime"); | ||
require("core-js/fn/regexp/escape"); | ||
if (global._babelPolyfill) { | ||
throw new Error("only one instance of babel-polyfill is allowed"); | ||
} | ||
global._babelPolyfill = true; | ||
var DEFINE_PROPERTY = "defineProperty"; | ||
function define(O, key, value) { | ||
O[key] || Object[DEFINE_PROPERTY](O, key, { | ||
writable: true, | ||
configurable: true, | ||
value: value | ||
}); | ||
} | ||
define(String.prototype, "padLeft", "".padStart); | ||
define(String.prototype, "padRight", "".padEnd); | ||
"pop,reverse,shift,keys,values,entries,indexOf,every,some,forEach,map,filter,find,findIndex,includes,join,slice,concat,push,splice,unshift,sort,lastIndexOf,reduce,reduceRight,copyWithin,fill".split(",").forEach(function (key) { | ||
[][key] && define(Array, key, Function.call.bind([][key])); | ||
}); | ||
var arr = []; | ||
@@ -9,0 +40,0 @@ var each = arr.forEach; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.i18nextBrowserLanguageDetector=t()}(this,function(){"use strict";function e(e){return a.call(i.call(arguments,1),function(t){if(t)for(var o in t)void 0===e[o]&&(e[o]=t[o])}),e}function t(e){return function(){var t=e.apply(this,arguments);return new Promise(function(e,o){function n(r,a){try{var i=t[r](a),u=i.value}catch(e){return void o(e)}if(!i.done)return Promise.resolve(u).then(function(e){n("next",e)},function(e){n("throw",e)});e(u)}return n("next")})}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(){return{order:["querystring","cookie","localStorage","navigator","htmlTag"],lookupQuerystring:"lng",lookupCookie:"i18next",lookupLocalStorage:"i18nextLng",caches:["localStorage"],excludeCacheFor:["cimode"]}}var r=[],a=r.forEach,i=r.slice,u={create:function(e,t,o,n){var r=void 0;if(o){var a=new Date;a.setTime(a.getTime()+60*o*1e3),r="; expires="+a.toGMTString()}else r="";n=n?"domain="+n+";":"",document.cookie=e+"="+t+r+";"+n+"path=/"},read:function(e){for(var t=e+"=",o=document.cookie.split(";"),n=0;n<o.length;n++){for(var r=o[n];" "===r.charAt(0);)r=r.substring(1,r.length);if(0===r.indexOf(t))return r.substring(t.length,r.length)}return null},remove:function(e){this.create(e,"",-1)}},c={name:"cookie",lookup:function(e){var t=void 0;if(e.lookupCookie&&"undefined"!=typeof document){var o=u.read(e.lookupCookie);o&&(t=o)}return t},cacheUserLanguage:function(e,t){t.lookupCookie&&"undefined"!=typeof document&&u.create(t.lookupCookie,e,t.cookieMinutes,t.cookieDomain)}},s={name:"querystring",lookup:function(e){var t=void 0;if("undefined"!=typeof window)for(var o=window.location.search.substring(1),n=o.split("&"),r=0;r<n.length;r++){var a=n[r].indexOf("=");if(a>0){var i=n[r].substring(0,a);i===e.lookupQuerystring&&(t=n[r].substring(a+1))}}return t}},l=void 0;try{l="undefined"!==window&&null!==window.localStorage;window.localStorage.setItem("i18next.translate.boo","foo"),window.localStorage.removeItem("i18next.translate.boo")}catch(e){l=!1}var d={name:"localStorage",lookup:function(e){var t=void 0;if(e.lookupLocalStorage&&l){var o=window.localStorage.getItem(e.lookupLocalStorage);o&&(t=o)}return t},cacheUserLanguage:function(e,t){t.lookupLocalStorage&&l&&window.localStorage.setItem(t.lookupLocalStorage,e)}},f={name:"navigator",lookup:function(e){var t=[];if("undefined"!=typeof navigator){if(navigator.languages)for(var o=0;o<navigator.languages.length;o++)t.push(navigator.languages[o]);navigator.userLanguage&&t.push(navigator.userLanguage),navigator.language&&t.push(navigator.language)}return t.length>0?t:void 0}},p={name:"htmlTag",lookup:function(e){var t=void 0,o=e.htmlTag||("undefined"!=typeof document?document.documentElement:null);return o&&"function"==typeof o.getAttribute&&(t=o.getAttribute("lang")),t}},g={name:"path",lookup:function(e){var t=void 0;if("undefined"!=typeof window){var o=window.location.pathname.match(/\/([a-zA-Z-]*)/g);if(o instanceof Array)if("number"==typeof e.lookupFromPathIndex){if("string"!=typeof o[e.lookupFromPathIndex])return;t=o[e.lookupFromPathIndex].replace("/","")}else t=o[0].replace("/","")}return t}},h={name:"subdomain",lookup:function(e){var t=void 0;if("undefined"!=typeof window){var o=window.location.href.match(/(?:http[s]*\:\/\/)*(.*?)\.(?=[^\/]*\..{2,5})/gi);o instanceof Array&&(t="number"==typeof e.lookupFromSubdomainIndex?o[e.lookupFromSubdomainIndex].replace("http://","").replace("https://","").replace(".",""):o[0].replace("http://","").replace("https://","").replace(".",""))}return t}},v=function(){function e(e,t){for(var o=0;o<t.length;o++){var n=t[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,o,n){return o&&e(t.prototype,o),n&&e(t,n),t}}(),m=function(){function r(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};o(this,r),this.type="languageDetector",this.detectors={},this.init(e,t)}return v(r,[{key:"init",value:function(t){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.services=t,this.options=e(o,this.options||{},n()),this.options.lookupFromUrlIndex&&(this.options.lookupFromPathIndex=this.options.lookupFromUrlIndex),this.i18nOptions=r,this.addDetector(c),this.addDetector(s),this.addDetector(d),this.addDetector(f),this.addDetector(p),this.addDetector(g),this.addDetector(h)}},{key:"addDetector",value:function(e){this.detectors[e.name]=e}},{key:"detect",value:function(){function e(e){return o.apply(this,arguments)}var o=t(regeneratorRuntime.mark(function e(t){var o,n,r,a,i,u,c,s,l,d,f=this;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:t||(t=this.options.order),o=[],n=!0,r=!1,a=void 0,e.prev=5,i=t[Symbol.iterator]();case 7:if(n=(u=i.next()).done){e.next=23;break}if(c=u.value,!this.detectors[c]){e.next=20;break}if(s=void 0,!this.detectors[c].async){e.next=17;break}return e.next=14,this.detectors[c].lookup(this.options);case 14:s=e.sent,e.next=18;break;case 17:s=this.detectors[c].lookup(this.options);case 18:s&&"string"==typeof s&&(s=[s]),s&&(o=o.concat(s));case 20:n=!0,e.next=7;break;case 23:e.next=29;break;case 25:e.prev=25,e.t0=e.catch(5),r=!0,a=e.t0;case 29:e.prev=29,e.prev=30,!n&&i.return&&i.return();case 32:if(e.prev=32,!r){e.next=35;break}throw a;case 35:return e.finish(32);case 36:return e.finish(29);case 37:return l=void 0,o.forEach(function(e){if(!l){var t=f.services.languageUtils.formatLanguageCode(e);f.services.languageUtils.isWhitelisted(t)&&(l=t)}}),l||(d=this.i18nOptions.fallbackLng,"string"==typeof d&&(d=[d]),d||(d=[]),l="[object Array]"===Object.prototype.toString.apply(d)?d[0]:d[0]||d.default&&d.default[0]),e.abrupt("return",l);case 42:case"end":return e.stop()}},e,this,[[5,25,29,37],[30,,32,36]])}));return e}()},{key:"cacheUserLanguage",value:function(e,t){var o=this;t||(t=this.options.caches),t&&(this.options.excludeCacheFor&&this.options.excludeCacheFor.indexOf(e)>-1||t.forEach(function(t){o.detectors[t]&&o.detectors[t].cacheUserLanguage(e,o.options)}))}}]),r}();return m.type="languageDetector",m}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.i18nextBrowserLanguageDetector=t()}(this,function(){"use strict";function e(e,t,o){e[t]||Object[i](e,t,{writable:!0,configurable:!0,value:o})}function t(e){return u.call(c.call(arguments,1),function(t){if(t)for(var o in t)void 0===e[o]&&(e[o]=t[o])}),e}function o(e){return function(){var t=e.apply(this,arguments);return new Promise(function(e,o){function n(r,i){try{var a=t[r](i),u=a.value}catch(e){return void o(e)}if(!a.done)return Promise.resolve(u).then(function(e){n("next",e)},function(e){n("throw",e)});e(u)}return n("next")})}}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(){return{order:["querystring","cookie","localStorage","navigator","htmlTag"],lookupQuerystring:"lng",lookupCookie:"i18next",lookupLocalStorage:"i18nextLng",caches:["localStorage"],excludeCacheFor:["cimode"]}}if(module.exports=require("babel-register"),require("core-js/shim"),require("regenerator-runtime/runtime"),require("core-js/fn/regexp/escape"),global._babelPolyfill)throw new Error("only one instance of babel-polyfill is allowed");global._babelPolyfill=!0;var i="defineProperty";e(String.prototype,"padLeft","".padStart),e(String.prototype,"padRight","".padEnd),"pop,reverse,shift,keys,values,entries,indexOf,every,some,forEach,map,filter,find,findIndex,includes,join,slice,concat,push,splice,unshift,sort,lastIndexOf,reduce,reduceRight,copyWithin,fill".split(",").forEach(function(t){[][t]&&e(Array,t,Function.call.bind([][t]))});var a=[],u=a.forEach,c=a.slice,s={create:function(e,t,o,n){var r=void 0;if(o){var i=new Date;i.setTime(i.getTime()+60*o*1e3),r="; expires="+i.toGMTString()}else r="";n=n?"domain="+n+";":"",document.cookie=e+"="+t+r+";"+n+"path=/"},read:function(e){for(var t=e+"=",o=document.cookie.split(";"),n=0;n<o.length;n++){for(var r=o[n];" "===r.charAt(0);)r=r.substring(1,r.length);if(0===r.indexOf(t))return r.substring(t.length,r.length)}return null},remove:function(e){this.create(e,"",-1)}},l={name:"cookie",lookup:function(e){var t=void 0;if(e.lookupCookie&&"undefined"!=typeof document){var o=s.read(e.lookupCookie);o&&(t=o)}return t},cacheUserLanguage:function(e,t){t.lookupCookie&&"undefined"!=typeof document&&s.create(t.lookupCookie,e,t.cookieMinutes,t.cookieDomain)}},f={name:"querystring",lookup:function(e){var t=void 0;if("undefined"!=typeof window)for(var o=window.location.search.substring(1),n=o.split("&"),r=0;r<n.length;r++){var i=n[r].indexOf("=");if(i>0){var a=n[r].substring(0,i);a===e.lookupQuerystring&&(t=n[r].substring(i+1))}}return t}},d=void 0;try{d="undefined"!==window&&null!==window.localStorage;window.localStorage.setItem("i18next.translate.boo","foo"),window.localStorage.removeItem("i18next.translate.boo")}catch(e){d=!1}var p={name:"localStorage",lookup:function(e){var t=void 0;if(e.lookupLocalStorage&&d){var o=window.localStorage.getItem(e.lookupLocalStorage);o&&(t=o)}return t},cacheUserLanguage:function(e,t){t.lookupLocalStorage&&d&&window.localStorage.setItem(t.lookupLocalStorage,e)}},g={name:"navigator",lookup:function(e){var t=[];if("undefined"!=typeof navigator){if(navigator.languages)for(var o=0;o<navigator.languages.length;o++)t.push(navigator.languages[o]);navigator.userLanguage&&t.push(navigator.userLanguage),navigator.language&&t.push(navigator.language)}return t.length>0?t:void 0}},h={name:"htmlTag",lookup:function(e){var t=void 0,o=e.htmlTag||("undefined"!=typeof document?document.documentElement:null);return o&&"function"==typeof o.getAttribute&&(t=o.getAttribute("lang")),t}},v={name:"path",lookup:function(e){var t=void 0;if("undefined"!=typeof window){var o=window.location.pathname.match(/\/([a-zA-Z-]*)/g);if(o instanceof Array)if("number"==typeof e.lookupFromPathIndex){if("string"!=typeof o[e.lookupFromPathIndex])return;t=o[e.lookupFromPathIndex].replace("/","")}else t=o[0].replace("/","")}return t}},m={name:"subdomain",lookup:function(e){var t=void 0;if("undefined"!=typeof window){var o=window.location.href.match(/(?:http[s]*\:\/\/)*(.*?)\.(?=[^\/]*\..{2,5})/gi);o instanceof Array&&(t="number"==typeof e.lookupFromSubdomainIndex?o[e.lookupFromSubdomainIndex].replace("http://","").replace("https://","").replace(".",""):o[0].replace("http://","").replace("https://","").replace(".",""))}return t}},k=function(){function e(e,t){for(var o=0;o<t.length;o++){var n=t[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,o,n){return o&&e(t.prototype,o),n&&e(t,n),t}}(),y=function(){function e(t){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};n(this,e),this.type="languageDetector",this.detectors={},this.init(t,o)}return k(e,[{key:"init",value:function(e){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.services=e,this.options=t(o,this.options||{},r()),this.options.lookupFromUrlIndex&&(this.options.lookupFromPathIndex=this.options.lookupFromUrlIndex),this.i18nOptions=n,this.addDetector(l),this.addDetector(f),this.addDetector(p),this.addDetector(g),this.addDetector(h),this.addDetector(v),this.addDetector(m)}},{key:"addDetector",value:function(e){this.detectors[e.name]=e}},{key:"detect",value:function(){function e(e){return t.apply(this,arguments)}var t=o(regeneratorRuntime.mark(function e(t){var o,n,r,i,a,u,c,s,l,f,d=this;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:t||(t=this.options.order),o=[],n=!0,r=!1,i=void 0,e.prev=5,a=t[Symbol.iterator]();case 7:if(n=(u=a.next()).done){e.next=23;break}if(c=u.value,!this.detectors[c]){e.next=20;break}if(s=void 0,!this.detectors[c].async){e.next=17;break}return e.next=14,this.detectors[c].lookup(this.options);case 14:s=e.sent,e.next=18;break;case 17:s=this.detectors[c].lookup(this.options);case 18:s&&"string"==typeof s&&(s=[s]),s&&(o=o.concat(s));case 20:n=!0,e.next=7;break;case 23:e.next=29;break;case 25:e.prev=25,e.t0=e.catch(5),r=!0,i=e.t0;case 29:e.prev=29,e.prev=30,!n&&a.return&&a.return();case 32:if(e.prev=32,!r){e.next=35;break}throw i;case 35:return e.finish(32);case 36:return e.finish(29);case 37:return l=void 0,o.forEach(function(e){if(!l){var t=d.services.languageUtils.formatLanguageCode(e);d.services.languageUtils.isWhitelisted(t)&&(l=t)}}),l||(f=this.i18nOptions.fallbackLng,"string"==typeof f&&(f=[f]),f||(f=[]),l="[object Array]"===Object.prototype.toString.apply(f)?f[0]:f[0]||f.default&&f.default[0]),e.abrupt("return",l);case 42:case"end":return e.stop()}},e,this,[[5,25,29,37],[30,,32,36]])}));return e}()},{key:"cacheUserLanguage",value:function(e,t){var o=this;t||(t=this.options.caches),t&&(this.options.excludeCacheFor&&this.options.excludeCacheFor.indexOf(e)>-1||t.forEach(function(t){o.detectors[t]&&o.detectors[t].cacheUserLanguage(e,o.options)}))}}]),e}();return y.type="languageDetector",y}); |
@@ -7,2 +7,33 @@ (function (global, factory) { | ||
/* eslint max-len: 0 */ | ||
// TODO: eventually deprecate this console.trace("use the `babel-register` package instead of `babel-core/register`"); | ||
module.exports = require("babel-register"); | ||
require("core-js/shim"); | ||
require("regenerator-runtime/runtime"); | ||
require("core-js/fn/regexp/escape"); | ||
if (global._babelPolyfill) { | ||
throw new Error("only one instance of babel-polyfill is allowed"); | ||
} | ||
global._babelPolyfill = true; | ||
var DEFINE_PROPERTY = "defineProperty"; | ||
function define(O, key, value) { | ||
O[key] || Object[DEFINE_PROPERTY](O, key, { | ||
writable: true, | ||
configurable: true, | ||
value: value | ||
}); | ||
} | ||
define(String.prototype, "padLeft", "".padStart); | ||
define(String.prototype, "padRight", "".padEnd); | ||
"pop,reverse,shift,keys,values,entries,indexOf,every,some,forEach,map,filter,find,findIndex,includes,join,slice,concat,push,splice,unshift,sort,lastIndexOf,reduce,reduceRight,copyWithin,fill".split(",").forEach(function (key) { | ||
[][key] && define(Array, key, Function.call.bind([][key])); | ||
}); | ||
var arr = []; | ||
@@ -9,0 +40,0 @@ var each = arr.forEach; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.i18nextBrowserLanguageDetector=t()}(this,function(){"use strict";function e(e){return a.call(i.call(arguments,1),function(t){if(t)for(var o in t)void 0===e[o]&&(e[o]=t[o])}),e}function t(e){return function(){var t=e.apply(this,arguments);return new Promise(function(e,o){function n(r,a){try{var i=t[r](a),u=i.value}catch(e){return void o(e)}if(!i.done)return Promise.resolve(u).then(function(e){n("next",e)},function(e){n("throw",e)});e(u)}return n("next")})}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(){return{order:["querystring","cookie","localStorage","navigator","htmlTag"],lookupQuerystring:"lng",lookupCookie:"i18next",lookupLocalStorage:"i18nextLng",caches:["localStorage"],excludeCacheFor:["cimode"]}}var r=[],a=r.forEach,i=r.slice,u={create:function(e,t,o,n){var r=void 0;if(o){var a=new Date;a.setTime(a.getTime()+60*o*1e3),r="; expires="+a.toGMTString()}else r="";n=n?"domain="+n+";":"",document.cookie=e+"="+t+r+";"+n+"path=/"},read:function(e){for(var t=e+"=",o=document.cookie.split(";"),n=0;n<o.length;n++){for(var r=o[n];" "===r.charAt(0);)r=r.substring(1,r.length);if(0===r.indexOf(t))return r.substring(t.length,r.length)}return null},remove:function(e){this.create(e,"",-1)}},c={name:"cookie",lookup:function(e){var t=void 0;if(e.lookupCookie&&"undefined"!=typeof document){var o=u.read(e.lookupCookie);o&&(t=o)}return t},cacheUserLanguage:function(e,t){t.lookupCookie&&"undefined"!=typeof document&&u.create(t.lookupCookie,e,t.cookieMinutes,t.cookieDomain)}},s={name:"querystring",lookup:function(e){var t=void 0;if("undefined"!=typeof window)for(var o=window.location.search.substring(1),n=o.split("&"),r=0;r<n.length;r++){var a=n[r].indexOf("=");if(a>0){var i=n[r].substring(0,a);i===e.lookupQuerystring&&(t=n[r].substring(a+1))}}return t}},l=void 0;try{l="undefined"!==window&&null!==window.localStorage;window.localStorage.setItem("i18next.translate.boo","foo"),window.localStorage.removeItem("i18next.translate.boo")}catch(e){l=!1}var d={name:"localStorage",lookup:function(e){var t=void 0;if(e.lookupLocalStorage&&l){var o=window.localStorage.getItem(e.lookupLocalStorage);o&&(t=o)}return t},cacheUserLanguage:function(e,t){t.lookupLocalStorage&&l&&window.localStorage.setItem(t.lookupLocalStorage,e)}},f={name:"navigator",lookup:function(e){var t=[];if("undefined"!=typeof navigator){if(navigator.languages)for(var o=0;o<navigator.languages.length;o++)t.push(navigator.languages[o]);navigator.userLanguage&&t.push(navigator.userLanguage),navigator.language&&t.push(navigator.language)}return t.length>0?t:void 0}},p={name:"htmlTag",lookup:function(e){var t=void 0,o=e.htmlTag||("undefined"!=typeof document?document.documentElement:null);return o&&"function"==typeof o.getAttribute&&(t=o.getAttribute("lang")),t}},g={name:"path",lookup:function(e){var t=void 0;if("undefined"!=typeof window){var o=window.location.pathname.match(/\/([a-zA-Z-]*)/g);if(o instanceof Array)if("number"==typeof e.lookupFromPathIndex){if("string"!=typeof o[e.lookupFromPathIndex])return;t=o[e.lookupFromPathIndex].replace("/","")}else t=o[0].replace("/","")}return t}},h={name:"subdomain",lookup:function(e){var t=void 0;if("undefined"!=typeof window){var o=window.location.href.match(/(?:http[s]*\:\/\/)*(.*?)\.(?=[^\/]*\..{2,5})/gi);o instanceof Array&&(t="number"==typeof e.lookupFromSubdomainIndex?o[e.lookupFromSubdomainIndex].replace("http://","").replace("https://","").replace(".",""):o[0].replace("http://","").replace("https://","").replace(".",""))}return t}},v=function(){function e(e,t){for(var o=0;o<t.length;o++){var n=t[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,o,n){return o&&e(t.prototype,o),n&&e(t,n),t}}(),m=function(){function r(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};o(this,r),this.type="languageDetector",this.detectors={},this.init(e,t)}return v(r,[{key:"init",value:function(t){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.services=t,this.options=e(o,this.options||{},n()),this.options.lookupFromUrlIndex&&(this.options.lookupFromPathIndex=this.options.lookupFromUrlIndex),this.i18nOptions=r,this.addDetector(c),this.addDetector(s),this.addDetector(d),this.addDetector(f),this.addDetector(p),this.addDetector(g),this.addDetector(h)}},{key:"addDetector",value:function(e){this.detectors[e.name]=e}},{key:"detect",value:function(){function e(e){return o.apply(this,arguments)}var o=t(regeneratorRuntime.mark(function e(t){var o,n,r,a,i,u,c,s,l,d,f=this;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:t||(t=this.options.order),o=[],n=!0,r=!1,a=void 0,e.prev=5,i=t[Symbol.iterator]();case 7:if(n=(u=i.next()).done){e.next=23;break}if(c=u.value,!this.detectors[c]){e.next=20;break}if(s=void 0,!this.detectors[c].async){e.next=17;break}return e.next=14,this.detectors[c].lookup(this.options);case 14:s=e.sent,e.next=18;break;case 17:s=this.detectors[c].lookup(this.options);case 18:s&&"string"==typeof s&&(s=[s]),s&&(o=o.concat(s));case 20:n=!0,e.next=7;break;case 23:e.next=29;break;case 25:e.prev=25,e.t0=e.catch(5),r=!0,a=e.t0;case 29:e.prev=29,e.prev=30,!n&&i.return&&i.return();case 32:if(e.prev=32,!r){e.next=35;break}throw a;case 35:return e.finish(32);case 36:return e.finish(29);case 37:return l=void 0,o.forEach(function(e){if(!l){var t=f.services.languageUtils.formatLanguageCode(e);f.services.languageUtils.isWhitelisted(t)&&(l=t)}}),l||(d=this.i18nOptions.fallbackLng,"string"==typeof d&&(d=[d]),d||(d=[]),l="[object Array]"===Object.prototype.toString.apply(d)?d[0]:d[0]||d.default&&d.default[0]),e.abrupt("return",l);case 42:case"end":return e.stop()}},e,this,[[5,25,29,37],[30,,32,36]])}));return e}()},{key:"cacheUserLanguage",value:function(e,t){var o=this;t||(t=this.options.caches),t&&(this.options.excludeCacheFor&&this.options.excludeCacheFor.indexOf(e)>-1||t.forEach(function(t){o.detectors[t]&&o.detectors[t].cacheUserLanguage(e,o.options)}))}}]),r}();return m.type="languageDetector",m}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.i18nextBrowserLanguageDetector=t()}(this,function(){"use strict";function e(e,t,o){e[t]||Object[i](e,t,{writable:!0,configurable:!0,value:o})}function t(e){return u.call(c.call(arguments,1),function(t){if(t)for(var o in t)void 0===e[o]&&(e[o]=t[o])}),e}function o(e){return function(){var t=e.apply(this,arguments);return new Promise(function(e,o){function n(r,i){try{var a=t[r](i),u=a.value}catch(e){return void o(e)}if(!a.done)return Promise.resolve(u).then(function(e){n("next",e)},function(e){n("throw",e)});e(u)}return n("next")})}}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(){return{order:["querystring","cookie","localStorage","navigator","htmlTag"],lookupQuerystring:"lng",lookupCookie:"i18next",lookupLocalStorage:"i18nextLng",caches:["localStorage"],excludeCacheFor:["cimode"]}}if(module.exports=require("babel-register"),require("core-js/shim"),require("regenerator-runtime/runtime"),require("core-js/fn/regexp/escape"),global._babelPolyfill)throw new Error("only one instance of babel-polyfill is allowed");global._babelPolyfill=!0;var i="defineProperty";e(String.prototype,"padLeft","".padStart),e(String.prototype,"padRight","".padEnd),"pop,reverse,shift,keys,values,entries,indexOf,every,some,forEach,map,filter,find,findIndex,includes,join,slice,concat,push,splice,unshift,sort,lastIndexOf,reduce,reduceRight,copyWithin,fill".split(",").forEach(function(t){[][t]&&e(Array,t,Function.call.bind([][t]))});var a=[],u=a.forEach,c=a.slice,s={create:function(e,t,o,n){var r=void 0;if(o){var i=new Date;i.setTime(i.getTime()+60*o*1e3),r="; expires="+i.toGMTString()}else r="";n=n?"domain="+n+";":"",document.cookie=e+"="+t+r+";"+n+"path=/"},read:function(e){for(var t=e+"=",o=document.cookie.split(";"),n=0;n<o.length;n++){for(var r=o[n];" "===r.charAt(0);)r=r.substring(1,r.length);if(0===r.indexOf(t))return r.substring(t.length,r.length)}return null},remove:function(e){this.create(e,"",-1)}},l={name:"cookie",lookup:function(e){var t=void 0;if(e.lookupCookie&&"undefined"!=typeof document){var o=s.read(e.lookupCookie);o&&(t=o)}return t},cacheUserLanguage:function(e,t){t.lookupCookie&&"undefined"!=typeof document&&s.create(t.lookupCookie,e,t.cookieMinutes,t.cookieDomain)}},f={name:"querystring",lookup:function(e){var t=void 0;if("undefined"!=typeof window)for(var o=window.location.search.substring(1),n=o.split("&"),r=0;r<n.length;r++){var i=n[r].indexOf("=");if(i>0){var a=n[r].substring(0,i);a===e.lookupQuerystring&&(t=n[r].substring(i+1))}}return t}},d=void 0;try{d="undefined"!==window&&null!==window.localStorage;window.localStorage.setItem("i18next.translate.boo","foo"),window.localStorage.removeItem("i18next.translate.boo")}catch(e){d=!1}var p={name:"localStorage",lookup:function(e){var t=void 0;if(e.lookupLocalStorage&&d){var o=window.localStorage.getItem(e.lookupLocalStorage);o&&(t=o)}return t},cacheUserLanguage:function(e,t){t.lookupLocalStorage&&d&&window.localStorage.setItem(t.lookupLocalStorage,e)}},g={name:"navigator",lookup:function(e){var t=[];if("undefined"!=typeof navigator){if(navigator.languages)for(var o=0;o<navigator.languages.length;o++)t.push(navigator.languages[o]);navigator.userLanguage&&t.push(navigator.userLanguage),navigator.language&&t.push(navigator.language)}return t.length>0?t:void 0}},h={name:"htmlTag",lookup:function(e){var t=void 0,o=e.htmlTag||("undefined"!=typeof document?document.documentElement:null);return o&&"function"==typeof o.getAttribute&&(t=o.getAttribute("lang")),t}},v={name:"path",lookup:function(e){var t=void 0;if("undefined"!=typeof window){var o=window.location.pathname.match(/\/([a-zA-Z-]*)/g);if(o instanceof Array)if("number"==typeof e.lookupFromPathIndex){if("string"!=typeof o[e.lookupFromPathIndex])return;t=o[e.lookupFromPathIndex].replace("/","")}else t=o[0].replace("/","")}return t}},m={name:"subdomain",lookup:function(e){var t=void 0;if("undefined"!=typeof window){var o=window.location.href.match(/(?:http[s]*\:\/\/)*(.*?)\.(?=[^\/]*\..{2,5})/gi);o instanceof Array&&(t="number"==typeof e.lookupFromSubdomainIndex?o[e.lookupFromSubdomainIndex].replace("http://","").replace("https://","").replace(".",""):o[0].replace("http://","").replace("https://","").replace(".",""))}return t}},k=function(){function e(e,t){for(var o=0;o<t.length;o++){var n=t[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,o,n){return o&&e(t.prototype,o),n&&e(t,n),t}}(),y=function(){function e(t){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};n(this,e),this.type="languageDetector",this.detectors={},this.init(t,o)}return k(e,[{key:"init",value:function(e){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.services=e,this.options=t(o,this.options||{},r()),this.options.lookupFromUrlIndex&&(this.options.lookupFromPathIndex=this.options.lookupFromUrlIndex),this.i18nOptions=n,this.addDetector(l),this.addDetector(f),this.addDetector(p),this.addDetector(g),this.addDetector(h),this.addDetector(v),this.addDetector(m)}},{key:"addDetector",value:function(e){this.detectors[e.name]=e}},{key:"detect",value:function(){function e(e){return t.apply(this,arguments)}var t=o(regeneratorRuntime.mark(function e(t){var o,n,r,i,a,u,c,s,l,f,d=this;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:t||(t=this.options.order),o=[],n=!0,r=!1,i=void 0,e.prev=5,a=t[Symbol.iterator]();case 7:if(n=(u=a.next()).done){e.next=23;break}if(c=u.value,!this.detectors[c]){e.next=20;break}if(s=void 0,!this.detectors[c].async){e.next=17;break}return e.next=14,this.detectors[c].lookup(this.options);case 14:s=e.sent,e.next=18;break;case 17:s=this.detectors[c].lookup(this.options);case 18:s&&"string"==typeof s&&(s=[s]),s&&(o=o.concat(s));case 20:n=!0,e.next=7;break;case 23:e.next=29;break;case 25:e.prev=25,e.t0=e.catch(5),r=!0,i=e.t0;case 29:e.prev=29,e.prev=30,!n&&a.return&&a.return();case 32:if(e.prev=32,!r){e.next=35;break}throw i;case 35:return e.finish(32);case 36:return e.finish(29);case 37:return l=void 0,o.forEach(function(e){if(!l){var t=d.services.languageUtils.formatLanguageCode(e);d.services.languageUtils.isWhitelisted(t)&&(l=t)}}),l||(f=this.i18nOptions.fallbackLng,"string"==typeof f&&(f=[f]),f||(f=[]),l="[object Array]"===Object.prototype.toString.apply(f)?f[0]:f[0]||f.default&&f.default[0]),e.abrupt("return",l);case 42:case"end":return e.stop()}},e,this,[[5,25,29,37],[30,,32,36]])}));return e}()},{key:"cacheUserLanguage",value:function(e,t){var o=this;t||(t=this.options.caches),t&&(this.options.excludeCacheFor&&this.options.excludeCacheFor.indexOf(e)>-1||t.forEach(function(t){o.detectors[t]&&o.detectors[t].cacheUserLanguage(e,o.options)}))}}]),e}();return y.type="languageDetector",y}); |
{ | ||
"name": "i18next-browser-languagedetector-async", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "language detector used in browser environment for i18next", | ||
@@ -21,8 +21,10 @@ "main": "./index.js", | ||
"babel-cli": "6.22.2", | ||
"babel-core": "6.22.1", | ||
"babel-core": "^6.22.1", | ||
"babel-eslint": "7.1.1", | ||
"babel-loader": "^8.0.6", | ||
"babel-plugin-external-helpers": "6.22.0", | ||
"babel-plugin-transform-es2015-classes": "6.22.0", | ||
"babel-preset-es2015": "6.22.0", | ||
"babel-preset-stage-0": "6.22.0", | ||
"babel-polyfill": "^6.26.0", | ||
"babel-preset-es2015": "^6.22.0", | ||
"babel-preset-stage-0": "^6.22.0", | ||
"dtslint": "^0.4.2", | ||
@@ -29,0 +31,0 @@ "eslint": "2.8.0", |
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
83966
4.62%1578
3.27%0
-100%21
10.53%3
200%1
Infinity%