
Security News
Open Source Maintainers Demand Ability to Block Copilot-Generated Issues and PRs
Open source maintainers are urging GitHub to let them block Copilot from submitting AI-generated issues and pull requests to their repositories.
navigator-languages
Advanced tools
Retrieves the language information saved in window.navigator.languages in a backwards compatible way.
Retrieves the language information saved in window.navigator.languages in a backwards compatible way.
npm i navigator-languages
const navigatorLanguages = require('navigator-languages');
console.log(navigatorLanguages());
/* CONSOLE:
["de-DE", "en-US", "nl"]
*/
If the browser is really old and there is no chance to get any information, you'll get undefined
.
There are probably many more issues like that.
(about 260 bytes)
var getNavigatorLanguages = function() {
if (typeof navigator === 'object') {
var t = 'anguage', n = navigator, f;
f = n['l' + t + 's'];
return f && f.length ? f : (t = n['l' + t] ||
n['browserL' + t] ||
n['userL' + t]) ? [ t ] : t;
}
};
Minified: (about 180 bytes)
var getNavigatorLanguages=function(){if('object'==typeof navigator){var c,a='anguage',b=navigator;return c=b['l'+a+'s'],c&&c.length?c:(a=b['l'+a]||b['browserL'+a]||b['userL'+a])?[a]:a}};
The umd module is about 370 bytes.
It checks for different entries in window.navigator
, in this order:
.languages
(if ! empty array).language
.browserLanguage
.userLanguage
.systemLanguage
is being ignored, because .userLanguage
is always available, when also .systemLanguage
is available and .userLanguage
is definitely the better choice.
v1.0.0 did also some lowercase/uppercase formatting & validating, which was removed in version 2, because it's normally not needed. Use the format-bcp-47 package, if you need to ensure client-side / server-side consistency
FAQs
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Open source maintainers are urging GitHub to let them block Copilot from submitting AI-generated issues and pull requests to their repositories.
Research
Security News
Malicious Koishi plugin silently exfiltrates messages with hex strings to a hardcoded QQ account, exposing secrets in chatbots across platforms.
Research
Security News
Malicious PyPI checkers validate stolen emails against TikTok and Instagram APIs, enabling targeted account attacks and dark web credential sales.