@aacn.eu/use-friendly-captcha

中文文档
1.3.0发布于 2024/02/20MITTypeScriptESM + CJS零依赖近 30 天下载 2.5万

FriendlyCaptcha React Implementation

原始使用文档
文档目录5 节
  1. Usage
  2. Frontend
  3. Backend
  4. httpPostFetcher
  5. Examples

Use Friendly Captcha hook

Usage

The library has functions for both frontend and backend. Both of them work independent of each other.

Frontend

Include the useCaptchaHook() in your selected file. From there you can then query the widget and state from the hook, for you to manage and use in your form.

Please be aware that the friendly-challenge library is a necessary peer dependency since version 1.2.0

The hook expects the following properties:

siteKey: string;
endpoint?: FC_PUZZLE_EP; enum for the currently available endpoints (EU & global)
language?: keyof typeof localizations | Localization;
startMode?: "auto" | "focus" | "none";
showAttribution: boolean;

The hook provides the following parameters:
- `CaptchaWidget` returns the HTML authentification widget. - `captchaStatus.solution` is used to determine if the puzzle was already solved (`string`) or not (`null`) - `captchaStatus.error` is used to determine if an error occured while solving (`string`) or not (`null`)


CaptchaWidget custom props
When the CaptchaWidget gets rendered, you can add additional properties:

props: HTMLAttributes This includes all possible html attributes. Therefor this is the entry point to add the className attribute, to add custom styling to the outer captcha container. Here can you either directly add TailwindCSS classes or define a custom class for future styling in the .css file of the project.

customWidgetStyle allows up to three attributes for specific stylings that are directly applied to the components:

  • icon The icon of the widget
  • button The submit button of the widget
  • text All text elements that appear inside the widget
    These attributes are all optional and if used, they expect a css object like the following example:
CustomWidgetStyle = { icon: {color: "green", background: "yellow"}, text: {color: "blue"} }

Backend

backend wise this library provides a function that uses the FriendlyCaptcha verification API to check if the submitted puzzle solution is valid or not. It returns a boolean for further handling in your own code.

The function expects the following properties:

endpoint?: FC_VERIFICATION_EP; enum for the currently available endpoints (EU & global)
solution: string;
secret: string;
sitekey?: string;
httpPostFetcher: (see further down)

httpPostFetcher

The backend expects a fetcher function as parameter. This function is provided by the user and is used to send a http post request to the fc verification server. It should match the following design:

function fetcherExample(
    endpoint: string,
    requestBody: { solution: string; secret: string; siteKey: string },
    headers: { 'Content-Type': 'application/json'; 'Accept': 'application/json'; }
) => Promise<{ success: boolean; errors: any; } | null>

Examples

We provided basic examples in the /examples folder, on how to use this library in React and Nextjs. Both examples are written in TypeScript and are kept simple to focus on easy readability and presenting the utility of the function from this library. If you want to run the examples on your machine, make sure to read the respective README files, to add all requirements that are needed.

版本与发布记录

@aacn.eu/use-friendly-captcha 共发布 12 个版本,首次发布于 2022/12/10;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.3.0latest2024/02/202 年前
1.2.32023/07/113 年前
1.2.22023/07/103 年前
1.2.12023/07/103 年前
1.2.02023/03/133 年前
1.1.32023/03/093 年前

关于 @aacn.eu/use-friendly-captcha 的常见问题

@aacn.eu/use-friendly-captcha 是什么?

FriendlyCaptcha React Implementation

如何安装 @aacn.eu/use-friendly-captcha?

在项目目录运行 npm install @aacn.eu/use-friendly-captcha,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:friendly-challenge(^0.9.11)、react(>=17.0.2)、react-dom(>=17.0.2)、tailwindcss(>=3.1.8)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@aacn.eu/use-friendly-captcha 支持 TypeScript 吗?

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

@aacn.eu/use-friendly-captcha 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@aacn.eu/use-friendly-captcha 可以商用吗?

@aacn.eu/use-friendly-captcha 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@aacn.eu/use-friendly-captcha 的下载量有多少?

根据 npm 官方下载统计,@aacn.eu/use-friendly-captcha 在 2026/10/05 – 2026/11/03 这 30 天内被下载 24,513 次,日均约 817 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aacn.eu/use-friendly-captcha 还在维护吗?

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