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

@lovekeqing/captcha

v0.0.8

Published

A simple svg captcha generator

Downloads

70

Readme

@lovekeqing/captcha

English | 中文

一个简单的 SVG 验证码生成器,支持数字、字母、混合和数学公式类型,可自定义字体、字符集、干扰线等参数。暂时不支持浏览器端。

特性

  • 支持多种验证码类型:数字、字母、混合、公式
  • 可自定义验证码长度、字符集、忽略字符
  • 支持自定义字体(TTF)
  • 可设置验证码图片宽高
  • 支持设置背景颜色和自动计算字体颜色
  • 干扰线数量和宽度可调
  • 生成 SVG 格式验证码图片
  • 支持 TypeScript 类型提示

安装

pnpm add @lovekeqing/captcha

使用方法

import { Captcha } from "@lovekeqing/captcha";

const captcha = new Captcha({
  type: "formula", // 验证码类型,可选:"number" | "letter" | "mix" | "formula"
  length: 3, // 验证码长度或公式中数字个数
  noise: 2, // 干扰线数量
});

captcha.generate().then(({ value, svg }) => {
  console.log("验证码值:", value);
  // svg 为验证码图片的 SVG 字符串
});

配置项

详见 CaptchaOptions

下面所有的配置项均为可选:

  • fontPath:字体文件路径,支持 ttf
  • type:验证码类型,"number" | "letter" | "mix" | "formula",默认 "number"
  • length:验证码长度,默认 4,公式类型表示数字个数
  • width/height:验证码图片宽高,默认自动计算
  • noise:干扰线数量,默认 1
  • noiseWidth:干扰线宽度,默认 0.03 的图片高度
  • chars:自定义字符集,默认根据 type 生成
  • ignoreChars:忽略的字符集
  • backgroundColor:背景颜色,默认随机生成

generate 方法

captcha.generate(content?: string): Promise<CaptchaResult>

generate 方法用于生成随机的验证码图片,详见 CaptchaResult

generate 方法接受一个可选参数 content,用于指定验证码的内容。如果不传入该参数,验证码内容将根据配置项随机生成。

返回一个 Promise 对象,其成功的结果包含以下属性:

  • value:验证码答案
  • svg:验证码的 SVG 字符串
  • backgroundColor:背景颜色
  • width:宽度,实际生成的验证码图片宽度
  • height:高度,实际生成的验证码图片高度
  • scale:缩放,当用户指定的宽高与计算宽高不符时,会按用户指定的宽高进行缩放

开发命令

  • pnpm build:构建项目
  • pnpm test:运行测试
  • pnpm build:docs:生成文档
  • pnpm build:all:测试、构建并生成文档

贡献流程

  1. Fork 本仓库
  2. 创建新分支并进行修改
  3. 提交 Pull Request

当项目的管理员审核通过后,您的贡献将被合并到主分支中。

许可证

MIT License