i18next-browser-languagedetector
Advanced tools
Comparing version 6.1.8 to 7.0.0
@@ -0,1 +1,5 @@ | ||
### 7.0.0 | ||
- typescript fix for i18next v22 | ||
### 6.1.8 | ||
@@ -2,0 +6,0 @@ |
@@ -27,3 +27,2 @@ 'use strict'; | ||
var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/; | ||
var serializeCookie = function serializeCookie(name, val, options) { | ||
@@ -34,3 +33,2 @@ var opt = options || {}; | ||
var str = "".concat(name, "=").concat(value); | ||
if (opt.maxAge > 0) { | ||
@@ -41,3 +39,2 @@ var maxAge = opt.maxAge - 0; | ||
} | ||
if (opt.domain) { | ||
@@ -47,6 +44,4 @@ if (!fieldContentRegExp.test(opt.domain)) { | ||
} | ||
str += "; Domain=".concat(opt.domain); | ||
} | ||
if (opt.path) { | ||
@@ -56,6 +51,4 @@ if (!fieldContentRegExp.test(opt.path)) { | ||
} | ||
str += "; Path=".concat(opt.path); | ||
} | ||
if (opt.expires) { | ||
@@ -65,12 +58,8 @@ if (typeof opt.expires.toUTCString !== 'function') { | ||
} | ||
str += "; Expires=".concat(opt.expires.toUTCString()); | ||
} | ||
if (opt.httpOnly) str += '; HttpOnly'; | ||
if (opt.secure) str += '; Secure'; | ||
if (opt.sameSite) { | ||
var sameSite = typeof opt.sameSite === 'string' ? opt.sameSite.toLowerCase() : opt.sameSite; | ||
switch (sameSite) { | ||
@@ -80,15 +69,11 @@ case true: | ||
break; | ||
case 'lax': | ||
str += '; SameSite=Lax'; | ||
break; | ||
case 'strict': | ||
str += '; SameSite=Strict'; | ||
break; | ||
case 'none': | ||
str += '; SameSite=None'; | ||
break; | ||
default: | ||
@@ -98,6 +83,4 @@ throw new TypeError('option sameSite is invalid'); | ||
} | ||
return str; | ||
}; | ||
var cookie = { | ||
@@ -109,3 +92,2 @@ create: function create(name, value, minutes, domain) { | ||
}; | ||
if (minutes) { | ||
@@ -115,3 +97,2 @@ cookieOptions.expires = new Date(); | ||
} | ||
if (domain) cookieOptions.domain = domain; | ||
@@ -123,13 +104,9 @@ document.cookie = serializeCookie(name, encodeURIComponent(value), cookieOptions); | ||
var ca = document.cookie.split(';'); | ||
for (var i = 0; i < ca.length; i++) { | ||
var c = ca[i]; | ||
while (c.charAt(0) === ' ') { | ||
c = c.substring(1, c.length); | ||
} | ||
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length); | ||
} | ||
return null; | ||
@@ -145,3 +122,2 @@ }, | ||
var found; | ||
if (options.lookupCookie && typeof document !== 'undefined') { | ||
@@ -151,3 +127,2 @@ var c = cookie.read(options.lookupCookie); | ||
} | ||
return found; | ||
@@ -166,19 +141,13 @@ }, | ||
var found; | ||
if (typeof window !== 'undefined') { | ||
var search = window.location.search; | ||
if (!window.location.search && window.location.hash && window.location.hash.indexOf('?') > -1) { | ||
search = window.location.hash.substring(window.location.hash.indexOf('?')); | ||
} | ||
var query = search.substring(1); | ||
var params = query.split('&'); | ||
for (var i = 0; i < params.length; i++) { | ||
var pos = params[i].indexOf('='); | ||
if (pos > 0) { | ||
var key = params[i].substring(0, pos); | ||
if (key === options.lookupQuerystring) { | ||
@@ -190,3 +159,2 @@ found = params[i].substring(pos + 1); | ||
} | ||
return found; | ||
@@ -197,6 +165,4 @@ } | ||
var hasLocalStorageSupport = null; | ||
var localStorageAvailable = function localStorageAvailable() { | ||
if (hasLocalStorageSupport !== null) return hasLocalStorageSupport; | ||
try { | ||
@@ -210,6 +176,4 @@ hasLocalStorageSupport = window !== 'undefined' && window.localStorage !== null; | ||
} | ||
return hasLocalStorageSupport; | ||
}; | ||
var localStorage = { | ||
@@ -219,3 +183,2 @@ name: 'localStorage', | ||
var found; | ||
if (options.lookupLocalStorage && localStorageAvailable()) { | ||
@@ -225,3 +188,2 @@ var lng = window.localStorage.getItem(options.lookupLocalStorage); | ||
} | ||
return found; | ||
@@ -237,6 +199,4 @@ }, | ||
var hasSessionStorageSupport = null; | ||
var sessionStorageAvailable = function sessionStorageAvailable() { | ||
if (hasSessionStorageSupport !== null) return hasSessionStorageSupport; | ||
try { | ||
@@ -250,6 +210,4 @@ hasSessionStorageSupport = window !== 'undefined' && window.sessionStorage !== null; | ||
} | ||
return hasSessionStorageSupport; | ||
}; | ||
var sessionStorage = { | ||
@@ -259,3 +217,2 @@ name: 'sessionStorage', | ||
var found; | ||
if (options.lookupSessionStorage && sessionStorageAvailable()) { | ||
@@ -265,3 +222,2 @@ var lng = window.sessionStorage.getItem(options.lookupSessionStorage); | ||
} | ||
return found; | ||
@@ -280,3 +236,2 @@ }, | ||
var found = []; | ||
if (typeof navigator !== 'undefined') { | ||
@@ -289,7 +244,5 @@ if (navigator.languages) { | ||
} | ||
if (navigator.userLanguage) { | ||
found.push(navigator.userLanguage); | ||
} | ||
if (navigator.language) { | ||
@@ -299,3 +252,2 @@ found.push(navigator.language); | ||
} | ||
return found.length > 0 ? found : undefined; | ||
@@ -310,7 +262,5 @@ } | ||
var htmlTag = options.htmlTag || (typeof document !== 'undefined' ? document.documentElement : null); | ||
if (htmlTag && typeof htmlTag.getAttribute === 'function') { | ||
found = htmlTag.getAttribute('lang'); | ||
} | ||
return found; | ||
@@ -324,6 +274,4 @@ } | ||
var found; | ||
if (typeof window !== 'undefined') { | ||
var language = window.location.pathname.match(/\/([a-zA-Z-]*)/g); | ||
if (language instanceof Array) { | ||
@@ -334,3 +282,2 @@ if (typeof options.lookupFromPathIndex === 'number') { | ||
} | ||
found = language[options.lookupFromPathIndex].replace('/', ''); | ||
@@ -342,3 +289,2 @@ } else { | ||
} | ||
return found; | ||
@@ -352,10 +298,11 @@ } | ||
// If given get the subdomain index else 1 | ||
var lookupFromSubdomainIndex = typeof options.lookupFromSubdomainIndex === 'number' ? options.lookupFromSubdomainIndex + 1 : 1; // get all matches if window.location. is existing | ||
var lookupFromSubdomainIndex = typeof options.lookupFromSubdomainIndex === 'number' ? options.lookupFromSubdomainIndex + 1 : 1; | ||
// get all matches if window.location. is existing | ||
// first item of match is the match itself and the second is the first group macht which sould be the first subdomain match | ||
// is the hostname no public domain get the or option of localhost | ||
var language = typeof window !== 'undefined' && window.location && window.location.hostname && window.location.hostname.match(/^(\w{2,5})\.(([a-z0-9-]{1,63}\.[a-z]{2,6})|localhost)/i); | ||
var language = typeof window !== 'undefined' && window.location && window.location.hostname && window.location.hostname.match(/^(\w{2,5})\.(([a-z0-9-]{1,63}\.[a-z]{2,6})|localhost)/i); // if there is no match (null) return undefined | ||
if (!language) return undefined; // return the given group match | ||
// if there is no match (null) return undefined | ||
if (!language) return undefined; | ||
// return the given group match | ||
return language[lookupFromSubdomainIndex]; | ||
@@ -374,14 +321,11 @@ } | ||
caches: ['localStorage'], | ||
excludeCacheFor: ['cimode'] // cookieMinutes: 10, | ||
excludeCacheFor: ['cimode'] | ||
// cookieMinutes: 10, | ||
// cookieDomain: 'myDomain' | ||
}; | ||
} | ||
var Browser = /*#__PURE__*/function () { | ||
function Browser(services) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
_classCallCheck__default["default"](this, Browser); | ||
this.type = 'languageDetector'; | ||
@@ -391,3 +335,2 @@ this.detectors = {}; | ||
} | ||
_createClass__default["default"](Browser, [{ | ||
@@ -399,4 +342,5 @@ key: "init", | ||
this.services = services; | ||
this.options = defaults(options, this.options || {}, getDefaults()); // backwards compatibility | ||
this.options = defaults(options, this.options || {}, getDefaults()); | ||
// backwards compatibility | ||
if (this.options.lookupFromUrlIndex) this.options.lookupFromPathIndex = this.options.lookupFromUrlIndex; | ||
@@ -422,3 +366,2 @@ this.i18nOptions = i18nOptions; | ||
var _this = this; | ||
if (!detectionOrder) detectionOrder = this.options.order; | ||
@@ -429,3 +372,2 @@ var detected = []; | ||
var lookup = _this.detectors[detectorName].lookup(_this.options); | ||
if (lookup && typeof lookup === 'string') lookup = [lookup]; | ||
@@ -436,3 +378,2 @@ if (lookup) detected = detected.concat(lookup); | ||
if (this.services.languageUtils.getBestMatchFromCodes) return detected; // new i18next v19.5.0 | ||
return detected.length > 0 ? detected[0] : null; // a little backward compatibility | ||
@@ -444,3 +385,2 @@ } | ||
var _this2 = this; | ||
if (!caches) caches = this.options.caches; | ||
@@ -454,8 +394,6 @@ if (!caches) return; | ||
}]); | ||
return Browser; | ||
}(); | ||
Browser.type = 'languageDetector'; | ||
module.exports = Browser; |
@@ -20,3 +20,2 @@ import _classCallCheck from '@babel/runtime/helpers/esm/classCallCheck'; | ||
var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/; | ||
var serializeCookie = function serializeCookie(name, val, options) { | ||
@@ -27,3 +26,2 @@ var opt = options || {}; | ||
var str = "".concat(name, "=").concat(value); | ||
if (opt.maxAge > 0) { | ||
@@ -34,3 +32,2 @@ var maxAge = opt.maxAge - 0; | ||
} | ||
if (opt.domain) { | ||
@@ -40,6 +37,4 @@ if (!fieldContentRegExp.test(opt.domain)) { | ||
} | ||
str += "; Domain=".concat(opt.domain); | ||
} | ||
if (opt.path) { | ||
@@ -49,6 +44,4 @@ if (!fieldContentRegExp.test(opt.path)) { | ||
} | ||
str += "; Path=".concat(opt.path); | ||
} | ||
if (opt.expires) { | ||
@@ -58,12 +51,8 @@ if (typeof opt.expires.toUTCString !== 'function') { | ||
} | ||
str += "; Expires=".concat(opt.expires.toUTCString()); | ||
} | ||
if (opt.httpOnly) str += '; HttpOnly'; | ||
if (opt.secure) str += '; Secure'; | ||
if (opt.sameSite) { | ||
var sameSite = typeof opt.sameSite === 'string' ? opt.sameSite.toLowerCase() : opt.sameSite; | ||
switch (sameSite) { | ||
@@ -73,15 +62,11 @@ case true: | ||
break; | ||
case 'lax': | ||
str += '; SameSite=Lax'; | ||
break; | ||
case 'strict': | ||
str += '; SameSite=Strict'; | ||
break; | ||
case 'none': | ||
str += '; SameSite=None'; | ||
break; | ||
default: | ||
@@ -91,6 +76,4 @@ throw new TypeError('option sameSite is invalid'); | ||
} | ||
return str; | ||
}; | ||
var cookie = { | ||
@@ -102,3 +85,2 @@ create: function create(name, value, minutes, domain) { | ||
}; | ||
if (minutes) { | ||
@@ -108,3 +90,2 @@ cookieOptions.expires = new Date(); | ||
} | ||
if (domain) cookieOptions.domain = domain; | ||
@@ -116,13 +97,9 @@ document.cookie = serializeCookie(name, encodeURIComponent(value), cookieOptions); | ||
var ca = document.cookie.split(';'); | ||
for (var i = 0; i < ca.length; i++) { | ||
var c = ca[i]; | ||
while (c.charAt(0) === ' ') { | ||
c = c.substring(1, c.length); | ||
} | ||
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length); | ||
} | ||
return null; | ||
@@ -138,3 +115,2 @@ }, | ||
var found; | ||
if (options.lookupCookie && typeof document !== 'undefined') { | ||
@@ -144,3 +120,2 @@ var c = cookie.read(options.lookupCookie); | ||
} | ||
return found; | ||
@@ -159,19 +134,13 @@ }, | ||
var found; | ||
if (typeof window !== 'undefined') { | ||
var search = window.location.search; | ||
if (!window.location.search && window.location.hash && window.location.hash.indexOf('?') > -1) { | ||
search = window.location.hash.substring(window.location.hash.indexOf('?')); | ||
} | ||
var query = search.substring(1); | ||
var params = query.split('&'); | ||
for (var i = 0; i < params.length; i++) { | ||
var pos = params[i].indexOf('='); | ||
if (pos > 0) { | ||
var key = params[i].substring(0, pos); | ||
if (key === options.lookupQuerystring) { | ||
@@ -183,3 +152,2 @@ found = params[i].substring(pos + 1); | ||
} | ||
return found; | ||
@@ -190,6 +158,4 @@ } | ||
var hasLocalStorageSupport = null; | ||
var localStorageAvailable = function localStorageAvailable() { | ||
if (hasLocalStorageSupport !== null) return hasLocalStorageSupport; | ||
try { | ||
@@ -203,6 +169,4 @@ hasLocalStorageSupport = window !== 'undefined' && window.localStorage !== null; | ||
} | ||
return hasLocalStorageSupport; | ||
}; | ||
var localStorage = { | ||
@@ -212,3 +176,2 @@ name: 'localStorage', | ||
var found; | ||
if (options.lookupLocalStorage && localStorageAvailable()) { | ||
@@ -218,3 +181,2 @@ var lng = window.localStorage.getItem(options.lookupLocalStorage); | ||
} | ||
return found; | ||
@@ -230,6 +192,4 @@ }, | ||
var hasSessionStorageSupport = null; | ||
var sessionStorageAvailable = function sessionStorageAvailable() { | ||
if (hasSessionStorageSupport !== null) return hasSessionStorageSupport; | ||
try { | ||
@@ -243,6 +203,4 @@ hasSessionStorageSupport = window !== 'undefined' && window.sessionStorage !== null; | ||
} | ||
return hasSessionStorageSupport; | ||
}; | ||
var sessionStorage = { | ||
@@ -252,3 +210,2 @@ name: 'sessionStorage', | ||
var found; | ||
if (options.lookupSessionStorage && sessionStorageAvailable()) { | ||
@@ -258,3 +215,2 @@ var lng = window.sessionStorage.getItem(options.lookupSessionStorage); | ||
} | ||
return found; | ||
@@ -273,3 +229,2 @@ }, | ||
var found = []; | ||
if (typeof navigator !== 'undefined') { | ||
@@ -282,7 +237,5 @@ if (navigator.languages) { | ||
} | ||
if (navigator.userLanguage) { | ||
found.push(navigator.userLanguage); | ||
} | ||
if (navigator.language) { | ||
@@ -292,3 +245,2 @@ found.push(navigator.language); | ||
} | ||
return found.length > 0 ? found : undefined; | ||
@@ -303,7 +255,5 @@ } | ||
var htmlTag = options.htmlTag || (typeof document !== 'undefined' ? document.documentElement : null); | ||
if (htmlTag && typeof htmlTag.getAttribute === 'function') { | ||
found = htmlTag.getAttribute('lang'); | ||
} | ||
return found; | ||
@@ -317,6 +267,4 @@ } | ||
var found; | ||
if (typeof window !== 'undefined') { | ||
var language = window.location.pathname.match(/\/([a-zA-Z-]*)/g); | ||
if (language instanceof Array) { | ||
@@ -327,3 +275,2 @@ if (typeof options.lookupFromPathIndex === 'number') { | ||
} | ||
found = language[options.lookupFromPathIndex].replace('/', ''); | ||
@@ -335,3 +282,2 @@ } else { | ||
} | ||
return found; | ||
@@ -345,10 +291,11 @@ } | ||
// If given get the subdomain index else 1 | ||
var lookupFromSubdomainIndex = typeof options.lookupFromSubdomainIndex === 'number' ? options.lookupFromSubdomainIndex + 1 : 1; // get all matches if window.location. is existing | ||
var lookupFromSubdomainIndex = typeof options.lookupFromSubdomainIndex === 'number' ? options.lookupFromSubdomainIndex + 1 : 1; | ||
// get all matches if window.location. is existing | ||
// first item of match is the match itself and the second is the first group macht which sould be the first subdomain match | ||
// is the hostname no public domain get the or option of localhost | ||
var language = typeof window !== 'undefined' && window.location && window.location.hostname && window.location.hostname.match(/^(\w{2,5})\.(([a-z0-9-]{1,63}\.[a-z]{2,6})|localhost)/i); | ||
var language = typeof window !== 'undefined' && window.location && window.location.hostname && window.location.hostname.match(/^(\w{2,5})\.(([a-z0-9-]{1,63}\.[a-z]{2,6})|localhost)/i); // if there is no match (null) return undefined | ||
if (!language) return undefined; // return the given group match | ||
// if there is no match (null) return undefined | ||
if (!language) return undefined; | ||
// return the given group match | ||
return language[lookupFromSubdomainIndex]; | ||
@@ -367,14 +314,11 @@ } | ||
caches: ['localStorage'], | ||
excludeCacheFor: ['cimode'] // cookieMinutes: 10, | ||
excludeCacheFor: ['cimode'] | ||
// cookieMinutes: 10, | ||
// cookieDomain: 'myDomain' | ||
}; | ||
} | ||
var Browser = /*#__PURE__*/function () { | ||
function Browser(services) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
_classCallCheck(this, Browser); | ||
this.type = 'languageDetector'; | ||
@@ -384,3 +328,2 @@ this.detectors = {}; | ||
} | ||
_createClass(Browser, [{ | ||
@@ -392,4 +335,5 @@ key: "init", | ||
this.services = services; | ||
this.options = defaults(options, this.options || {}, getDefaults()); // backwards compatibility | ||
this.options = defaults(options, this.options || {}, getDefaults()); | ||
// backwards compatibility | ||
if (this.options.lookupFromUrlIndex) this.options.lookupFromPathIndex = this.options.lookupFromUrlIndex; | ||
@@ -415,3 +359,2 @@ this.i18nOptions = i18nOptions; | ||
var _this = this; | ||
if (!detectionOrder) detectionOrder = this.options.order; | ||
@@ -422,3 +365,2 @@ var detected = []; | ||
var lookup = _this.detectors[detectorName].lookup(_this.options); | ||
if (lookup && typeof lookup === 'string') lookup = [lookup]; | ||
@@ -429,3 +371,2 @@ if (lookup) detected = detected.concat(lookup); | ||
if (this.services.languageUtils.getBestMatchFromCodes) return detected; // new i18next v19.5.0 | ||
return detected.length > 0 ? detected[0] : null; // a little backward compatibility | ||
@@ -437,3 +378,2 @@ } | ||
var _this2 = this; | ||
if (!caches) caches = this.options.caches; | ||
@@ -447,8 +387,6 @@ if (!caches) return; | ||
}]); | ||
return Browser; | ||
}(); | ||
Browser.type = 'languageDetector'; | ||
export { Browser as default }; |
@@ -22,3 +22,2 @@ (function (global, factory) { | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
@@ -49,3 +48,2 @@ if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/; | ||
var serializeCookie = function serializeCookie(name, val, options) { | ||
@@ -56,3 +54,2 @@ var opt = options || {}; | ||
var str = "".concat(name, "=").concat(value); | ||
if (opt.maxAge > 0) { | ||
@@ -63,3 +60,2 @@ var maxAge = opt.maxAge - 0; | ||
} | ||
if (opt.domain) { | ||
@@ -69,6 +65,4 @@ if (!fieldContentRegExp.test(opt.domain)) { | ||
} | ||
str += "; Domain=".concat(opt.domain); | ||
} | ||
if (opt.path) { | ||
@@ -78,6 +72,4 @@ if (!fieldContentRegExp.test(opt.path)) { | ||
} | ||
str += "; Path=".concat(opt.path); | ||
} | ||
if (opt.expires) { | ||
@@ -87,12 +79,8 @@ if (typeof opt.expires.toUTCString !== 'function') { | ||
} | ||
str += "; Expires=".concat(opt.expires.toUTCString()); | ||
} | ||
if (opt.httpOnly) str += '; HttpOnly'; | ||
if (opt.secure) str += '; Secure'; | ||
if (opt.sameSite) { | ||
var sameSite = typeof opt.sameSite === 'string' ? opt.sameSite.toLowerCase() : opt.sameSite; | ||
switch (sameSite) { | ||
@@ -102,15 +90,11 @@ case true: | ||
break; | ||
case 'lax': | ||
str += '; SameSite=Lax'; | ||
break; | ||
case 'strict': | ||
str += '; SameSite=Strict'; | ||
break; | ||
case 'none': | ||
str += '; SameSite=None'; | ||
break; | ||
default: | ||
@@ -120,6 +104,4 @@ throw new TypeError('option sameSite is invalid'); | ||
} | ||
return str; | ||
}; | ||
var cookie = { | ||
@@ -131,3 +113,2 @@ create: function create(name, value, minutes, domain) { | ||
}; | ||
if (minutes) { | ||
@@ -137,3 +118,2 @@ cookieOptions.expires = new Date(); | ||
} | ||
if (domain) cookieOptions.domain = domain; | ||
@@ -145,13 +125,9 @@ document.cookie = serializeCookie(name, encodeURIComponent(value), cookieOptions); | ||
var ca = document.cookie.split(';'); | ||
for (var i = 0; i < ca.length; i++) { | ||
var c = ca[i]; | ||
while (c.charAt(0) === ' ') { | ||
c = c.substring(1, c.length); | ||
} | ||
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length); | ||
} | ||
return null; | ||
@@ -167,3 +143,2 @@ }, | ||
var found; | ||
if (options.lookupCookie && typeof document !== 'undefined') { | ||
@@ -173,3 +148,2 @@ var c = cookie.read(options.lookupCookie); | ||
} | ||
return found; | ||
@@ -188,19 +162,13 @@ }, | ||
var found; | ||
if (typeof window !== 'undefined') { | ||
var search = window.location.search; | ||
if (!window.location.search && window.location.hash && window.location.hash.indexOf('?') > -1) { | ||
search = window.location.hash.substring(window.location.hash.indexOf('?')); | ||
} | ||
var query = search.substring(1); | ||
var params = query.split('&'); | ||
for (var i = 0; i < params.length; i++) { | ||
var pos = params[i].indexOf('='); | ||
if (pos > 0) { | ||
var key = params[i].substring(0, pos); | ||
if (key === options.lookupQuerystring) { | ||
@@ -212,3 +180,2 @@ found = params[i].substring(pos + 1); | ||
} | ||
return found; | ||
@@ -219,6 +186,4 @@ } | ||
var hasLocalStorageSupport = null; | ||
var localStorageAvailable = function localStorageAvailable() { | ||
if (hasLocalStorageSupport !== null) return hasLocalStorageSupport; | ||
try { | ||
@@ -232,6 +197,4 @@ hasLocalStorageSupport = window !== 'undefined' && window.localStorage !== null; | ||
} | ||
return hasLocalStorageSupport; | ||
}; | ||
var localStorage = { | ||
@@ -241,3 +204,2 @@ name: 'localStorage', | ||
var found; | ||
if (options.lookupLocalStorage && localStorageAvailable()) { | ||
@@ -247,3 +209,2 @@ var lng = window.localStorage.getItem(options.lookupLocalStorage); | ||
} | ||
return found; | ||
@@ -259,6 +220,4 @@ }, | ||
var hasSessionStorageSupport = null; | ||
var sessionStorageAvailable = function sessionStorageAvailable() { | ||
if (hasSessionStorageSupport !== null) return hasSessionStorageSupport; | ||
try { | ||
@@ -272,6 +231,4 @@ hasSessionStorageSupport = window !== 'undefined' && window.sessionStorage !== null; | ||
} | ||
return hasSessionStorageSupport; | ||
}; | ||
var sessionStorage = { | ||
@@ -281,3 +238,2 @@ name: 'sessionStorage', | ||
var found; | ||
if (options.lookupSessionStorage && sessionStorageAvailable()) { | ||
@@ -287,3 +243,2 @@ var lng = window.sessionStorage.getItem(options.lookupSessionStorage); | ||
} | ||
return found; | ||
@@ -302,3 +257,2 @@ }, | ||
var found = []; | ||
if (typeof navigator !== 'undefined') { | ||
@@ -311,7 +265,5 @@ if (navigator.languages) { | ||
} | ||
if (navigator.userLanguage) { | ||
found.push(navigator.userLanguage); | ||
} | ||
if (navigator.language) { | ||
@@ -321,3 +273,2 @@ found.push(navigator.language); | ||
} | ||
return found.length > 0 ? found : undefined; | ||
@@ -332,7 +283,5 @@ } | ||
var htmlTag = options.htmlTag || (typeof document !== 'undefined' ? document.documentElement : null); | ||
if (htmlTag && typeof htmlTag.getAttribute === 'function') { | ||
found = htmlTag.getAttribute('lang'); | ||
} | ||
return found; | ||
@@ -346,6 +295,4 @@ } | ||
var found; | ||
if (typeof window !== 'undefined') { | ||
var language = window.location.pathname.match(/\/([a-zA-Z-]*)/g); | ||
if (language instanceof Array) { | ||
@@ -356,3 +303,2 @@ if (typeof options.lookupFromPathIndex === 'number') { | ||
} | ||
found = language[options.lookupFromPathIndex].replace('/', ''); | ||
@@ -364,3 +310,2 @@ } else { | ||
} | ||
return found; | ||
@@ -374,10 +319,11 @@ } | ||
// If given get the subdomain index else 1 | ||
var lookupFromSubdomainIndex = typeof options.lookupFromSubdomainIndex === 'number' ? options.lookupFromSubdomainIndex + 1 : 1; // get all matches if window.location. is existing | ||
var lookupFromSubdomainIndex = typeof options.lookupFromSubdomainIndex === 'number' ? options.lookupFromSubdomainIndex + 1 : 1; | ||
// get all matches if window.location. is existing | ||
// first item of match is the match itself and the second is the first group macht which sould be the first subdomain match | ||
// is the hostname no public domain get the or option of localhost | ||
var language = typeof window !== 'undefined' && window.location && window.location.hostname && window.location.hostname.match(/^(\w{2,5})\.(([a-z0-9-]{1,63}\.[a-z]{2,6})|localhost)/i); | ||
var language = typeof window !== 'undefined' && window.location && window.location.hostname && window.location.hostname.match(/^(\w{2,5})\.(([a-z0-9-]{1,63}\.[a-z]{2,6})|localhost)/i); // if there is no match (null) return undefined | ||
if (!language) return undefined; // return the given group match | ||
// if there is no match (null) return undefined | ||
if (!language) return undefined; | ||
// return the given group match | ||
return language[lookupFromSubdomainIndex]; | ||
@@ -396,14 +342,11 @@ } | ||
caches: ['localStorage'], | ||
excludeCacheFor: ['cimode'] // cookieMinutes: 10, | ||
excludeCacheFor: ['cimode'] | ||
// cookieMinutes: 10, | ||
// cookieDomain: 'myDomain' | ||
}; | ||
} | ||
var Browser = /*#__PURE__*/function () { | ||
function Browser(services) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
_classCallCheck(this, Browser); | ||
this.type = 'languageDetector'; | ||
@@ -413,3 +356,2 @@ this.detectors = {}; | ||
} | ||
_createClass(Browser, [{ | ||
@@ -421,4 +363,5 @@ key: "init", | ||
this.services = services; | ||
this.options = defaults(options, this.options || {}, getDefaults()); // backwards compatibility | ||
this.options = defaults(options, this.options || {}, getDefaults()); | ||
// backwards compatibility | ||
if (this.options.lookupFromUrlIndex) this.options.lookupFromPathIndex = this.options.lookupFromUrlIndex; | ||
@@ -444,3 +387,2 @@ this.i18nOptions = i18nOptions; | ||
var _this = this; | ||
if (!detectionOrder) detectionOrder = this.options.order; | ||
@@ -451,3 +393,2 @@ var detected = []; | ||
var lookup = _this.detectors[detectorName].lookup(_this.options); | ||
if (lookup && typeof lookup === 'string') lookup = [lookup]; | ||
@@ -458,3 +399,2 @@ if (lookup) detected = detected.concat(lookup); | ||
if (this.services.languageUtils.getBestMatchFromCodes) return detected; // new i18next v19.5.0 | ||
return detected.length > 0 ? detected[0] : null; // a little backward compatibility | ||
@@ -466,3 +406,2 @@ } | ||
var _this2 = this; | ||
if (!caches) caches = this.options.caches; | ||
@@ -476,6 +415,4 @@ if (!caches) return; | ||
}]); | ||
return Browser; | ||
}(); | ||
Browser.type = 'languageDetector'; | ||
@@ -482,0 +419,0 @@ |
@@ -22,3 +22,2 @@ (function (global, factory) { | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
@@ -49,3 +48,2 @@ if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/; | ||
var serializeCookie = function serializeCookie(name, val, options) { | ||
@@ -56,3 +54,2 @@ var opt = options || {}; | ||
var str = "".concat(name, "=").concat(value); | ||
if (opt.maxAge > 0) { | ||
@@ -63,3 +60,2 @@ var maxAge = opt.maxAge - 0; | ||
} | ||
if (opt.domain) { | ||
@@ -69,6 +65,4 @@ if (!fieldContentRegExp.test(opt.domain)) { | ||
} | ||
str += "; Domain=".concat(opt.domain); | ||
} | ||
if (opt.path) { | ||
@@ -78,6 +72,4 @@ if (!fieldContentRegExp.test(opt.path)) { | ||
} | ||
str += "; Path=".concat(opt.path); | ||
} | ||
if (opt.expires) { | ||
@@ -87,12 +79,8 @@ if (typeof opt.expires.toUTCString !== 'function') { | ||
} | ||
str += "; Expires=".concat(opt.expires.toUTCString()); | ||
} | ||
if (opt.httpOnly) str += '; HttpOnly'; | ||
if (opt.secure) str += '; Secure'; | ||
if (opt.sameSite) { | ||
var sameSite = typeof opt.sameSite === 'string' ? opt.sameSite.toLowerCase() : opt.sameSite; | ||
switch (sameSite) { | ||
@@ -102,15 +90,11 @@ case true: | ||
break; | ||
case 'lax': | ||
str += '; SameSite=Lax'; | ||
break; | ||
case 'strict': | ||
str += '; SameSite=Strict'; | ||
break; | ||
case 'none': | ||
str += '; SameSite=None'; | ||
break; | ||
default: | ||
@@ -120,6 +104,4 @@ throw new TypeError('option sameSite is invalid'); | ||
} | ||
return str; | ||
}; | ||
var cookie = { | ||
@@ -131,3 +113,2 @@ create: function create(name, value, minutes, domain) { | ||
}; | ||
if (minutes) { | ||
@@ -137,3 +118,2 @@ cookieOptions.expires = new Date(); | ||
} | ||
if (domain) cookieOptions.domain = domain; | ||
@@ -145,13 +125,9 @@ document.cookie = serializeCookie(name, encodeURIComponent(value), cookieOptions); | ||
var ca = document.cookie.split(';'); | ||
for (var i = 0; i < ca.length; i++) { | ||
var c = ca[i]; | ||
while (c.charAt(0) === ' ') { | ||
c = c.substring(1, c.length); | ||
} | ||
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length); | ||
} | ||
return null; | ||
@@ -167,3 +143,2 @@ }, | ||
var found; | ||
if (options.lookupCookie && typeof document !== 'undefined') { | ||
@@ -173,3 +148,2 @@ var c = cookie.read(options.lookupCookie); | ||
} | ||
return found; | ||
@@ -188,19 +162,13 @@ }, | ||
var found; | ||
if (typeof window !== 'undefined') { | ||
var search = window.location.search; | ||
if (!window.location.search && window.location.hash && window.location.hash.indexOf('?') > -1) { | ||
search = window.location.hash.substring(window.location.hash.indexOf('?')); | ||
} | ||
var query = search.substring(1); | ||
var params = query.split('&'); | ||
for (var i = 0; i < params.length; i++) { | ||
var pos = params[i].indexOf('='); | ||
if (pos > 0) { | ||
var key = params[i].substring(0, pos); | ||
if (key === options.lookupQuerystring) { | ||
@@ -212,3 +180,2 @@ found = params[i].substring(pos + 1); | ||
} | ||
return found; | ||
@@ -219,6 +186,4 @@ } | ||
var hasLocalStorageSupport = null; | ||
var localStorageAvailable = function localStorageAvailable() { | ||
if (hasLocalStorageSupport !== null) return hasLocalStorageSupport; | ||
try { | ||
@@ -232,6 +197,4 @@ hasLocalStorageSupport = window !== 'undefined' && window.localStorage !== null; | ||
} | ||
return hasLocalStorageSupport; | ||
}; | ||
var localStorage = { | ||
@@ -241,3 +204,2 @@ name: 'localStorage', | ||
var found; | ||
if (options.lookupLocalStorage && localStorageAvailable()) { | ||
@@ -247,3 +209,2 @@ var lng = window.localStorage.getItem(options.lookupLocalStorage); | ||
} | ||
return found; | ||
@@ -259,6 +220,4 @@ }, | ||
var hasSessionStorageSupport = null; | ||
var sessionStorageAvailable = function sessionStorageAvailable() { | ||
if (hasSessionStorageSupport !== null) return hasSessionStorageSupport; | ||
try { | ||
@@ -272,6 +231,4 @@ hasSessionStorageSupport = window !== 'undefined' && window.sessionStorage !== null; | ||
} | ||
return hasSessionStorageSupport; | ||
}; | ||
var sessionStorage = { | ||
@@ -281,3 +238,2 @@ name: 'sessionStorage', | ||
var found; | ||
if (options.lookupSessionStorage && sessionStorageAvailable()) { | ||
@@ -287,3 +243,2 @@ var lng = window.sessionStorage.getItem(options.lookupSessionStorage); | ||
} | ||
return found; | ||
@@ -302,3 +257,2 @@ }, | ||
var found = []; | ||
if (typeof navigator !== 'undefined') { | ||
@@ -311,7 +265,5 @@ if (navigator.languages) { | ||
} | ||
if (navigator.userLanguage) { | ||
found.push(navigator.userLanguage); | ||
} | ||
if (navigator.language) { | ||
@@ -321,3 +273,2 @@ found.push(navigator.language); | ||
} | ||
return found.length > 0 ? found : undefined; | ||
@@ -332,7 +283,5 @@ } | ||
var htmlTag = options.htmlTag || (typeof document !== 'undefined' ? document.documentElement : null); | ||
if (htmlTag && typeof htmlTag.getAttribute === 'function') { | ||
found = htmlTag.getAttribute('lang'); | ||
} | ||
return found; | ||
@@ -346,6 +295,4 @@ } | ||
var found; | ||
if (typeof window !== 'undefined') { | ||
var language = window.location.pathname.match(/\/([a-zA-Z-]*)/g); | ||
if (language instanceof Array) { | ||
@@ -356,3 +303,2 @@ if (typeof options.lookupFromPathIndex === 'number') { | ||
} | ||
found = language[options.lookupFromPathIndex].replace('/', ''); | ||
@@ -364,3 +310,2 @@ } else { | ||
} | ||
return found; | ||
@@ -374,10 +319,11 @@ } | ||
// If given get the subdomain index else 1 | ||
var lookupFromSubdomainIndex = typeof options.lookupFromSubdomainIndex === 'number' ? options.lookupFromSubdomainIndex + 1 : 1; // get all matches if window.location. is existing | ||
var lookupFromSubdomainIndex = typeof options.lookupFromSubdomainIndex === 'number' ? options.lookupFromSubdomainIndex + 1 : 1; | ||
// get all matches if window.location. is existing | ||
// first item of match is the match itself and the second is the first group macht which sould be the first subdomain match | ||
// is the hostname no public domain get the or option of localhost | ||
var language = typeof window !== 'undefined' && window.location && window.location.hostname && window.location.hostname.match(/^(\w{2,5})\.(([a-z0-9-]{1,63}\.[a-z]{2,6})|localhost)/i); | ||
var language = typeof window !== 'undefined' && window.location && window.location.hostname && window.location.hostname.match(/^(\w{2,5})\.(([a-z0-9-]{1,63}\.[a-z]{2,6})|localhost)/i); // if there is no match (null) return undefined | ||
if (!language) return undefined; // return the given group match | ||
// if there is no match (null) return undefined | ||
if (!language) return undefined; | ||
// return the given group match | ||
return language[lookupFromSubdomainIndex]; | ||
@@ -396,14 +342,11 @@ } | ||
caches: ['localStorage'], | ||
excludeCacheFor: ['cimode'] // cookieMinutes: 10, | ||
excludeCacheFor: ['cimode'] | ||
// cookieMinutes: 10, | ||
// cookieDomain: 'myDomain' | ||
}; | ||
} | ||
var Browser = /*#__PURE__*/function () { | ||
function Browser(services) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
_classCallCheck(this, Browser); | ||
this.type = 'languageDetector'; | ||
@@ -413,3 +356,2 @@ this.detectors = {}; | ||
} | ||
_createClass(Browser, [{ | ||
@@ -421,4 +363,5 @@ key: "init", | ||
this.services = services; | ||
this.options = defaults(options, this.options || {}, getDefaults()); // backwards compatibility | ||
this.options = defaults(options, this.options || {}, getDefaults()); | ||
// backwards compatibility | ||
if (this.options.lookupFromUrlIndex) this.options.lookupFromPathIndex = this.options.lookupFromUrlIndex; | ||
@@ -444,3 +387,2 @@ this.i18nOptions = i18nOptions; | ||
var _this = this; | ||
if (!detectionOrder) detectionOrder = this.options.order; | ||
@@ -451,3 +393,2 @@ var detected = []; | ||
var lookup = _this.detectors[detectorName].lookup(_this.options); | ||
if (lookup && typeof lookup === 'string') lookup = [lookup]; | ||
@@ -458,3 +399,2 @@ if (lookup) detected = detected.concat(lookup); | ||
if (this.services.languageUtils.getBestMatchFromCodes) return detected; // new i18next v19.5.0 | ||
return detected.length > 0 ? detected[0] : null; // a little backward compatibility | ||
@@ -466,3 +406,2 @@ } | ||
var _this2 = this; | ||
if (!caches) caches = this.options.caches; | ||
@@ -476,6 +415,4 @@ if (!caches) return; | ||
}]); | ||
return Browser; | ||
}(); | ||
Browser.type = 'languageDetector'; | ||
@@ -482,0 +419,0 @@ |
@@ -93,5 +93,5 @@ import * as i18next from 'i18next'; | ||
declare module 'i18next' { | ||
interface PluginOptions { | ||
interface CustomPluginOptions { | ||
detection?: DetectorOptions; | ||
} | ||
} |
{ | ||
"name": "i18next-browser-languagedetector", | ||
"version": "6.1.8", | ||
"version": "7.0.0", | ||
"description": "language detector used in browser environment for i18next", | ||
@@ -35,8 +35,8 @@ "main": "./dist/cjs/i18nextBrowserLanguageDetector.js", | ||
"dependencies": { | ||
"@babel/runtime": "^7.19.0" | ||
"@babel/runtime": "^7.19.4" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.19.3", | ||
"@babel/plugin-transform-runtime": "^7.19.1", | ||
"@babel/preset-env": "^7.19.3", | ||
"@babel/core": "^7.19.6", | ||
"@babel/plugin-transform-runtime": "^7.19.6", | ||
"@babel/preset-env": "^7.19.4", | ||
"@babel/eslint-parser": "^7.19.1", | ||
@@ -51,8 +51,8 @@ "babel-polyfill": "^6.26.0", | ||
"dtslint": "^4.2.1", | ||
"eslint": "8.24.0", | ||
"eslint": "8.26.0", | ||
"eslint-config-airbnb": "19.0.4", | ||
"expect.js": "0.3.1", | ||
"i18next": "21.10.0", | ||
"i18next": "22.0.2", | ||
"mkdirp": "1.0.4", | ||
"mocha": "10.0.0", | ||
"mocha": "10.1.0", | ||
"rimraf": "3.0.2", | ||
@@ -64,2 +64,3 @@ "rollup": "^2.79.1", | ||
"tslint": "^5.20.1", | ||
"tsd": "0.24.1", | ||
"typescript": "^4.8.4", | ||
@@ -72,3 +73,3 @@ "yargs": "17.6.0" | ||
"test": "npm run build && mocha test -R spec --exit", | ||
"test:typescript": "tslint --project tsconfig.json", | ||
"test:typescript": "tslint --project tsconfig.json && tsd", | ||
"test:typescript:noninterop": "tslint --project tsconfig.nonEsModuleInterop.json", | ||
@@ -79,4 +80,7 @@ "build": "rimraf dist && rollup -c && cpy \"./dist/umd/*.js\" ./", | ||
}, | ||
"tsd": { | ||
"directory": "test/typescript" | ||
}, | ||
"author": "Jan Mühlemann <jan.muehlemann@gmail.com> (https://github.com/jamuhl)", | ||
"license": "MIT" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1559
80826
27
Updated@babel/runtime@^7.19.4