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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@plotdb/captcha

v0.0.2

Published

captcha sample

Readme

captcha

Captcha wrapper for captcha services.

Usage

include captcha.js:

<script src="dist/captcha.js"></script>

use captcha object to create captcha service wrappers like this:

mycaptcha = new captcha({
  init: function() { Promise.resolve('...'); },
  get: function(opt) { Promise.resolve('...'); }
  isVerifyFailed: function(err) { ... }
  alt: { ... },
  config: { ... }
  lc: { ... }
});

with following options:

  • init(): function for initializing your captcha.

    • will be called only once and always called automatically when get is called.
    • should return Promise.
  • get(opt): function used to getting captcha token for verifying through backend.

    • should return Promise resolving object with token field ( {token: ... } ).

    • opt is defined by user.

    • if captcha verification failed, reject with an error which can be recognize with isVerifyFailed.

  • isVerifyFailed(err): optional function to check if a given error object err is for verification failure.

    • if alt is provided and when execute calls callback function but an error for verification failure is returned by the callback function, then captcha will try again with another captcha object corresponding to alt.
    • check below section for how execute works.
  • alt: optional. either an object for captcha constructor options, or a captcha object.

    • if set, alt will be used when veritification failed with the owner captcha object.
  • config: default config object for this captcha object.

    • this is designed for providing configuration to user defined get and init functions.
  • lc: object storing default value for storing variables defined by get and init functions.

Once constructed, you can get a token by:

mycaptcha.get().then(function(opt) { opt.token; });

Since token usually involves server-side verification, you can use execute for alt captcha

postData = function({ .../* object returned by `get` */... }) {
  /* should return promise */
  Promise.resolve!
    .then -> /* fetch, ajax with the `get` returned object */
};

mycaptcha.execute({ ... /* options to `get` */ ... }, postData).then(function() { ... });

API

  • get(opt): get captcha token. should return Promise resolving {token} object.
    • opt: user defined option for using in user defined get function.
  • execute(opt, cb): execute cb with get returned object. return promise
    • opt: options passed to get.
    • cb(ret): callback functions with get returned object as option ( ret ).
      • cb should return Promise. If verification failed, cb can optionally rejects with error object recognizable by isVerifyFailed.
  • setConfig: update config object.

ReCaptcha

captcha ships with predefined Google Recaptcha wrapper. use it by first including the needed js:

<script src="dist/captcha.js"></script>
<script src="dist/recaptcha.js"></script>

then:

recaptcha.v2.setConfig({sitekey: '....', enabled: ture});
recaptcha.v2.get();

recaptcha.v3.setConfig({sitekey: '....', enabled: ture});
recaptcha.v3.get();

License

MIT