Skip to content

Commit

Permalink
Prepare release
Browse files Browse the repository at this point in the history
  • Loading branch information
tomayac committed Jun 12, 2023
1 parent 1c03d05 commit 8e6a1b8
Show file tree
Hide file tree
Showing 11 changed files with 177 additions and 101 deletions.
2 changes: 1 addition & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"node": true,
"loopfunc": true,
"expr": true,
"esversion": 6
"esversion": 11
}
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ geocoder.init(
);
```

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

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

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

Expand All @@ -359,10 +359,10 @@ geocoder.init(

### Post-install script

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ app.listen(port, function () {
console.log('Local reverse geocoder listening on port ' + port);
console.log('Initializing Geocoder…');
console.log(
'(This may take a long time and will download ~300MB worth of data.)'
'(This may take a long time and will download ~2.29GB worth of data by default.)'
);
geocoder.init(
{
Expand Down
2 changes: 1 addition & 1 deletion app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ app.listen(port, function () {
console.log('Local reverse geocoder listening on port ' + port);
console.log('Initializing Geocoder…');
console.log(
'(This may take a long time and will download ~300MB worth of data.)'
'(This may take a long time and will download ~2.29GB worth of data by default.)'
);

geocoder.init(
Expand Down
20 changes: 17 additions & 3 deletions docs/global.html
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ <h5>Parameters:</h5>



<td class="description last">One single or an array of latitude/longitude pairs</td>
<td class="description last">One single or an array of
latitude/longitude pairs</td>
</tr>


Expand Down Expand Up @@ -296,7 +297,20 @@ <h5>Returns:</h5>

<h5>Example</h5>

<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>
<pre class="prettyprint"><code>// With just one point
var 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 points
var 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>



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

<footer>
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)
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)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ <h2><a href="index.html">Home</a></h2><h3><a href="global.html">Global</a></h3>
<br class="clear">

<footer>
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)
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)
</footer>

<script> prettyPrint(); </script>
Expand Down
23 changes: 11 additions & 12 deletions docs/index.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ <h1 class="page-title">Source: index.js</h1>

var debug = require('debug')('local-reverse-geocoder');
var fs = require('fs');
var path = require('path');
var parser = require('csv-parse');
var parse = parser.parse;
var kdTree = require('kdt');
var fetch = (...args) =>
import('node-fetch').then(({ default: fetch }) => fetch(...args));
var unzip = require('unzip-stream');
var async = require('async');
var readline = require('readline');
const { basename } = require('path');
// mod.cjs
const fetch = (...args) =>
import('node-fetch').then(({ default: fetch }) => fetch(...args));

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

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

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

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

<footer>
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)
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)
</footer>

<script> prettyPrint(); </script>
Expand Down
20 changes: 10 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@

var debug = require('debug')('local-reverse-geocoder');
var fs = require('fs');
var path = require('path');
var parser = require('csv-parse');
var parse = parser.parse;
var kdTree = require('kdt');
var fetch = require('node-fetch');
var unzip = require('unzip-stream');
var async = require('async');
var readline = require('readline');
const { basename } = require('path');
// mod.cjs
const fetch = (...args) =>
import('node-fetch').then(({ default: fetch }) => fetch(...args));

// All data from http://download.geonames.org/export/dump/
var GEONAMES_URL = 'https://download.geonames.org/export/dump/';
Expand Down Expand Up @@ -140,7 +141,7 @@ var geocoder = {
downloadMethodBoundToThis,
callback
) {
const now = new Date().toISOString().substr(0, 10);
const now = new Date().toISOString().substring(0, 10);

// Use timestamped file OR bare file
const timestampedBasename = `${baseName}_${now}.txt`;
Expand Down Expand Up @@ -193,7 +194,7 @@ var geocoder = {
.then((response) => {
if (!response.ok) {
throw new Error(
`Error downloading GeoNames ${dataName} data (response ${response.status} for url ${geonamesUrl})`
`Error downloading GeoNames ${dataName} data (response ${response.status} for URL ${geonamesUrl})`
);
}

Expand Down Expand Up @@ -241,7 +242,7 @@ var geocoder = {
.then((response) => {
if (!response.ok) {
throw new Error(
`Error downloading GeoNames ${dataName} data (response ${response.status} for url ${geonamesUrl})`
`Error downloading GeoNames ${dataName} data (response ${response.status} for URL ${geonamesUrl})`
);
}

Expand All @@ -256,7 +257,7 @@ var geocoder = {
.on('entry', (entry) => {
var entryPath = entry.path;
var entryType = entry.type; // 'Directory' or 'File'
var entrySize = entry.size; // might be undefined in some archives
var entrySize = entry.size; // Might be undefined in some archives
if (entryType === 'File' && entryPath === fileNameInsideZip) {
debug(
`Unzipping GeoNames ${dataName} data - found ${entryType} ${entryPath}` +
Expand All @@ -282,13 +283,12 @@ var geocoder = {
}
})
.on('finish', () => {
// beware - this event is a finish of unzip, finish event of writeStream may and will happen later ...
// Beware - this event is a finish of unzip, finish event of writeStream may and will happen later...
if (foundFiles === 1) {
// ... so if we found one file, we call callback in it's finish event above
// ...so if we found one file, we call callback in it's finish event above
debug(`Unzipped GeoNames ${dataName} data.`);
// return callback(null, outputFilePath);
} else {
// .. while if there is something unexpected, we fire callback here
// ...while if there is something unexpected, we fire callback here
debug(
`Error unzipping ${geonamesZipFilename}: Was expecting ${outputFileName}, found ${foundFiles} file(s).`
);
Expand Down
Loading

0 comments on commit 8e6a1b8

Please sign in to comment.