# express-langs

> resolve accept langagues from header for you request

Latest version **0.4.0** (published 2019-12-29) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install express-langs
pnpm add express-langs
yarn add express-langs
bun add express-langs
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2019-12-29 |
| First published | 2019-11-20 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 278.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | S.Gaborieau |
| Maintainers | orivoir21 |
| Keywords | express, langs, lang, parse, request, langagues, middleware, header, use |

## Links

- npm: https://www.npmjs.com/package/express-langs
- Repository: https://github.com/Orivoir/express-langs
- Homepage: https://https://github.com/Orivoir/express-live-reloading
- Issues: https://github.com/Orivoir/express-langs/issues
- npm.io page: https://npm.io/package/express-langs

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.4.0 (latest) — 2019-12-29
- 0.3.6 — 2019-12-28
- 0.3.5 — 2019-12-27
- 0.3.0 — 2019-12-27
- 0.2.63 — 2019-12-27
- 0.2.62 — 2019-12-27
- 0.2.61 — 2019-12-26
- 0.2.6 — 2019-12-26
- 0.2.51 — 2019-12-26
- 0.2.5 — 2019-12-26
- 0.2.1 — 2019-12-26
- 0.2.0 — 2019-12-26
- 0.1.82 — 2019-12-26
- 0.1.81 — 2019-12-26
- 0.1.8 — 2019-12-26
- … 6 more at https://npm.io/package/express-langs/versions

## README

# [express-langs](https://www.npmjs.com/package/express-langs)

[![npm](https://img.shields.io/npm/l/express-langs.svg?style=for-the-badge)](https://www.npmjs.com/package/express-langs)
[![npm version](https://img.shields.io/npm/v/express-langs.svg?style=for-the-badge)](https://www.npmjs.com/package/express-langs)


[![build travis](https://travis-ci.com/Orivoir/express-langs.svg?branch=master)](https://travis-ci.com/Orivoir/express-langs)
[![codecov](https://codecov.io/gh/Orivoir/express-langs/branch/master/graph/badge.svg)](https://codecov.io/gh/Orivoir/express-langs)


## parse langs from `request` for easier use with *express*

![screen shot demo](./screen-demo.png)

> resolve langagues **accept** in header `request` get `array` langagues with `request.langs`

### Installation

```npm install express-langs --save```

```yarn add express-langs```

server.js

```javascript
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.items );

        res.send( 'hello world !' ) ;

    } )
;

server.listen( 80 , () => console.log('server run ...') ) ;

```

## you can use `methods` *test* `exists langs`

```javascript
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 relative test with langs found *e.g* :

```javascript
langs.exists('en') ; // match with 'en-US'
langs.exists('en') ; // match with 'en'
langs.exists('en') ; // not match with 'fr'
```

## or with an **pattern** *e.g* :


```javascript
langs.exists( /en/i ) ; // match with 'en-US'
langs.exists( /en/i ) ; // match with 'en'

langs.exists( /en|fr/i ) ; // match with 'fr'
```

## you can make a `strict test exists` *e.g* :

```javascript
langs.existsStrict('en') ; // not match with 'en-US'
langs.existsStrict('en') ; // match with 'en'
langs.existsStrict('en') ; // not match with 'fr'
```

## `getWith` method get array langs match with you support `pattern`

```javascript
const supportLangs = langs.getWith( /en|fr|es/i ) ; // array[ langs ]

// you can give an string for build an pattern e.g :
const pattern = "en|fr|es" ;
const supportLangs = langs.getWith( pattern ) ; // array[ langs ]
```

#### develop by [Samuel Gaborieau]( https://orivoir.github.io/profil-reactjs/ ) with <3 and NodeJS for *Open Source* and *enjoy* !

---
_Source: https://npm.io/package/express-langs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
