UNPKG

req-country

Version:

Given a request, get the country code. ISO 3166-1 alpha-2 compliant.

58 lines (38 loc) 2 kB
# req-country ![Last version](https://img.shields.io/github/tag/Kikobeats/req-country.svg?style=flat-square) [![NPM Status](https://img.shields.io/npm/dm/req-country.svg?style=flat-square)](https://www.npmjs.org/package/req-country) > Given a request, get the country associated with it. ISO 3166-1 alpha-2 compliant. ## Install ```bash $ npm install req-country --save ``` ## Usage ```js const requestCountry = require('req-country') module.exports = (req, res) => { const country = requestCountry(req) console.log({ country }) // => { country: 'ES' } } ``` You can combine it with [`is-european`](https://github.com/Kikobeats/is-european) and [`country-vat`](https://github.com/Kikobeats/country-vat): ```js const { eeaMember, euMember } = require('is-european') const requestCountry = require('req-country') const countryVat = require('country-vat') module.exports = (req, res) => { const country = requestCountry(req) console.log({ eeaMember: eeaMember(country), euMember: euMember(country) }) // => { eeaMember: true, euMember: true } console.log(countryVat(country)) // => 0.21 } ``` ## Related - [is-european](https://github.com/Kikobeats/is-european) – Check if a country is part of the EU (European Union) or EEA (European Economic Area). ISO 3166-1 compliant. - [country-vat](https://github.com/Kikobeats/country-vat) – Given a request, get the country associated with it. ISO 3166-1 alpha-2 compliant. - [tom.js.org](https://tom.js.org) – tom 🐶 is a backoffice for your projects. ## License **req-country** © [Kiko Beats](https://kikobeats.com), released under the [MIT](https://github.com/Kikobeats/req-country/blob/master/LICENSE.md) License.<br> Authored and maintained by [Kiko Beats](https://kikobeats.com) with help from [contributors](https://github.com/Kikobeats/req-country/contributors). > [kikobeats.com](https://kikobeats.com) · GitHub [Kiko Beats](https://github.com/Kikobeats) · Twitter [@Kikobeats](https://twitter.com/Kikobeats)