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.
(type)
An unknown type of input. Must be one of the following:
longitude,latitude
x
and y
properties.
x
represents longitude and y
represents latitude.lon
, lng
or longitude
For latitude any of the following are valid: lat
or latitude
Type: (Array | string | Object)
Parameters
unknown
(exception type)
An error that is thrown upon providing invalid coordinates.
Type: Error
Parameters
unknown
Parse an unknown type of input.
Parameters
unknown
lonlat.types.inputExamples
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
Returns lonlat.types.output
aliases: fromGeoJSON
Tries to parse from an array of coordinates.
Parameters
coordinates
Array An array in the format: [longitude, latitude]Examples
var lonlat = require('@conveyal/lonlat')
var position = lonlat.fromCoordinates([12, 34]) // { lon: 12, lat: 34 }
position = lonlat.fromGeoJSON([12, 34]) // { lon: 12, lat: 34 }
Returns lonlat.types.output
aliases: fromLeaflet
Tries to parse from an object.
Parameters
lonlat
Object An object with a lon
, lng
or longitude
attribute and a lat
or latitude
attributeExamples
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 }
Returns lonlat.types.output
Tries to parse from an object.
Parameters
point
Object An object with a x
attribute representing longitude
and a y
attribute representing latitude
Examples
var lonlat = require('@conveyal/lonlat')
var position = lonlat.fromPoint({ x: 12, y: 34 }) // { lon: 12, lat: 34 }
Returns lonlat.types.output
aliases: fromLonFirstString
Tries to parse from a string where the longitude appears before the latitude.
Parameters
str
string A string in the format: longitude,latitude
Examples
var lonlat = require('@conveyal/lonlat')
var position = lonlat.fromString('12,34') // { lon: 12, lat: 34 }
var position = lonlat.fromLonFirstString('12,34') // { lon: 12, lat: 34 }
Returns lonlat.types.output
Tries to parse from a string where the latitude appears before the longitude.
Parameters
str
string A string in the format: latitude,longitude
Examples
var lonlat = require('@conveyal/lonlat')
var position = lonlat.fromLatFirstString('12,34') // { lon: 34, lat: 12 }
Returns lonlat.types.output
Determine if two inputs are equal to each other
Parameters
lonlat1
inputlonlat2
inputepsilon
number? The maximum acceptable deviation to be considered equal. (optional, default 0
)Examples
var lonlat = require('@conveyal/lonlat')
var isEqual = lonlat.isEqual('12,34', [12, 34]) // true
Returns boolean
Parameters
input
inputfixed
number? The number of decimal places to round to. (optional, default 5
)Examples
var lonlat = require('@conveyal/lonlat')
var pretty = lonlat.print('12.345678,34') // '12.34568, 34.00000'
Returns string A string with in the format longitude,latitude
rounded to
the number of decimal places as specified by fixed
aliases: toGeoJSON
Translates to a coordinate array.
Parameters
input
lonlat.types.inputExamples
var lonlat = require('@conveyal/lonlat')
var coords = lonlat.toCoordinates('12,34') // [12, 34]
Returns Array An array in the format [longitude, latitude]
Translates to Leaflet LatLng object.
This function requires Leaflet to be installed as a global variable L
in the window environment.
Parameters
input
lonlat.types.inputExamples
var lonlat = require('@conveyal/lonlat')
var position = lonlat.toLeaflet({ lat: 12, long: 34 }) // Leaflet LatLng object
Returns Object A Leaflet LatLng object
Translates to point Object.
Parameters
input
lonlat.types.inputExamples
var lonlat = require('@conveyal/lonlat')
var point = lonlat.toPoint('12,34') // { x: 12, y: 34 }
Returns Object An object with x
and y
attributes representing latitude and longitude respectively
aliases: toLonFirstString
Translates to coordinate string where the longitude appears before latitude.
Parameters
input
lonlat.types.inputExamples
var lonlat = require('@conveyal/lonlat')
var str = lonlat.toString({ lat: 12, longitude: 34 }) // '34,12'
var str = lonlat.toLonFirstString({ lat: 12, longitude: 34 }) // '34,12'
Returns string A string in the format 'longitude,latitude'
Translates to coordinate string where the latitude appears before longitude.
Parameters
input
lonlat.types.inputExamples
var lonlat = require('@conveyal/lonlat')
var str = lonlat.toLatFirstString({ lat: 12, longitude: 34 }) // '12,34'
Returns string A string in the format 'longitude,latitude'
(type)
Standardized lon/lat object.
Type: Object
Parameters
unknown
Properties
FAQs
Lon/lat normalization
The npm package @conveyal/lonlat receives a total of 287 weekly downloads. As such, @conveyal/lonlat popularity was classified as not popular.
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.