Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

i18next-browser-languagedetector

Package Overview
Dependencies
Maintainers
2
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

i18next-browser-languagedetector - npm Package Compare versions

Comparing version 4.0.2 to 4.1.0

4

CHANGELOG.md

@@ -0,1 +1,5 @@

### 4.1.0
- feat: add cookieOptions for setting cookies [203](https://github.com/i18next/i18next-browser-languageDetector/pull/203)
### 4.0.2

@@ -2,0 +6,0 @@

@@ -24,2 +24,5 @@ 'use strict';

create: function create(name, value, minutes, domain) {
var cookieOptions = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
path: '/'
};
var expires;

@@ -30,7 +33,12 @@

date.setTime(date.getTime() + minutes * 60 * 1000);
expires = '; expires=' + date.toGMTString();
expires = '; expires=' + date.toUTCString();
} else expires = '';
domain = domain ? 'domain=' + domain + ';' : '';
document.cookie = name + '=' + value + expires + ';' + domain + 'path=/';
cookieOptions = Object.keys(cookieOptions).reduce(function (acc, key) {
return acc + ';' + key.replace(/([A-Z])/g, function ($1) {
return '-' + $1.toLowerCase();
}) + '=' + cookieOptions[key];
}, '');
document.cookie = name + '=' + encodeURIComponent(value) + expires + ';' + domain + cookieOptions;
},

@@ -37,0 +45,0 @@ read: function read(name) {

@@ -20,2 +20,5 @@ import _classCallCheck from '@babel/runtime/helpers/esm/classCallCheck';

create: function create(name, value, minutes, domain) {
var cookieOptions = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
path: '/'
};
var expires;

@@ -26,7 +29,12 @@

date.setTime(date.getTime() + minutes * 60 * 1000);
expires = '; expires=' + date.toGMTString();
expires = '; expires=' + date.toUTCString();
} else expires = '';
domain = domain ? 'domain=' + domain + ';' : '';
document.cookie = name + '=' + value + expires + ';' + domain + 'path=/';
cookieOptions = Object.keys(cookieOptions).reduce(function (acc, key) {
return acc + ';' + key.replace(/([A-Z])/g, function ($1) {
return '-' + $1.toLowerCase();
}) + '=' + cookieOptions[key];
}, '');
document.cookie = name + '=' + encodeURIComponent(value) + expires + ';' + domain + cookieOptions;
},

@@ -33,0 +41,0 @@ read: function read(name) {

@@ -45,2 +45,5 @@ (function (global, factory) {

create: function create(name, value, minutes, domain) {
var cookieOptions = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
path: '/'
};
var expires;

@@ -51,7 +54,12 @@

date.setTime(date.getTime() + minutes * 60 * 1000);
expires = '; expires=' + date.toGMTString();
expires = '; expires=' + date.toUTCString();
} else expires = '';
domain = domain ? 'domain=' + domain + ';' : '';
document.cookie = name + '=' + value + expires + ';' + domain + 'path=/';
cookieOptions = Object.keys(cookieOptions).reduce(function (acc, key) {
return acc + ';' + key.replace(/([A-Z])/g, function ($1) {
return '-' + $1.toLowerCase();
}) + '=' + cookieOptions[key];
}, '');
document.cookie = name + '=' + encodeURIComponent(value) + expires + ';' + domain + cookieOptions;
},

@@ -58,0 +66,0 @@ read: function read(name) {

2

dist/umd/i18nextBrowserLanguageDetector.min.js

@@ -1,1 +0,1 @@

!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?module.exports=o():"function"==typeof define&&define.amd?define(o):(e=e||self).i18nextBrowserLanguageDetector=o()}(this,(function(){"use strict";function e(e,o){for(var t=0;t<o.length;t++){var n=o[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}var o=[],t=o.forEach,n=o.slice;function a(e){return t.call(n.call(arguments,1),(function(o){if(o)for(var t in o)void 0===e[t]&&(e[t]=o[t])})),e}var i,r=function(e,o,t,n){var a;if(t){var i=new Date;i.setTime(i.getTime()+60*t*1e3),a="; expires="+i.toGMTString()}else a="";n=n?"domain="+n+";":"",document.cookie=e+"="+o+a+";"+n+"path=/"},u=function(e){for(var o=e+"=",t=document.cookie.split(";"),n=0;n<t.length;n++){for(var a=t[n];" "===a.charAt(0);)a=a.substring(1,a.length);if(0===a.indexOf(o))return a.substring(o.length,a.length)}return null},c={name:"cookie",lookup:function(e){var o;if(e.lookupCookie&&"undefined"!=typeof document){var t=u(e.lookupCookie);t&&(o=t)}return o},cacheUserLanguage:function(e,o){o.lookupCookie&&"undefined"!=typeof document&&r(o.lookupCookie,e,o.cookieMinutes,o.cookieDomain)}},l={name:"querystring",lookup:function(e){var o;if("undefined"!=typeof window)for(var t=window.location.search.substring(1).split("&"),n=0;n<t.length;n++){var a=t[n].indexOf("=");if(a>0)t[n].substring(0,a)===e.lookupQuerystring&&(o=t[n].substring(a+1))}return o}};try{i="undefined"!==window&&null!==window.localStorage;window.localStorage.setItem("i18next.translate.boo","foo"),window.localStorage.removeItem("i18next.translate.boo")}catch(e){i=!1}var s={name:"localStorage",lookup:function(e){var o;if(e.lookupLocalStorage&&i){var t=window.localStorage.getItem(e.lookupLocalStorage);t&&(o=t)}return o},cacheUserLanguage:function(e,o){o.lookupLocalStorage&&i&&window.localStorage.setItem(o.lookupLocalStorage,e)}},f={name:"navigator",lookup:function(e){var o=[];if("undefined"!=typeof navigator){if(navigator.languages)for(var t=0;t<navigator.languages.length;t++)o.push(navigator.languages[t]);navigator.userLanguage&&o.push(navigator.userLanguage),navigator.language&&o.push(navigator.language)}return o.length>0?o:void 0}},d={name:"htmlTag",lookup:function(e){var o,t=e.htmlTag||("undefined"!=typeof document?document.documentElement:null);return t&&"function"==typeof t.getAttribute&&(o=t.getAttribute("lang")),o}},g={name:"path",lookup:function(e){var o;if("undefined"!=typeof window){var t=window.location.pathname.match(/\/([a-zA-Z-]*)/g);if(t instanceof Array)if("number"==typeof e.lookupFromPathIndex){if("string"!=typeof t[e.lookupFromPathIndex])return;o=t[e.lookupFromPathIndex].replace("/","")}else o=t[0].replace("/","")}return o}},p={name:"subdomain",lookup:function(e){var o;if("undefined"!=typeof window){var t=window.location.href.match(/(?:http[s]*\:\/\/)*(.*?)\.(?=[^\/]*\..{2,5})/gi);t instanceof Array&&(o="number"==typeof e.lookupFromSubdomainIndex?t[e.lookupFromSubdomainIndex].replace("http://","").replace("https://","").replace(".",""):t[0].replace("http://","").replace("https://","").replace(".",""))}return o}};var h=function(){function o(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};!function(e,o){if(!(e instanceof o))throw new TypeError("Cannot call a class as a function")}(this,o),this.type="languageDetector",this.detectors={},this.init(e,t)}var t,n,i;return t=o,(n=[{key:"init",value:function(e){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.services=e,this.options=a(o,this.options||{},{order:["querystring","cookie","localStorage","navigator","htmlTag"],lookupQuerystring:"lng",lookupCookie:"i18next",lookupLocalStorage:"i18nextLng",caches:["localStorage"],excludeCacheFor:["cimode"],checkWhitelist:!0}),this.options.lookupFromUrlIndex&&(this.options.lookupFromPathIndex=this.options.lookupFromUrlIndex),this.i18nOptions=t,this.addDetector(c),this.addDetector(l),this.addDetector(s),this.addDetector(f),this.addDetector(d),this.addDetector(g),this.addDetector(p)}},{key:"addDetector",value:function(e){this.detectors[e.name]=e}},{key:"detect",value:function(e){var o=this;e||(e=this.options.order);var t,n=[];if(e.forEach((function(e){if(o.detectors[e]){var t=o.detectors[e].lookup(o.options);t&&"string"==typeof t&&(t=[t]),t&&(n=n.concat(t))}})),n.forEach((function(e){if(!t){var n=o.services.languageUtils.formatLanguageCode(e);o.options.checkWhitelist&&!o.services.languageUtils.isWhitelisted(n)||(t=n)}})),!t){var a=this.i18nOptions.fallbackLng;"string"==typeof a&&(a=[a]),a||(a=[]),t="[object Array]"===Object.prototype.toString.apply(a)?a[0]:a[0]||a.default&&a.default[0]}return t}},{key:"cacheUserLanguage",value:function(e,o){var t=this;o||(o=this.options.caches),o&&(this.options.excludeCacheFor&&this.options.excludeCacheFor.indexOf(e)>-1||o.forEach((function(o){t.detectors[o]&&t.detectors[o].cacheUserLanguage(e,t.options)})))}}])&&e(t.prototype,n),i&&e(t,i),o}();return h.type="languageDetector",h}));
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?module.exports=o():"function"==typeof define&&define.amd?define(o):(e=e||self).i18nextBrowserLanguageDetector=o()}(this,(function(){"use strict";function e(e,o){for(var t=0;t<o.length;t++){var n=o[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}var o=[],t=o.forEach,n=o.slice;function a(e){return t.call(n.call(arguments,1),(function(o){if(o)for(var t in o)void 0===e[t]&&(e[t]=o[t])})),e}var i,r=function(e,o,t,n){var a,i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{path:"/"};if(t){var r=new Date;r.setTime(r.getTime()+60*t*1e3),a="; expires="+r.toUTCString()}else a="";n=n?"domain="+n+";":"",i=Object.keys(i).reduce((function(e,o){return e+";"+o.replace(/([A-Z])/g,(function(e){return"-"+e.toLowerCase()}))+"="+i[o]}),""),document.cookie=e+"="+encodeURIComponent(o)+a+";"+n+i},u=function(e){for(var o=e+"=",t=document.cookie.split(";"),n=0;n<t.length;n++){for(var a=t[n];" "===a.charAt(0);)a=a.substring(1,a.length);if(0===a.indexOf(o))return a.substring(o.length,a.length)}return null},c={name:"cookie",lookup:function(e){var o;if(e.lookupCookie&&"undefined"!=typeof document){var t=u(e.lookupCookie);t&&(o=t)}return o},cacheUserLanguage:function(e,o){o.lookupCookie&&"undefined"!=typeof document&&r(o.lookupCookie,e,o.cookieMinutes,o.cookieDomain)}},l={name:"querystring",lookup:function(e){var o;if("undefined"!=typeof window)for(var t=window.location.search.substring(1).split("&"),n=0;n<t.length;n++){var a=t[n].indexOf("=");if(a>0)t[n].substring(0,a)===e.lookupQuerystring&&(o=t[n].substring(a+1))}return o}};try{i="undefined"!==window&&null!==window.localStorage;window.localStorage.setItem("i18next.translate.boo","foo"),window.localStorage.removeItem("i18next.translate.boo")}catch(e){i=!1}var s={name:"localStorage",lookup:function(e){var o;if(e.lookupLocalStorage&&i){var t=window.localStorage.getItem(e.lookupLocalStorage);t&&(o=t)}return o},cacheUserLanguage:function(e,o){o.lookupLocalStorage&&i&&window.localStorage.setItem(o.lookupLocalStorage,e)}},f={name:"navigator",lookup:function(e){var o=[];if("undefined"!=typeof navigator){if(navigator.languages)for(var t=0;t<navigator.languages.length;t++)o.push(navigator.languages[t]);navigator.userLanguage&&o.push(navigator.userLanguage),navigator.language&&o.push(navigator.language)}return o.length>0?o:void 0}},d={name:"htmlTag",lookup:function(e){var o,t=e.htmlTag||("undefined"!=typeof document?document.documentElement:null);return t&&"function"==typeof t.getAttribute&&(o=t.getAttribute("lang")),o}},g={name:"path",lookup:function(e){var o;if("undefined"!=typeof window){var t=window.location.pathname.match(/\/([a-zA-Z-]*)/g);if(t instanceof Array)if("number"==typeof e.lookupFromPathIndex){if("string"!=typeof t[e.lookupFromPathIndex])return;o=t[e.lookupFromPathIndex].replace("/","")}else o=t[0].replace("/","")}return o}},p={name:"subdomain",lookup:function(e){var o;if("undefined"!=typeof window){var t=window.location.href.match(/(?:http[s]*\:\/\/)*(.*?)\.(?=[^\/]*\..{2,5})/gi);t instanceof Array&&(o="number"==typeof e.lookupFromSubdomainIndex?t[e.lookupFromSubdomainIndex].replace("http://","").replace("https://","").replace(".",""):t[0].replace("http://","").replace("https://","").replace(".",""))}return o}};var h=function(){function o(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};!function(e,o){if(!(e instanceof o))throw new TypeError("Cannot call a class as a function")}(this,o),this.type="languageDetector",this.detectors={},this.init(e,t)}var t,n,i;return t=o,(n=[{key:"init",value:function(e){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.services=e,this.options=a(o,this.options||{},{order:["querystring","cookie","localStorage","navigator","htmlTag"],lookupQuerystring:"lng",lookupCookie:"i18next",lookupLocalStorage:"i18nextLng",caches:["localStorage"],excludeCacheFor:["cimode"],checkWhitelist:!0}),this.options.lookupFromUrlIndex&&(this.options.lookupFromPathIndex=this.options.lookupFromUrlIndex),this.i18nOptions=t,this.addDetector(c),this.addDetector(l),this.addDetector(s),this.addDetector(f),this.addDetector(d),this.addDetector(g),this.addDetector(p)}},{key:"addDetector",value:function(e){this.detectors[e.name]=e}},{key:"detect",value:function(e){var o=this;e||(e=this.options.order);var t,n=[];if(e.forEach((function(e){if(o.detectors[e]){var t=o.detectors[e].lookup(o.options);t&&"string"==typeof t&&(t=[t]),t&&(n=n.concat(t))}})),n.forEach((function(e){if(!t){var n=o.services.languageUtils.formatLanguageCode(e);o.options.checkWhitelist&&!o.services.languageUtils.isWhitelisted(n)||(t=n)}})),!t){var a=this.i18nOptions.fallbackLng;"string"==typeof a&&(a=[a]),a||(a=[]),t="[object Array]"===Object.prototype.toString.apply(a)?a[0]:a[0]||a.default&&a.default[0]}return t}},{key:"cacheUserLanguage",value:function(e,o){var t=this;o||(o=this.options.caches),o&&(this.options.excludeCacheFor&&this.options.excludeCacheFor.indexOf(e)>-1||o.forEach((function(o){t.detectors[o]&&t.detectors[o].cacheUserLanguage(e,t.options)})))}}])&&e(t.prototype,n),i&&e(t,i),o}();return h.type="languageDetector",h}));

@@ -45,2 +45,5 @@ (function (global, factory) {

create: function create(name, value, minutes, domain) {
var cookieOptions = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
path: '/'
};
var expires;

@@ -51,7 +54,12 @@

date.setTime(date.getTime() + minutes * 60 * 1000);
expires = '; expires=' + date.toGMTString();
expires = '; expires=' + date.toUTCString();
} else expires = '';
domain = domain ? 'domain=' + domain + ';' : '';
document.cookie = name + '=' + value + expires + ';' + domain + 'path=/';
cookieOptions = Object.keys(cookieOptions).reduce(function (acc, key) {
return acc + ';' + key.replace(/([A-Z])/g, function ($1) {
return '-' + $1.toLowerCase();
}) + '=' + cookieOptions[key];
}, '');
document.cookie = name + '=' + encodeURIComponent(value) + expires + ';' + domain + cookieOptions;
},

@@ -58,0 +66,0 @@ read: function read(name) {

@@ -1,1 +0,1 @@

!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?module.exports=o():"function"==typeof define&&define.amd?define(o):(e=e||self).i18nextBrowserLanguageDetector=o()}(this,(function(){"use strict";function e(e,o){for(var t=0;t<o.length;t++){var n=o[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}var o=[],t=o.forEach,n=o.slice;function a(e){return t.call(n.call(arguments,1),(function(o){if(o)for(var t in o)void 0===e[t]&&(e[t]=o[t])})),e}var i,r=function(e,o,t,n){var a;if(t){var i=new Date;i.setTime(i.getTime()+60*t*1e3),a="; expires="+i.toGMTString()}else a="";n=n?"domain="+n+";":"",document.cookie=e+"="+o+a+";"+n+"path=/"},u=function(e){for(var o=e+"=",t=document.cookie.split(";"),n=0;n<t.length;n++){for(var a=t[n];" "===a.charAt(0);)a=a.substring(1,a.length);if(0===a.indexOf(o))return a.substring(o.length,a.length)}return null},c={name:"cookie",lookup:function(e){var o;if(e.lookupCookie&&"undefined"!=typeof document){var t=u(e.lookupCookie);t&&(o=t)}return o},cacheUserLanguage:function(e,o){o.lookupCookie&&"undefined"!=typeof document&&r(o.lookupCookie,e,o.cookieMinutes,o.cookieDomain)}},l={name:"querystring",lookup:function(e){var o;if("undefined"!=typeof window)for(var t=window.location.search.substring(1).split("&"),n=0;n<t.length;n++){var a=t[n].indexOf("=");if(a>0)t[n].substring(0,a)===e.lookupQuerystring&&(o=t[n].substring(a+1))}return o}};try{i="undefined"!==window&&null!==window.localStorage;window.localStorage.setItem("i18next.translate.boo","foo"),window.localStorage.removeItem("i18next.translate.boo")}catch(e){i=!1}var s={name:"localStorage",lookup:function(e){var o;if(e.lookupLocalStorage&&i){var t=window.localStorage.getItem(e.lookupLocalStorage);t&&(o=t)}return o},cacheUserLanguage:function(e,o){o.lookupLocalStorage&&i&&window.localStorage.setItem(o.lookupLocalStorage,e)}},f={name:"navigator",lookup:function(e){var o=[];if("undefined"!=typeof navigator){if(navigator.languages)for(var t=0;t<navigator.languages.length;t++)o.push(navigator.languages[t]);navigator.userLanguage&&o.push(navigator.userLanguage),navigator.language&&o.push(navigator.language)}return o.length>0?o:void 0}},d={name:"htmlTag",lookup:function(e){var o,t=e.htmlTag||("undefined"!=typeof document?document.documentElement:null);return t&&"function"==typeof t.getAttribute&&(o=t.getAttribute("lang")),o}},g={name:"path",lookup:function(e){var o;if("undefined"!=typeof window){var t=window.location.pathname.match(/\/([a-zA-Z-]*)/g);if(t instanceof Array)if("number"==typeof e.lookupFromPathIndex){if("string"!=typeof t[e.lookupFromPathIndex])return;o=t[e.lookupFromPathIndex].replace("/","")}else o=t[0].replace("/","")}return o}},p={name:"subdomain",lookup:function(e){var o;if("undefined"!=typeof window){var t=window.location.href.match(/(?:http[s]*\:\/\/)*(.*?)\.(?=[^\/]*\..{2,5})/gi);t instanceof Array&&(o="number"==typeof e.lookupFromSubdomainIndex?t[e.lookupFromSubdomainIndex].replace("http://","").replace("https://","").replace(".",""):t[0].replace("http://","").replace("https://","").replace(".",""))}return o}};var h=function(){function o(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};!function(e,o){if(!(e instanceof o))throw new TypeError("Cannot call a class as a function")}(this,o),this.type="languageDetector",this.detectors={},this.init(e,t)}var t,n,i;return t=o,(n=[{key:"init",value:function(e){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.services=e,this.options=a(o,this.options||{},{order:["querystring","cookie","localStorage","navigator","htmlTag"],lookupQuerystring:"lng",lookupCookie:"i18next",lookupLocalStorage:"i18nextLng",caches:["localStorage"],excludeCacheFor:["cimode"],checkWhitelist:!0}),this.options.lookupFromUrlIndex&&(this.options.lookupFromPathIndex=this.options.lookupFromUrlIndex),this.i18nOptions=t,this.addDetector(c),this.addDetector(l),this.addDetector(s),this.addDetector(f),this.addDetector(d),this.addDetector(g),this.addDetector(p)}},{key:"addDetector",value:function(e){this.detectors[e.name]=e}},{key:"detect",value:function(e){var o=this;e||(e=this.options.order);var t,n=[];if(e.forEach((function(e){if(o.detectors[e]){var t=o.detectors[e].lookup(o.options);t&&"string"==typeof t&&(t=[t]),t&&(n=n.concat(t))}})),n.forEach((function(e){if(!t){var n=o.services.languageUtils.formatLanguageCode(e);o.options.checkWhitelist&&!o.services.languageUtils.isWhitelisted(n)||(t=n)}})),!t){var a=this.i18nOptions.fallbackLng;"string"==typeof a&&(a=[a]),a||(a=[]),t="[object Array]"===Object.prototype.toString.apply(a)?a[0]:a[0]||a.default&&a.default[0]}return t}},{key:"cacheUserLanguage",value:function(e,o){var t=this;o||(o=this.options.caches),o&&(this.options.excludeCacheFor&&this.options.excludeCacheFor.indexOf(e)>-1||o.forEach((function(o){t.detectors[o]&&t.detectors[o].cacheUserLanguage(e,t.options)})))}}])&&e(t.prototype,n),i&&e(t,i),o}();return h.type="languageDetector",h}));
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?module.exports=o():"function"==typeof define&&define.amd?define(o):(e=e||self).i18nextBrowserLanguageDetector=o()}(this,(function(){"use strict";function e(e,o){for(var t=0;t<o.length;t++){var n=o[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}var o=[],t=o.forEach,n=o.slice;function a(e){return t.call(n.call(arguments,1),(function(o){if(o)for(var t in o)void 0===e[t]&&(e[t]=o[t])})),e}var i,r=function(e,o,t,n){var a,i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{path:"/"};if(t){var r=new Date;r.setTime(r.getTime()+60*t*1e3),a="; expires="+r.toUTCString()}else a="";n=n?"domain="+n+";":"",i=Object.keys(i).reduce((function(e,o){return e+";"+o.replace(/([A-Z])/g,(function(e){return"-"+e.toLowerCase()}))+"="+i[o]}),""),document.cookie=e+"="+encodeURIComponent(o)+a+";"+n+i},u=function(e){for(var o=e+"=",t=document.cookie.split(";"),n=0;n<t.length;n++){for(var a=t[n];" "===a.charAt(0);)a=a.substring(1,a.length);if(0===a.indexOf(o))return a.substring(o.length,a.length)}return null},c={name:"cookie",lookup:function(e){var o;if(e.lookupCookie&&"undefined"!=typeof document){var t=u(e.lookupCookie);t&&(o=t)}return o},cacheUserLanguage:function(e,o){o.lookupCookie&&"undefined"!=typeof document&&r(o.lookupCookie,e,o.cookieMinutes,o.cookieDomain)}},l={name:"querystring",lookup:function(e){var o;if("undefined"!=typeof window)for(var t=window.location.search.substring(1).split("&"),n=0;n<t.length;n++){var a=t[n].indexOf("=");if(a>0)t[n].substring(0,a)===e.lookupQuerystring&&(o=t[n].substring(a+1))}return o}};try{i="undefined"!==window&&null!==window.localStorage;window.localStorage.setItem("i18next.translate.boo","foo"),window.localStorage.removeItem("i18next.translate.boo")}catch(e){i=!1}var s={name:"localStorage",lookup:function(e){var o;if(e.lookupLocalStorage&&i){var t=window.localStorage.getItem(e.lookupLocalStorage);t&&(o=t)}return o},cacheUserLanguage:function(e,o){o.lookupLocalStorage&&i&&window.localStorage.setItem(o.lookupLocalStorage,e)}},f={name:"navigator",lookup:function(e){var o=[];if("undefined"!=typeof navigator){if(navigator.languages)for(var t=0;t<navigator.languages.length;t++)o.push(navigator.languages[t]);navigator.userLanguage&&o.push(navigator.userLanguage),navigator.language&&o.push(navigator.language)}return o.length>0?o:void 0}},d={name:"htmlTag",lookup:function(e){var o,t=e.htmlTag||("undefined"!=typeof document?document.documentElement:null);return t&&"function"==typeof t.getAttribute&&(o=t.getAttribute("lang")),o}},g={name:"path",lookup:function(e){var o;if("undefined"!=typeof window){var t=window.location.pathname.match(/\/([a-zA-Z-]*)/g);if(t instanceof Array)if("number"==typeof e.lookupFromPathIndex){if("string"!=typeof t[e.lookupFromPathIndex])return;o=t[e.lookupFromPathIndex].replace("/","")}else o=t[0].replace("/","")}return o}},p={name:"subdomain",lookup:function(e){var o;if("undefined"!=typeof window){var t=window.location.href.match(/(?:http[s]*\:\/\/)*(.*?)\.(?=[^\/]*\..{2,5})/gi);t instanceof Array&&(o="number"==typeof e.lookupFromSubdomainIndex?t[e.lookupFromSubdomainIndex].replace("http://","").replace("https://","").replace(".",""):t[0].replace("http://","").replace("https://","").replace(".",""))}return o}};var h=function(){function o(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};!function(e,o){if(!(e instanceof o))throw new TypeError("Cannot call a class as a function")}(this,o),this.type="languageDetector",this.detectors={},this.init(e,t)}var t,n,i;return t=o,(n=[{key:"init",value:function(e){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.services=e,this.options=a(o,this.options||{},{order:["querystring","cookie","localStorage","navigator","htmlTag"],lookupQuerystring:"lng",lookupCookie:"i18next",lookupLocalStorage:"i18nextLng",caches:["localStorage"],excludeCacheFor:["cimode"],checkWhitelist:!0}),this.options.lookupFromUrlIndex&&(this.options.lookupFromPathIndex=this.options.lookupFromUrlIndex),this.i18nOptions=t,this.addDetector(c),this.addDetector(l),this.addDetector(s),this.addDetector(f),this.addDetector(d),this.addDetector(g),this.addDetector(p)}},{key:"addDetector",value:function(e){this.detectors[e.name]=e}},{key:"detect",value:function(e){var o=this;e||(e=this.options.order);var t,n=[];if(e.forEach((function(e){if(o.detectors[e]){var t=o.detectors[e].lookup(o.options);t&&"string"==typeof t&&(t=[t]),t&&(n=n.concat(t))}})),n.forEach((function(e){if(!t){var n=o.services.languageUtils.formatLanguageCode(e);o.options.checkWhitelist&&!o.services.languageUtils.isWhitelisted(n)||(t=n)}})),!t){var a=this.i18nOptions.fallbackLng;"string"==typeof a&&(a=[a]),a||(a=[]),t="[object Array]"===Object.prototype.toString.apply(a)?a[0]:a[0]||a.default&&a.default[0]}return t}},{key:"cacheUserLanguage",value:function(e,o){var t=this;o||(o=this.options.caches),o&&(this.options.excludeCacheFor&&this.options.excludeCacheFor.indexOf(e)>-1||o.forEach((function(o){t.detectors[o]&&t.detectors[o].cacheUserLanguage(e,t.options)})))}}])&&e(t.prototype,n),i&&e(t,i),o}();return h.type="languageDetector",h}));
{
"name": "i18next-browser-languagedetector",
"version": "4.0.2",
"version": "4.1.0",
"description": "language detector used in browser environment for i18next",

@@ -5,0 +5,0 @@ "main": "./dist/cjs/i18nextBrowserLanguageDetector.js",

@@ -71,2 +71,4 @@ # Introduction

checkWhitelist: true
// optional set cookie options, reference:[MDN Set-Cookie docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie)
cookieOptions: {path:'/'}
}

@@ -73,0 +75,0 @@ ```

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc