# invisible-grecaptcha

[![npm (scoped)](https://img.shields.io/npm/v/invisible-grecaptcha.svg)](https://www.npmjs.com/package/invisible-grecaptcha)
[![Travis](https://img.shields.io/travis/thiamsantos/invisible-grecaptcha.svg)](https://travis-ci.org/thiamsantos/invisible-grecaptcha)
[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)

> Invisible reCAPTCHA integration

[Checkout the demo](https://thiamsantos.github.io/invisible-grecaptcha/).

## Table of Contents

-   [Install](#install)
-   [Usage](#usage)
-   [API](#api)
-   [Contributing](#contributing)
-   [License](#license)

## Install

This project uses [node](http://nodejs.org) and [npm](https://npmjs.com).
Go check them out if you don't have them locally installed.

```sh
$ npm install --save invisible-grecaptcha
```

The [UMD](https://github.com/umdjs/umd) build is also available on [jsdelivr](https://www.jsdelivr.com/):

```html
<script src="https://cdn.jsdelivr.net/npm/invisible-grecaptcha/dist/index.min.js"></script>
```

You can find the library on `window.invisibleGrecaptcha`.

## Usage

```js
import { 
  execute, 
  destroy, 
} from 'invisible-grecaptcha'


const token = await execute('RECAPTCHA_SITE_KEY')

destroy()
```

## API

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

#### Table of Contents

-   [execute](#execute)
-   [destroy](#destroy)

### execute

Creates an invisible reCAPTCHA instance, dynamically loading Google's library if necessary, and then returns a user
response token. This is a client-side step, and the token must be sent to the server side for verification as a
separate step. Tokens are single use and can be verified only once.

**Parameters**

-   `sitekey` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Your recaptcha sitekey. You can get one here: <https://www.google.com/recaptcha/admin>.
-   `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** The options to create an invisible reCAPTCHA. (optional, default `{}`)
    -   `options.locale` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Language of the captcha. See available language codes <https://developers.google.com/recaptcha/docs/language>. Auto-detects the user's language if unspecified. (optional, default `en`)
    -   `options.position` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Position the reCAPTCHA badge. Values: bottomright, bottomleft and inline. (optional, default `bottomright`)
    -   `options.baseUrl`   (optional, default `'https://www.google.com'`)

Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 

### destroy

Destroy the instance of an invisible grecaptcha.

## Contributing

See the [contributing file](CONTRIBUTING.md).

## License

[MIT License](LICENSE.md) © [Thiago Santos](https://github.com/thiamsantos)
