-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a74109c
commit 23bb7d1
Showing
10 changed files
with
37,263 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,4 @@ node_modules | |
.lock-wscript | ||
|
||
codes-postaux.json | ||
*.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
prepublish.js | ||
|
||
*.csv | ||
codes-postaux.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
French postal codes API for Node.js | ||
------ | ||
|
||
Based on the [official postal codes database](https://www.data.gouv.fr/fr/datasets/base-officielle-des-codes-postaux/) from [La Poste](http://www.laposte.fr/). | ||
|
||
## Usage | ||
```js | ||
var codesPostaux = require('codes-postaux'); | ||
|
||
codesPostaux.find(75001); | ||
codesPostaux.find('75001'); | ||
``` | ||
|
||
Will return | ||
```js | ||
[ { codeInsee: '75101', | ||
nomCommune: 'PARIS 01', | ||
codePostal: '75001', | ||
libelleAcheminement: 'PARIS' } ] | ||
``` |
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
var _ = require('lodash'); | ||
|
||
var data = require('./codes-postaux.json'); | ||
|
||
var index = _.groupBy(data, 'codePostal'); | ||
|
||
exports.find = function(postalCode) { | ||
return index[postalCode] || []; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,31 @@ | ||
{ | ||
"name": "codes-postaux", | ||
"version": "0.1.0", | ||
"description": "API Codes postaux France", | ||
"version": "1.0.0", | ||
"description": "French postal codes API for Node.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/sgmap/codes-postaux.git" | ||
}, | ||
"keywords": [ | ||
"france", | ||
"codes postaux" | ||
"codes postaux", | ||
"open data" | ||
], | ||
"author": "Jérôme Desboeufs <[email protected]>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/sgmap/codes-postaux/issues" | ||
}, | ||
"homepage": "https://github.com/sgmap/codes-postaux", | ||
"main": "api", | ||
"scripts": { | ||
"prepublish": "node prepublish.js", | ||
"postinstall": "node postinstall.js" | ||
}, | ||
"dependencies": { | ||
"lodash": "^2.4.1" | ||
"lodash": ">= 2.0 <4.0" | ||
}, | ||
"devDependencies": { | ||
"JSONStream": "^0.9.0", | ||
"csv-parse": "0.0.6", | ||
"request": "^2.48.0" | ||
"csv-parse": "0.0.6" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
var fs = require('fs'); | ||
var zlib = require('zlib'); | ||
|
||
var gzip = zlib.createGunzip(); | ||
|
||
var sourceFile = __dirname + '/codes-postaux.json.gz'; | ||
var destFile = __dirname + '/codes-postaux.json'; | ||
|
||
// Just inflate json file | ||
fs.createReadStream(sourceFile) | ||
.pipe(gzip) | ||
.pipe(fs.createWriteStream(destFile)) | ||
.on('finish', function () { | ||
console.log('Dataset has been successfully inflated'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
var fs = require('fs'); | ||
var zlib = require('zlib'); | ||
|
||
var csvParse = require('csv-parse'); | ||
var JSONStream = require('JSONStream'); | ||
|
||
var gzip = zlib.createGzip(); | ||
|
||
var sourceFile = __dirname + '/code_postaux_v201410.csv'; | ||
var destFile = __dirname + '/codes-postaux.json.gz'; | ||
|
||
// Override first line | ||
var cswColumns = function() { | ||
return ['codeInsee', 'nomCommune', 'codePostal', 'libelleAcheminement']; | ||
}; | ||
|
||
// Read source file | ||
fs.createReadStream(sourceFile) | ||
// Parse CSV as Object | ||
.pipe(csvParse({ delimiter: ';', trim: true, columns: cswColumns })) | ||
// Turn into JSON Array String | ||
.pipe(JSONStream.stringify()) | ||
// Deflate | ||
.pipe(gzip) | ||
// Write gzipped json file | ||
.pipe(fs.createWriteStream(destFile)) | ||
// Finished! | ||
.on('finish', function () { | ||
console.log('Dataset has been successfully converted and deflated'); | ||
}); |