@captchahub/recaptcha

中文文档
1.0.14发布于 2026/09/11TypeScriptES Module近 30 天下载 6400

CaptchaHub ReCaptcha is a TypeScript library that provides integration with the Google ReCaptcha service, allowing for seamless captcha implementation within your applications. This package extends the core functionality of CaptchaHub to support ReCap

原始使用文档
文档目录10 节
  1. Installation
  2. Features
  3. Usage
  4. Getting the Captcha Script
  5. Getting the Captcha Form Element
  6. Verifying the Captcha
  7. Configuration
  8. Extensibility
  9. Rationale
  10. Contributing

CaptchaHub ReCaptcha

CaptchaHub ReCaptcha is a TypeScript library that provides integration with the Google ReCaptcha service, allowing for seamless captcha implementation within your applications. This package extends the core functionality of CaptchaHub to support ReCaptcha as a captcha provider.

Installation

Install the package using pnpm:

pnpm add @captchahub/core
pnpm add @captchahub/recaptcha

Features

  • Widely Used: ReCaptcha is a widely adopted captcha solution by Google.
  • Customizable: Easily customize the appearance and behavior of the captcha.
  • Requires Core Package: This package requires the @captchahub/core package for functionality.

Usage

Getting the Captcha Script

The getCaptchaScript function can be used as follows:

import { getCaptchaScript } from '@captchahub/core';
// Import the provider package to trigger self-registration
import '@captchahub/recaptcha';

const config = {
    CAPTCHA_PROVIDER: 'recaptcha',
    RECAPTCHA_SITE_KEY: process.env.RECAPTCHA_SITE_KEY, // Your ReCaptcha site key
};

const CaptchaComponent = () => {
    const CaptchaScript = getCaptchaScript(config);

    return (
        <div>
            <CaptchaScript />
            {/* Additional form elements */}
        </div>
    );
};

Getting the Captcha Form Element

The getCaptchaFormElement function can be used as follows:

import { getCaptchaFormElement } from '@captchahub/core';
// Import the provider package to trigger self-registration
import '@captchahub/recaptcha';

const config = {
    CAPTCHA_PROVIDER: 'recaptcha',
    RECAPTCHA_SITE_KEY: process.env.RECAPTCHA_SITE_KEY, // Your ReCaptcha site key
};

const CaptchaFormComponent = async () => {
    const CaptchaFormElement = getCaptchaFormElement(config);

    return (
        <div>
            <CaptchaFormElement />
            {/* Additional form elements */}
        </div>
    );
};

Verifying the Captcha

The verifyCaptcha function can be used as follows:

import { verifyCaptcha } from '@captchahub/core';
// Import the provider package to trigger self-registration
import '@captchahub/recaptcha';

const config = {
    CAPTCHA_PROVIDER: 'recaptcha',
    RECAPTCHA_SECRET_KEY: process.env.RECAPTCHA_SECRET_KEY, // Your ReCaptcha secret key
};

const formFieldValues = {
    // Your form field values that need to be verified
};

const isValid = await verifyCaptcha(formFieldValues, config);
if (isValid) {
    console.log('Captcha verified successfully!');
} else {
    console.error('Captcha verification failed.');
}

Configuration

Configuration for the ReCaptcha provider can be defined in a configuration object passed to the factory when creating the captcha instance. The configuration object must include the CAPTCHA_PROVIDER property to specify which captcha provider to use. Additionally, you will need to provide the RECAPTCHA_SITE_KEY and RECAPTCHA_SECRET_KEY for proper functionality.

Extensibility

The @captchahub/recaptcha package is designed to be extensible. You can create new captcha providers by implementing the CaptchaInterface. This allows you to add support for additional captcha services in the future.

Rationale

The @captchahub/recaptcha package is designed to provide integration with the Google ReCaptcha service for managing captcha workflows in TypeScript applications. By using the core package, developers can easily integrate ReCaptcha capabilities into their web applications.

Contributing

Contributions are welcome! Feel free to fork this project and submit pull requests. Before submitting, please ensure your code passes all linting and unit tests.

You can format code using:

pnpm format

You can run unit tests using:

pnpm test

版本与发布记录

@captchahub/recaptcha 共发布 14 个版本,首次发布于 2024/11/24;过去 12 个月发布了 6 个版本。

版本发布日期距今
1.0.14latest2026/09/111 个月前
1.0.132026/08/292 个月前
1.0.122026/08/282 个月前
1.0.112026/08/063 个月前
1.0.102026/03/297 个月前
1.0.92026/03/277 个月前

关于 @captchahub/recaptcha 的常见问题

@captchahub/recaptcha 是什么?

CaptchaHub ReCaptcha is a TypeScript library that provides integration with the Google ReCaptcha service, allowing for seamless captcha implementation within your applications. This package extends the core functionality of CaptchaHub to support ReCap

如何安装 @captchahub/recaptcha?

在项目目录运行 npm install @captchahub/recaptcha,或使用 pnpm add / yarn add / bun add。

@captchahub/recaptcha 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@captchahub/recaptcha 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@captchahub/recaptcha 可以商用吗?

@captchahub/recaptcha 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@captchahub/recaptcha 的下载量有多少?

根据 npm 官方下载统计,@captchahub/recaptcha 在 2026/10/09 – 2026/11/07 这 30 天内被下载 6,400 次,日均约 213 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@captchahub/recaptcha 还在维护吗?

最新版本 1.0.14 发布于 2026/09/11(1 个月前);至今共发布 14 个版本,其中过去 12 个月发布了 6 个;首次发布于 2024/11/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。