-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
22 lines (16 loc) · 655 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
'use strict'
const epsg = require('epsg-index/all.json')
const proj4 = require('proj4')
const leadingEPSG = /^epsg:/i
const transform = (from, to) => {
if ('string' !== typeof from) throw new Error('from must be a string')
from = from.replace(leadingEPSG, '')
const fromEPSG = epsg[from]
if (!fromEPSG) throw new Error(from + ' is not a valid EPSG coordinate system')
if ('string' !== typeof to) throw new Error('to must be a string')
to = to.replace(leadingEPSG, '')
const toEPSG = epsg[to]
if (!toEPSG) throw new Error(to + ' is not a valid EPSG coordinate system')
return proj4(fromEPSG.proj4, toEPSG.proj4)
}
module.exports = transform