-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
13 changed files
with
1,952 additions
and
1,555 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 |
---|---|---|
@@ -1,2 +1,6 @@ | ||
/node_modules/ | ||
coverage/ | ||
/nominatim.browser.js | ||
/nominatim.module.mjs | ||
/nominatim.node.js | ||
*.map |
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 |
---|---|---|
|
@@ -6,3 +6,5 @@ coverage | |
.gitlab-ci.yml | ||
.eslintrc.js | ||
*.tgz | ||
lib | ||
rollup.config.js |
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
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
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,7 @@ | ||
module.exports = async function query(host, path, { headers, ...params }) { | ||
const response = await fetch(host + path, { headers }); | ||
|
||
return params.format === 'json' | ||
? await response.json() | ||
: await response.text(); | ||
}; |
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,26 @@ | ||
const https = require('https'); | ||
|
||
module.exports = function fetch(host, path, { headers, ...params }) { | ||
return new Promise((resolve, reject) => { | ||
https.get({ host, path, headers }, (res) => { | ||
let data = ''; | ||
|
||
res.setEncoding('utf8'); | ||
res.on('error', reject); | ||
|
||
res.on('data', (chunk) => { | ||
data += chunk; | ||
}); | ||
|
||
res.on('end', () => { | ||
try { | ||
data = params.format === 'json' ? JSON.parse(data) : data; | ||
|
||
resolve(data); | ||
} catch (err) { | ||
reject(err); | ||
} | ||
}); | ||
}).on('error', reject); | ||
}); | ||
}; |
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 @@ | ||
const nominatim = require('./nominatim'); | ||
const fetch = require('./fetch.browser'); | ||
|
||
module.exports = nominatim(fetch); |
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,38 @@ | ||
const API_ENDPOINT = 'nominatim.openstreetmap.org'; | ||
const defaultParams = { | ||
format: 'json', | ||
}; | ||
|
||
function encode(params) { | ||
const params_query = []; | ||
|
||
for (const key in params) { | ||
params_query.push(key + '=' + encodeURIComponent(params[key])); | ||
} | ||
|
||
return params_query.join('&'); | ||
}; | ||
|
||
module.exports = (query) => ({ | ||
createClient: ({ useragent, referer, ...options }) => { | ||
const headers = { | ||
'User-Agent': useragent, | ||
referer, | ||
}; | ||
|
||
return { | ||
search(params) { | ||
const queryParams = { ...defaultParams, ...options, ...params }; | ||
const search = encode(queryParams); | ||
|
||
return query(API_ENDPOINT, `/?${search}`, { ...queryParams, headers }); | ||
}, | ||
reverse(params) { | ||
const queryParams = { ...defaultParams, zoom: 18, ...options, ...params }; | ||
const search = encode(queryParams); | ||
|
||
return query(API_ENDPOINT, `/reverse?${search}`, { ...queryParams, headers }); | ||
}, | ||
}; | ||
}, | ||
}); |
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 @@ | ||
const nominatim = require('./nominatim'); | ||
const fetch = require('./fetch.node'); | ||
|
||
module.exports = nominatim(fetch); |
Oops, something went wrong.