kinotto / geonames.js

Nodejs and Browser client for Geonames.org REST API :earth_africa:
http://www.geonames.org/export/client-libraries.html
MIT License
88 stars 17 forks source link

Suggestion for v2.0 (ES6+ version) #3

Closed lamuertepeluda closed 6 years ago

lamuertepeluda commented 6 years ago

Hey there,

I was trying to use your library, but I had some difficult importing it using my module bundler (webpack).

So after some time I gave up and rewrote it entirely using a more modern syntax. I wanted to share this with you, since I tried to make it backward compatible (although compatibility is 100% untested) and it seems to work. I used axios, a promise based ajax library which works well on both browser and node. So you could drop a bunch of superseeded dependencies.

I also added the HTTPS endpoint as baseURL since it's more suited for modern websites.

See the code and how it works on StackBlitz: https://stackblitz.com/edit/js-hqzhep?file=Geonames.js

If you think ES5 compatibility is important, we can make a webpack config file for transpiling it.

Feel free to use this code to make a new version of this library if you wish.

kinotto commented 6 years ago

Hi @lamuertepeluda, you are absolutely correct, i was using the request library to make ajax calls on the browser, that is exclusively a node library, that is why webpack was raising an error at build time. today i updated the library, v2.0, new compact and elegant ES6+ syntax integrated with webpack and babel to allow transpiling for both client and server, the code has been tested in both environments and seems to work fine (check out the readme :) ) I followed your advice and used axios as well, with the secure endpoint rather then the normal one.

thank you very much for the effort you made in providing your code, hope you will be able to include the library now :) Best

lamuertepeluda commented 6 years ago

Hi @kinotto,

I'm glad you integrated my suggestions for v2.0! 😃

I'd like to suggest you the following steps (will fork and make PRs as soon as I have time if you agree) in order to improve this library further:

what do you think about it?

kinotto commented 6 years ago

@lamuertepeluda

i'll be more than happy to accept your PR and add you as a collaborator to the project, just please run the unit tests once finished.

Actually would be nice to improve the coverage of the tests, now they cover only the 70% of the code but maybe you can improve it (not strictly necessary, but if you find time would be great)

thanks again 👍