insee-municipality-code
Version:
🇫🇷 Get the INSEE municipality code from postal code and name of French municipality
70 lines (43 loc) • 2.89 kB
Markdown
[](https://github.com/facebook/jest) [](http://badge.fury.io/js/insee-municipality-code) [](https://circleci.com/gh/aymericbouzy/insee-municipality-code) [](https://codecov.io/gh/aymericbouzy/insee-municipality-code)
Simply provide the postal code and / or name of a French municipality and get the most likely INSEE municipality code
```sh
yarn add insee-municipality-code
```
or
```sh
npm i --save insee-municipality-code
```
```js
import InseeCode from "insee-municipality-code"
InseeCode.getCode({ postalCode: "14710", name: "Colombières" }) // "14168"
InseeCode.getCode({ name: "Collonbier", postalCode: "15710" }) // "14168"
InseeCode.getCode({ name: "Lyon" }) // "69381"
InseeCode.getMunicipality("14168") // { postalCode: "14710", name: "COLOMBIERES" }
InseeCode.getMunicipality("96501") // null
```
| Method | arguments | returned value | throws |
| ------ | --------- | -------------- | ------ |
| `getCode` | `params: { postalCode: string? \| number?, name: string? }` | `string`: the most likely Insee code regarding your input | will throw if both params are empty |
| `getMunicipality` | `string, params: { postalCode: string? \| number? }?` | `{ postalCode: string, name: string }?`: the corresponding city (if it exists).<sup>1</sup> | will throw if insee code is not well formated (`/(\d{2}|2[AB])\d{3}/i`) |
<sup>1</sup>The second argument is optional and used to help decide which postalCode to return when the city corresponding to the Insee code has many options. e.g. : `Saint-Maur-des-Fossés` has Insee code `94068` and postal codes `94100` and `94210`.
* fuse.js : [http://fusejs.io/](http://fusejs.io/)
This package loads in memory the name and postal code of 39k+ French towns. You should probably not try to send this package client side.
Please fork this package, and run
```sh
yarn install
yarn test
```
Something is not working as expected? Some result is wrong? Documentation is missing? You need a different feature / API? Please file an [issue](https://github.com/aymericbouzy/insee-municipality-code/issues/new), we'll be in touch.
(in French)
* [https://public.opendatasoft.com/explore/dataset/correspondance-code-insee-code-postal/](https://public.opendatasoft.com/explore/dataset/correspondance-code-insee-code-postal/)
Gofer 🤝 (the human-centric work-on-demand solution) is the main support of this package.