Skip to content

Commit eaa2901

Browse files
feat(rename): Renamed to lonlat.
1 parent 78254ed commit eaa2901

File tree

4 files changed

+27
-36
lines changed

4 files changed

+27
-36
lines changed

.travis.yml

-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
sudo: false
22
language: node_js
3-
cache:
4-
directories:
5-
- node_modules
63
notifications:
74
email: false
85
node_js:
96
- '6'
10-
before_install:
11-
- npm i -g npm@^3.0.0
12-
before_script:
13-
- npm prune
147
after_success:
158
- npm run semantic-release
169
branches:

index.js

+10-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
module.exports = normalize
33
module.exports.fromCoordinates = module.exports.fromGeoJSON = fromCoordinates
4-
module.exports.fromLatlng = module.exports.fromLatlon = module.exports.fromLeaflet = fromLatlon
4+
module.exports.fromLatlng = module.exports.fromLeaflet = fromLatlng
55
module.exports.fromPoint = fromPoint
66
module.exports.fromString = fromString
77

@@ -10,22 +10,18 @@ module.exports.print = function print (input, fixed) {
1010
return ll.lon.toFixed(fixed || 5) + ', ' + ll.lat.toFixed(fixed || 5)
1111
}
1212

13-
module.exports.isEqual = function (latlon1, latlon2, epsilon) {
14-
latlon1 = normalize(latlon1)
15-
latlon2 = normalize(latlon2)
13+
module.exports.isEqual = function (lonlat1, lonlat2, epsilon) {
14+
lonlat1 = normalize(lonlat1)
15+
lonlat2 = normalize(lonlat2)
1616
epsilon = epsilon || 0
17-
return (Math.abs(latlon1.lat - latlon2.lat) <= epsilon) && (Math.abs(latlon1.lon - latlon2.lon) <= epsilon)
17+
return (Math.abs(lonlat1.lat - lonlat2.lat) <= epsilon) && (Math.abs(lonlat1.lon - lonlat2.lon) <= epsilon)
1818
}
1919

2020
module.exports.toCoordinates = module.exports.toGeoJSON = function toCoordinates (input) {
2121
var ll = normalize(input)
2222
return [ll.lon, ll.lat]
2323
}
2424

25-
module.exports.tolatlon = function tolatlon (input) {
26-
return normalize(input)
27-
}
28-
2925
module.exports.toPoint = function toPoint (input) {
3026
var ll = normalize(input)
3127
return {x: ll.lon, y: ll.lat}
@@ -46,8 +42,8 @@ function fromCoordinates (coordinates) {
4642
return floatize({lon: coordinates[0], lat: coordinates[1]})
4743
}
4844

49-
function fromLatlon (latlon) {
50-
return floatize(latlon)
45+
function fromLatlng (lonlat) {
46+
return floatize(lonlat)
5147
}
5248

5349
function fromPoint (point) {
@@ -59,9 +55,9 @@ function fromString (str) {
5955
return floatize({lon: arr[0], lat: arr[1]})
6056
}
6157

62-
function floatize (latlon) {
63-
const lon = parseFloat(latlon.lon || latlon.lng || latlon.longitude)
64-
return {lng: lon, lon: lon, lat: parseFloat(latlon.lat || latlon.latitude)}
58+
function floatize (lonlat) {
59+
const lon = parseFloat(lonlat.lon || lonlat.lng || lonlat.longitude)
60+
return {lon: lon, lat: parseFloat(lonlat.lat || lonlat.latitude)}
6561
}
6662

6763
function normalize (unknown) {

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"name": "lonlng",
3-
"description": "Lat/lon normalization cause...**sigh**",
2+
"name": "@conveyal/lonlat",
3+
"description": "Lon/lat normalization",
44
"main": "index.js",
55
"scripts": {
6-
"test": "node test.js",
6+
"test": "mastarm lint && node test.js",
77
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
88
},
99
"repository": {
@@ -24,6 +24,7 @@
2424
},
2525
"homepage": "https://github.com/conveyal/lonlng",
2626
"devDependencies": {
27+
"mastarm": "^1.3.0",
2728
"semantic-release": "^4.3.5"
2829
}
2930
}

test.js

+13-12
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,29 @@ const ll = require('./')
33

44
const lat = 38.13234
55
const lon = 70.01232
6-
const latlon = {lat, lon, lng: lon}
6+
const lonlat = {lon, lat}
77
const point = {x: lon, y: lat}
88
const coordinates = [lon, lat]
99
const str = `${lon},${lat}`
10+
const latlng = {lat, lng: lon}
1011

1112
const pairs = [
1213
// normalization
13-
[latlon, ll(latlon)],
14-
[latlon, ll(point)],
15-
[latlon, ll(coordinates)],
16-
[latlon, ll(str)],
14+
[lonlat, ll(lonlat)],
15+
[lonlat, ll(point)],
16+
[lonlat, ll(coordinates)],
17+
[lonlat, ll(str)],
1718

1819
// convert to type, normalizes to `latlng` first in each function
19-
[ll.toCoordinates(latlon), coordinates],
20-
[ll.toPoint(latlon), point],
21-
[ll.toString(latlon), str],
20+
[ll.toCoordinates(lonlat), coordinates],
21+
[ll.toPoint(lonlat), point],
22+
[ll.toString(lonlat), str],
2223

2324
// if the type is known, use the specific convert function directly
24-
[latlon, ll.fromLatlng(latlon)],
25-
[latlon, ll.fromCoordinates(coordinates)],
26-
[latlon, ll.fromPoint(point)],
27-
[latlon, ll.fromString(str)]
25+
[lonlat, ll.fromLatlng(latlng)],
26+
[lonlat, ll.fromCoordinates(coordinates)],
27+
[lonlat, ll.fromPoint(point)],
28+
[lonlat, ll.fromString(str)]
2829
]
2930

3031
pairs.forEach((pair) => assert.deepEqual(pair[0], pair[1]))

0 commit comments

Comments
 (0)