# gengojs-accept

> Express, Koa, and Hapi locale parser.

Latest version **1.0.0** (published 2015-11-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install gengojs-accept
pnpm add gengojs-accept
yarn add gengojs-accept
bun add gengojs-accept
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2015-11-09 |
| First published | 2015-02-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Known vulnerabilities | 0 (+7 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | iwatakeshi |
| Maintainers | iwatakeshi |
| Keywords | locale, i18n, accept-language, header, express, koa, feathers, hapi, international, accept-header, subdomain, domain |

## Links

- npm: https://www.npmjs.com/package/gengojs-accept
- Repository: https://github.com/gengojs/accept
- Issues: https://github.com/gengojs/accept/issues
- npm.io page: https://npm.io/package/gengojs-accept

## Dependencies (5)

- [babel](https://npm.io/package/babel.md) ^6.0.15
- [cookie](https://npm.io/package/cookie.md) ^0.2.0
- [lodash](https://npm.io/package/lodash.md) ^3.10.1
- [koa-convert](https://npm.io/package/koa-convert.md) ^1.1.0
- [babel-polyfill](https://npm.io/package/babel-polyfill.md) ^6.0.16

## Recent versions

- 1.0.0 (latest) — 2015-11-09
- 0.2.6 — 2015-09-27
- 0.2.5 — 2015-09-27
- 0.2.4 — 2015-09-27
- 0.2.3 — 2015-09-27
- 0.2.2 — 2015-09-25
- 0.2.1 — 2015-09-01
- 0.2.0 — 2015-08-30
- 0.1.0 — 2015-08-30
- 0.0.11 — 2015-08-23
- 0.0.10 — 2015-03-25
- 0.0.9 — 2015-03-18
- 0.0.8 — 2015-03-18
- 0.0.7 — 2015-03-03
- 0.0.6 — 2015-03-02
- … 5 more at https://npm.io/package/gengojs-accept/versions

## README

# gengojs-accept
Express, Koa, Hapi locale parser that powers [gengo.js](https://github.com/gengojs/gengojs).

[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/iwatakeshi/gengojs-accept?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

[![Build Status](https://travis-ci.org/gengojs/accept.svg)](https://travis-ci.org/gengojs/accept)
[![Dependency Status](https://david-dm.org/gengojs/accept.svg)](https://github.com/gengojs/accept/blob/master/package.json) 
[![License Status](http://img.shields.io/npm/l/gengojs-accept.svg)](https://github.com/iwatakeshi/gengojs-accept/blob/master/LICENSE) 
[![Downloads](http://img.shields.io/npm/dm/gengojs-accept.svg)](https://www.npmjs.com/package/gengojs-accept) [![Version](http://img.shields.io/npm/v/gengojs-accept.svg)](https://www.npmjs.com/package/gengojs-accept)

This module parses the accept-language header from Express, Koa, or Hapi and returns the appropriate locale.


## Documentation

See the beautifully generated documenation at [GitHub](http://gengojs.github.io/accept/index.html).

## Usage

```bash
$ npm i --save gengojs-accept
```

### Express

```javascript
import express from 'express';
import accept from 'gengojs-accept/express';

let app = express();

app.use(accept());

app.use('/', function(req, res, next){
	console.log(req.getLocale());
});

// ...
```

### Hapi

```javascript
import Hapi from 'hapi';
import accept from 'gengojs-accept/hapi';

let server = new Hapi.Server();
server.connection({
	port:3000
})
 
server.register(accept(), function(error){
 	if(error) console.log(error);
});

server.route({
    method: 'GET',
    path: '/',
    handler: function (request, reply) {
        console.log(request.accept.getLocale());
        reply();
    }
});

// ...
```

### Koa

Note: I have not tested Koa's v1.0.0 API but in theory it should work. Please report any bugs if encountered or create a pull request to add tests.

```javascript
import Koa from 'koa';
import accept from 'gengojs-accept/koa';

let app = new Koa();

app.use(accept());

app.use('/', function (self, next){
	console.log(self.accept.getLocale());
    // or
    console.log(self.request.accept.getLocale());
    // or
    console.log(self.response.accept.getLocale());
});

// ...
```

### Standalone

```javascript
import accept from 'gengojs-accept';

// pass the request object from express or hapi 
// or the 'ctx'/'self' context from koa;
let currentLocale = accept(req || ctx, options).getLocale();
```

## Options

```json
{
    "check": true,
    "default": "en-US",
    "supported": [
        "en-US"
    ],
    "keys": {
        "cookie": "locale",
        "query": "locale"
    },
    "detect": {
        "header": true,
        "cookie": false,
        "query": false,
        "url": false,
        "domain": false,
        "subdomain": false
    }
}  

```

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