Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
@conveyal/lonlat
Advanced tools
Lon/lat normalization cause...sigh.
No one has agreed on a standard way of representing lon/lat. This is a small normalization library. Use this to convert all outside input before processing internally and convert to an external format right when it's being output.
Tries parse input and transform to an output of normalized coordinates. Will throw an error upon finding invalid coordinates.
input (*)
: Can be any of the following:
x
attribute representing longitude
and a y
attribute representing latitude
lon
, lng
or longitude
attribute and a lat
or latitude
attribute(Object)
: An object with lon
and lat
attributes.
var lonlat = require('@conveyal/lonlat')
// Object with lon/lat-ish attributes
var position = lonlat({ lon: 12, lat: 34 }) // { lon: 12, lat: 34 }
position = lonlat({ lng: 12, lat: 34 }) // { lon: 12, lat: 34 }
position = lonlat({ longitude: 12, latitude: 34 }) // { lon: 12, lat: 34 }
position = lonlat({ lng: 12, latitude: 34 }) // { lon: 12, lat: 34 }
// coordinate array
position = lonlat([12, 34]) // { lon: 12, lat: 34 }
// string
position = lonlat('12,34') // { lon: 12, lat: 34 }
// object with x and y attributes
position = lonlat({ x: 12, y: 34 }) // { lon: 12, lat: 34 }
// the following will throw errors
position = lonlat({ lon: 999, lat: 34 }) // Error: Invalid longitude value: 999
position = lonlat({ lon: 12, lat: 999 }) // Error: Invalid latitude value: 999
position = lonlat({}) // Error: Invalid latitude value: undefined
position = lonlat(null) // Error: Value must not be null or undefined
Tries to parse from an array of coordinates. Will throw an error upon finding invalid coordinates.
arr (Array)
: An array in the format: [longitude, latitude]
(Object)
: An object with lon
and lat
attributes.
var lonlat = require('@conveyal/lonlat')
var position = lonlat.fromCoordinates([12, 34]) // { lon: 12, lat: 34 }
position = lonlat.fromGeoJSON([12, 34]) // { lon: 12, lat: 34 }
Tries to parse from an object. Will throw an error upon finding invalid coordinates.
obj (Object)
: An object with a lon
, lng
or longitude
attribute and a lat
or latitude
attribute
(Object)
: An object with lon
and lat
attributes.
var lonlat = require('@conveyal/lonlat')
var position = lonlat.fromLatlng({ longitude: 12, latitude: 34 }) // { lon: 12, lat: 34 }
position = lonlat.fromLeaflet({ lng: 12, lat: 34 }) // { lon: 12, lat: 34 }
Tries to parse from an object. Will throw an error upon finding invalid coordinates.
obj (Object)
: An object with a x
attribute representing longitude
and a y
attribute representing latitude
(Object)
: An object with lon
and lat
attributes.
var lonlat = require('@conveyal/lonlat')
var position = lonlat.fromPoint({ x: 12, y: 34 }) // { lon: 12, lat: 34 }
Tries to parse from a string. Will throw an error upon finding invalid coordinates.
str (string)
: A string in the format: '{longitude},{latitude}'
(Object)
: An object with lon
and lat
attributes.
var lonlat = require('@conveyal/lonlat')
var position = lonlat.fromString('12,34') // { lon: 12, lat: 34 }
Returns a pretty string
input (*)
: Any format mentioned in lonlat(input)[fixed=5] (Number)
: The number of digits to round to(string)
: A string with the latitude and longitude rounded to the number of decimal places as specified by fixed
var lonlat = require('@conveyal/lonlat')
var pretty = lonlat.print('12.345678,34') // '12.34568, 34.00000'
Checks equality of two inputs within an allowable difference.
lonlat1 (*)
: Any format mentioned in lonlat(input)lonlat2 (*)
: Any format mentioned in lonlat(input)[epsilon=0] (Number)
: The maximum allowable difference of between each latitude and longitude(boolean)
: Returns true
if the inputs are equal or false
if they are not
var lonlat = require('@conveyal/lonlat')
var isEqual = lonlat.isEqual('12,34', [12, 34]) // true
Translates to a coordinate array.
input (*)
: Any format mentioned in lonlat(input)
(Array)
: An array in the format: [longitude, latitude]
var lonlat = require('@conveyal/lonlat')
var coords = lonlat.toCoordinates('12,34') // [12, 34]
Translates to point Object.
input (*)
: Any format mentioned in lonlat(input)
(Object)
: An object with x
and y
attributes representing latitude and longitude respectively
var lonlat = require('@conveyal/lonlat')
var point = lonlat.toPoint('12,34') // { x: 12, y: 34 }
Translates to coordinate string.
input (*)
: Any format mentioned in lonlat(input)
(string)
: A string in the format 'latitude,longitude'
var lonlat = require('@conveyal/lonlat')
var str = lonlat.toString({ lat: 12, long: 34 }) // '12,34'
Translates to Leaflet LatLng object. This function requires Leaflet to be installed as a global variable L
in the window environment.
input (*)
: Any format mentioned in lonlat(input)
(Object)
: A Leaflet LatLng object
var lonlat = require('@conveyal/lonlat')
var position = lonlat.toLeaflet({ lat: 12, long: 34 }) // Leaflet LatLng object
FAQs
Lon/lat normalization
We found that @conveyal/lonlat demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.