Skip to content

Commit 8e6a1b8

Browse files
committed
Prepare release
1 parent 1c03d05 commit 8e6a1b8

File tree

11 files changed

+177
-101
lines changed

11 files changed

+177
-101
lines changed

.jshintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
"node": true,
55
"loopfunc": true,
66
"expr": true,
7-
"esversion": 6
7+
"esversion": 11
88
}

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ geocoder.init(
7676
);
7777
```
7878

79-
Optionally `init()` allows you to specify the directory that geonames files are
79+
Optionally `init()` allows you to specify the directory that GeoNames files are
8080
downloaded and cached in, and a specific cities database to be used.
8181

8282
```javascript
@@ -330,9 +330,9 @@ of disk space). All follow-up requests are lightning fast.
330330
### Downloading specific sets of countries
331331

332332
To reduce the time taken to initialize the data, you can manually configure it
333-
to only download a specific set of countries from Geonames. Do note that when
333+
to only download a specific set of countries from GeoNames. Do note that when
334334
you add a country code into the array, it will disable the geocoder from
335-
downloading all ~2GB(!) worth of data and only load the specified countries'
335+
downloading all ~2.29GB(!) worth of data and only load the specified countries'
336336
data. If you want to re-enable the geocoder to download all data, the countries
337337
array needs to be empty.
338338

@@ -359,10 +359,10 @@ geocoder.init(
359359

360360
### Post-install script
361361

362-
There's also the option of downloading the Geonames files via a post-install
363-
script.
362+
There's also the option of downloading the GeoNames files via a post-install
363+
script.
364364
The script is invoked automatically after installation, but won't download any
365-
files without getting at least one of the init options in an env variable.
365+
files without getting at least one of the init options in an env variable.
366366
The options should be specified with a `GEOCODER_POSTINSTALL_` prefix.
367367

368368
#### Example of downloading the files via the post-install script
@@ -417,8 +417,8 @@ specific language governing permissions and limitations under the License.
417417
## Acknowledgements
418418

419419
This project was inspired by Richard Penman's Python
420-
[reverse geocoder](https://github.com/richardpenman/reverse_geocode/). It
421-
uses Ubilabs'
420+
[reverse geocoder](https://github.com/richardpenman/reverse_geocode/). It uses
421+
Ubilabs'
422422
[k-d-tree implementation](https://github.com/ubilabs/kd-tree-javascript) that
423423
was ported to Node.js by [Luke Arduini](https://github.com/luk-/node-kdt).
424424

app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ app.listen(port, function () {
5555
console.log('Local reverse geocoder listening on port ' + port);
5656
console.log('Initializing Geocoder…');
5757
console.log(
58-
'(This may take a long time and will download ~300MB worth of data.)'
58+
'(This may take a long time and will download ~2.29GB worth of data by default.)'
5959
);
6060
geocoder.init(
6161
{

app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ app.listen(port, function () {
6767
console.log('Local reverse geocoder listening on port ' + port);
6868
console.log('Initializing Geocoder…');
6969
console.log(
70-
'(This may take a long time and will download ~300MB worth of data.)'
70+
'(This may take a long time and will download ~2.29GB worth of data by default.)'
7171
);
7272

7373
geocoder.init(

docs/global.html

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ <h5>Parameters:</h5>
169169

170170

171171

172-
<td class="description last">One single or an array of latitude/longitude pairs</td>
172+
<td class="description last">One single or an array of
173+
latitude/longitude pairs</td>
173174
</tr>
174175

175176

@@ -296,7 +297,20 @@ <h5>Returns:</h5>
296297

297298
<h5>Example</h5>
298299

299-
<pre class="prettyprint"><code>// With just one pointvar point = {latitude: 42.083333, longitude: 3.1};geocoder.lookUp(point, 1, function(err, res) { console.log(JSON.stringify(res, null, 2));});// In batch mode with many pointsvar points = [ {latitude: 42.083333, longitude: 3.1}, {latitude: 48.466667, longitude: 9.133333}];geocoder.lookUp(points, 1, function(err, res) { console.log(JSON.stringify(res, null, 2));});</code></pre>
300+
<pre class="prettyprint"><code>// With just one point
301+
var point = {latitude: 42.083333, longitude: 3.1};
302+
geocoder.lookUp(point, 1, function(err, res) {
303+
console.log(JSON.stringify(res, null, 2));
304+
});
305+
306+
// In batch mode with many points
307+
var points = [
308+
{latitude: 42.083333, longitude: 3.1},
309+
{latitude: 48.466667, longitude: 9.133333}
310+
];
311+
geocoder.lookUp(points, 1, function(err, res) {
312+
console.log(JSON.stringify(res, null, 2));
313+
});</code></pre>
300314

301315

302316

@@ -320,7 +334,7 @@ <h2><a href="index.html">Home</a></h2><h3><a href="global.html">Global</a></h3>
320334
<br class="clear">
321335

322336
<footer>
323-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Sun Jun 11 2023 00:39:00 GMT+0700 (Western Indonesia Time)
337+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.0</a> on Mon Jun 12 2023 11:07:01 GMT+0200 (Central European Summer Time)
324338
</footer>
325339

326340
<script> prettyPrint(); </script>

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ <h2><a href="index.html">Home</a></h2><h3><a href="global.html">Global</a></h3>
5656
<br class="clear">
5757

5858
<footer>
59-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Sun Jun 11 2023 00:39:00 GMT+0700 (Western Indonesia Time)
59+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.0</a> on Mon Jun 12 2023 11:07:01 GMT+0200 (Central European Summer Time)
6060
</footer>
6161

6262
<script> prettyPrint(); </script>

docs/index.js.html

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,16 @@ <h1 class="page-title">Source: index.js</h1>
5959

6060
var debug = require('debug')('local-reverse-geocoder');
6161
var fs = require('fs');
62-
var path = require('path');
6362
var parser = require('csv-parse');
6463
var parse = parser.parse;
6564
var kdTree = require('kdt');
66-
var fetch = (...args) =>
67-
import('node-fetch').then(({ default: fetch }) => fetch(...args));
6865
var unzip = require('unzip-stream');
6966
var async = require('async');
7067
var readline = require('readline');
7168
const { basename } = require('path');
69+
// mod.cjs
70+
const fetch = (...args) =>
71+
import('node-fetch').then(({ default: fetch }) => fetch(...args));
7272

7373
// All data from http://download.geonames.org/export/dump/
7474
var GEONAMES_URL = 'https://download.geonames.org/export/dump/';
@@ -169,7 +169,7 @@ <h1 class="page-title">Source: index.js</h1>
169169
downloadMethodBoundToThis,
170170
callback
171171
) {
172-
const now = new Date().toISOString().substr(0, 10);
172+
const now = new Date().toISOString().substring(0, 10);
173173

174174
// Use timestamped file OR bare file
175175
const timestampedBasename = `${baseName}_${now}.txt`;
@@ -222,7 +222,7 @@ <h1 class="page-title">Source: index.js</h1>
222222
.then((response) => {
223223
if (!response.ok) {
224224
throw new Error(
225-
`Error downloading GeoNames ${dataName} data (response ${response.status} for url ${geonamesUrl})`
225+
`Error downloading GeoNames ${dataName} data (response ${response.status} for URL ${geonamesUrl})`
226226
);
227227
}
228228

@@ -270,7 +270,7 @@ <h1 class="page-title">Source: index.js</h1>
270270
.then((response) => {
271271
if (!response.ok) {
272272
throw new Error(
273-
`Error downloading GeoNames ${dataName} data (response ${response.status} for url ${geonamesUrl})`
273+
`Error downloading GeoNames ${dataName} data (response ${response.status} for URL ${geonamesUrl})`
274274
);
275275
}
276276

@@ -285,7 +285,7 @@ <h1 class="page-title">Source: index.js</h1>
285285
.on('entry', (entry) => {
286286
var entryPath = entry.path;
287287
var entryType = entry.type; // 'Directory' or 'File'
288-
var entrySize = entry.size; // might be undefined in some archives
288+
var entrySize = entry.size; // Might be undefined in some archives
289289
if (entryType === 'File' &amp;&amp; entryPath === fileNameInsideZip) {
290290
debug(
291291
`Unzipping GeoNames ${dataName} data - found ${entryType} ${entryPath}` +
@@ -311,13 +311,12 @@ <h1 class="page-title">Source: index.js</h1>
311311
}
312312
})
313313
.on('finish', () => {
314-
// beware - this event is a finish of unzip, finish event of writeStream may and will happen later ...
314+
// Beware - this event is a finish of unzip, finish event of writeStream may and will happen later...
315315
if (foundFiles === 1) {
316-
// ... so if we found one file, we call callback in it's finish event above
316+
// ...so if we found one file, we call callback in it's finish event above
317317
debug(`Unzipped GeoNames ${dataName} data.`);
318-
// return callback(null, outputFilePath);
319318
} else {
320-
// .. while if there is something unexpected, we fire callback here
319+
// ...while if there is something unexpected, we fire callback here
321320
debug(
322321
`Error unzipping ${geonamesZipFilename}: Was expecting ${outputFileName}, found ${foundFiles} file(s).`
323322
);
@@ -989,7 +988,7 @@ <h2><a href="index.html">Home</a></h2><h3><a href="global.html">Global</a></h3>
989988
<br class="clear">
990989

991990
<footer>
992-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Sun Jun 11 2023 00:39:00 GMT+0700 (Western Indonesia Time)
991+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.0</a> on Mon Jun 12 2023 11:07:01 GMT+0200 (Central European Summer Time)
993992
</footer>
994993

995994
<script> prettyPrint(); </script>

index.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,16 @@
3131

3232
var debug = require('debug')('local-reverse-geocoder');
3333
var fs = require('fs');
34-
var path = require('path');
3534
var parser = require('csv-parse');
3635
var parse = parser.parse;
3736
var kdTree = require('kdt');
38-
var fetch = require('node-fetch');
3937
var unzip = require('unzip-stream');
4038
var async = require('async');
4139
var readline = require('readline');
4240
const { basename } = require('path');
41+
// mod.cjs
42+
const fetch = (...args) =>
43+
import('node-fetch').then(({ default: fetch }) => fetch(...args));
4344

4445
// All data from http://download.geonames.org/export/dump/
4546
var GEONAMES_URL = 'https://download.geonames.org/export/dump/';
@@ -140,7 +141,7 @@ var geocoder = {
140141
downloadMethodBoundToThis,
141142
callback
142143
) {
143-
const now = new Date().toISOString().substr(0, 10);
144+
const now = new Date().toISOString().substring(0, 10);
144145

145146
// Use timestamped file OR bare file
146147
const timestampedBasename = `${baseName}_${now}.txt`;
@@ -193,7 +194,7 @@ var geocoder = {
193194
.then((response) => {
194195
if (!response.ok) {
195196
throw new Error(
196-
`Error downloading GeoNames ${dataName} data (response ${response.status} for url ${geonamesUrl})`
197+
`Error downloading GeoNames ${dataName} data (response ${response.status} for URL ${geonamesUrl})`
197198
);
198199
}
199200

@@ -241,7 +242,7 @@ var geocoder = {
241242
.then((response) => {
242243
if (!response.ok) {
243244
throw new Error(
244-
`Error downloading GeoNames ${dataName} data (response ${response.status} for url ${geonamesUrl})`
245+
`Error downloading GeoNames ${dataName} data (response ${response.status} for URL ${geonamesUrl})`
245246
);
246247
}
247248

@@ -256,7 +257,7 @@ var geocoder = {
256257
.on('entry', (entry) => {
257258
var entryPath = entry.path;
258259
var entryType = entry.type; // 'Directory' or 'File'
259-
var entrySize = entry.size; // might be undefined in some archives
260+
var entrySize = entry.size; // Might be undefined in some archives
260261
if (entryType === 'File' && entryPath === fileNameInsideZip) {
261262
debug(
262263
`Unzipping GeoNames ${dataName} data - found ${entryType} ${entryPath}` +
@@ -282,13 +283,12 @@ var geocoder = {
282283
}
283284
})
284285
.on('finish', () => {
285-
// beware - this event is a finish of unzip, finish event of writeStream may and will happen later ...
286+
// Beware - this event is a finish of unzip, finish event of writeStream may and will happen later...
286287
if (foundFiles === 1) {
287-
// ... so if we found one file, we call callback in it's finish event above
288+
// ...so if we found one file, we call callback in it's finish event above
288289
debug(`Unzipped GeoNames ${dataName} data.`);
289-
// return callback(null, outputFilePath);
290290
} else {
291-
// .. while if there is something unexpected, we fire callback here
291+
// ...while if there is something unexpected, we fire callback here
292292
debug(
293293
`Error unzipping ${geonamesZipFilename}: Was expecting ${outputFileName}, found ${foundFiles} file(s).`
294294
);

0 commit comments

Comments
 (0)