-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (34 loc) · 794 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const data = require('./data.json');
function fromPRJ(prj) {
return get(prj, 'prj').epsg;
}
function fromEPSG(epsg) {
return get(epsg, 'epsg').prj;
}
function get(prj, type = 'prj') {
if (prj) {
if (typeof prj == 'object') {
if (prj.buffer && prj.buffer.byteLength) return (findBy(prj.toString(), type) || {});
else {
console.log('[prj2epsg] Invalid object');
return undefined;
}
}
else {
return (findBy(prj.toString(), type) || {});
}
}
else {
return {}
}
}
function findBy(prj, type) {
for (let i = 0; i < data.length; i++) {
if (data[i][type] == prj) return data[i];
}
}
module.exports = {
fromPRJ,
fromEPSG,
get
}