npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

geocoder-dadata

v1.0.1

Published

Dadata geocoder API client that supports caching and is written purely on typescript

Downloads

4

Readme

Why dadata?

  • Amazing quality of Geocoding for territory of Russia
  • Moderate pricing
  • Lot's of other useful servicies like suggestions and others

Example

Forward geocoding

    const { Geocoder } = require('geocoder-dadata')
    const coder = new Geocoder({ api_token: 'YOUR DATATA API TOKEN', api_secret: 'YOUR DATATA API SECRET' })

    coder.geocode('Москва, Мичуринский пр-т, 9к1').then(resp => {

        if (resp.ok) {

            console.log('Geo coordinates:', resp.geo)
            console.log('Detailed response:', resp.results)
        }

        else {

            console.log('Request has failed')
            console.log('Check the full response from dadata:', resp)
            console.log('Or you can check response status only:', resp.status.code, resp.status.message)
        }
    })

Make it safe

To make your code safer put your API token and secret into environment variables DADATA_API_TOKEN и DADATA_API_SECRET and avoid passing it to the geocoder constructor as plain text in your code:

    const coder = new geocoder() //In this case your are expected to provide your API credebtials in DADATA_API_TOKEN и DADATA_API_SECRET variable before using geocoder constructor

Response caching

By default the geocoder automaticaly caches responses in memory. The cache is shared among all instances of the geocoder class that use the same API KEY. If you change an API key, it makes cached responses effectively invisible to other geocoder instances if they use other API keys.

If you would like a particular geocoder instance not to use caching you may provide it a { cached: false } option like so:

    const coder = new geocoder({ cached: false })
    // By default "cached" option is set to true

Batch request throttling

It's important to note that just like any other service provider dadata puts certain limits on how much requests you may send per second (10 requests per second). When it comes to batch processing, a pace keeping techniques comes into play. The geocoder-dadata client supports requests throttling by default so you can rest peacefully. If you send lots of requests to geocoder-dadata they will be arranged in a queue and scheduled to be sent at rate of 5 request per second. If you want to tweek internal pace keeper by pace_limit option like so:

    const coder = new geocoder({ pace_limit: 10 })
        // This will limit the geocoder to 10 requests per second.
        // Put here whatever suits your contract with dadata
        // By default "pace_limit" equals to 5