Skip to content

Commit

Permalink
Release v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jdesboeufs committed May 21, 2015
1 parent a74109c commit 23bb7d1
Show file tree
Hide file tree
Showing 10 changed files with 37,263 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ node_modules
.lock-wscript

codes-postaux.json
*.gz
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
prepublish.js

*.csv
codes-postaux.json
20 changes: 20 additions & 0 deletions README.md
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' } ]
```
8 changes: 0 additions & 8 deletions api.js

This file was deleted.

37,174 changes: 37,174 additions & 0 deletions code_postaux_v201410.csv

Large diffs are not rendered by default.

20 changes: 0 additions & 20 deletions import-data.js

This file was deleted.

9 changes: 9 additions & 0 deletions index.js
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] || [];
};
17 changes: 10 additions & 7 deletions package.json
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"
}
}
15 changes: 15 additions & 0 deletions postinstall.js
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');
});
30 changes: 30 additions & 0 deletions prepublish.js
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');
});

0 comments on commit 23bb7d1

Please sign in to comment.