Package Exports
- express-langs
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (express-langs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
express-langs
parse langs from request
for easier use with express
resolve langagues accept in header
request
getarray
langagues withrequest.langs
Installation
npm install express-langs --save
yarn add express-langs
server.js
const
exp = require('express')
,app =exp()
,server = require('http').Server( app )
,langs = require('express-langs')
;
app
// ... , you other middleware
.use( langs )
// you other middleware ... ,
;
app
.get('/' , (req,res) => {
/**
* array<object>
* {
* lang: string
* ,val: float
* }
*/
console.log( req.langs );
res.send( 'hello world !' ) ;
} )
;
server.listen( 80 , () => console.log('server run ...') ) ;
you can use methods
test exists langs
const
exp = require('express')
,app =exp()
,server = require('http').Server( app )
,langs = require('express-langs')
;
app
// ... , you other middleware
.use( langs )
// you other middleware ... ,
;
app
.get('/' , (req,res) => {
const langs = req.langs ;
if( langs.exists( 'fr' ) ) {
res.send( 'salut le monde !' ) ;
} else {
res.send('hello world') ;
}
} )
;
server.listen( 80 , () => console.log('server run ...') ) ;
exists
methods make a contains test with langs found e.g :
langs.exists('en') ; // match with 'en-US'
langs.exists('en') ; // match with 'en'
langs.exists('en') ; // not match with 'fr'
you can make a strict test exists
with:
langs.existsStrict('en') ; // not match with 'en-US'
langs.existsStrict('en') ; // match with 'en'
langs.existsStrict('en') ; // not match with 'fr'