Skip to content

Instantly share code, notes, and snippets.

@aynik
Created December 26, 2017 20:49
Show Gist options
  • Save aynik/6052d753b30760fc466884ead2752271 to your computer and use it in GitHub Desktop.
Save aynik/6052d753b30760fc466884ead2752271 to your computer and use it in GitHub Desktop.
Nearest city
#!/usr/bin/env node
const stdin = require('/usr/local/lib/node_modules/get-stdin')
const { parseDms } = require('/usr/local/lib/node_modules/dms-conversion')
const nearbyCities = require('/usr/local/lib/node_modules/aynik-nearby-cities')
const { NEAREST_CITY_DEBUG } = process.env
const getNearestCity = (latitude, longitude) => (
((data) => (
NEAREST_CITY_DEBUG
? JSON.stringify(data, null, 4)
: `${data.name}, ${data.country}`
))(nearbyCities({ latitude, longitude })[0])
)
stdin().then((str) => process.stdout.write(getNearestCity.apply(null, str.split(',').map(parseDms))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment