captcha-svg-generator
Version:
A lightweight, customizable Node.js library to generate SVG CAPTCHA images with random characters, noise lines, and custom fonts using opentype.js. Ideal for Express.js, authentication, and bot protection.
18 lines (16 loc) • 759 B
JavaScript
import { CaptchaGenerator } from "./CaptchaGenerator.js";
/**
* Simple wrapper for generating a CAPTCHA with default options.
*
* @param {import("./CaptchaGenerator.mjs").CaptchaOptions} [options={}] - Captcha configuration options
* @param {string[]} [fontsFamily=[]] - Array of font file paths to use
* @returns {Promise<{ key: string, text: string, data: string }>} - Captcha object containing key, text, and SVG data
*
* @example
* import { generateCaptcha } from "./generateCaptcha.mjs";
* const captcha = await generateCaptcha({ size: 5 });
*/
export const generateCaptcha = async function (options = {}, fontsFamily = []) {
const captchaGen = new CaptchaGenerator(options, fontsFamily);
return captchaGen.generate();
};