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

express-guess-lang

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-guess-lang - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

37

express-guess-lang.js

@@ -10,31 +10,30 @@ var egl = exports

regions = [],
langs = [],
likely = { lang: 'en', likelihood: 0.0}
languages = [],
lookup = {},
likely = { name: 'en', likelihood: 0.0 }
if (typeof accept_lang === 'string') {
accept_lang = accept_lang.replace(/\s/g, '')
var candidates = accept_lang.split(',')
for (var i = 0; i < candidates.length; i++) {
var match = candidates[i].match(/q=([0-9].[0-9])/)
var likelihood = match ? match[1] : 0.0
match = candidates[i].match(/-([^;]*)/)
if (match)
regions.push(match[1])
match = candidates[i].match(/(.*)[;||-]/)
var lang = match ? match[1] : ''
var newLang = { lang: lang, likelihood: likelihood }
var matches = candidates[i].match(/([^-;]*)(?:-([^;]*))?(?:;q=([0-9]\.[0-9]))?/)
if (matches[2])
regions.push(matches[2])
var newLang = { name: matches[1], likelihood: matches[3] ? matches[3] : 1.0 }
languages.push(newLang)
lookup[newLang.name] = newLang.likelihood
if (newLang.likelihood > likely.likelihood)
likely = newLang
if (likelihood > 0.0)
langs.push(newLang)
}
request.getRegions = function () { return regions }
request.getLanguages = function () { return langs }
request.getLikelyLanguage = function () { return likely.lang }
}
else {
request.getRegions = function () { return [ defaultRegion ] }
request.getLanguages = function () { return [{ lang: defaultLang, likelihood: 0.0 }] }
request.getLikelyLanguage = function () { return defaultLang }
likely = { name: defaultLang, likelihood: 1.0 }
regions = [ defaultRegion ]
languages = [ likely ]
}
request.getRegions = function () { return regions }
request.getLanguages = function () { return languages }
request.getLikelyLanguage = function () { return likely.name }
request.isAppropriate = function (name) { return (typeof lookup[name] !== 'undefined') }
if (typeof next === 'function')

@@ -41,0 +40,0 @@ next()

{
"name": "express-guess-lang",
"version": "0.0.5",
"version": "0.0.6",
"description": "Provides the language accepted by the users browser in the request object",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -53,2 +53,3 @@ # express-guess-lang

var preferedLanguage = request.getLikelyLanguage()
var acceptable = request.isAppropriate('en')
})

@@ -73,2 +74,7 @@

Check if a language is appropriate for the user:
isAppropriate('en'): boolean
//Example: true
## Licensed under MIT

@@ -75,0 +81,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