# @ebao/captchajs

> 前端验证码生产器

Latest version **1.0.2** (published 2022-06-17) · ISC license · 0 weekly downloads

## Install

```sh
npm install @ebao/captchajs
pnpm add @ebao/captchajs
yarn add @ebao/captchajs
bun add @ebao/captchajs
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2022-06-17 |
| First published | 2022-06-15 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 38.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | ebao |

## Links

- npm: https://www.npmjs.com/package/@ebao/captchajs
- Repository: https://github.com/qyjs/captchajs
- Homepage: https://github.com/qyjs/captchajs#readme
- Issues: https://github.com/qyjs/captchajs/issues
- npm.io page: https://npm.io/package/@ebao/captchajs

## Dependencies (1)

- [typescript](https://npm.io/package/typescript.md) ^4.7.3

## Recent versions

- 1.0.2 (latest) — 2022-06-17
- 1.0.1 — 2022-06-15
- 1.0.0 — 2022-06-15

## README

# code-validator

前端验证码生产器

## install

```bash
pnpm  i @ebao/captchajs
# OR npm i @ebao/captchajs --save
```

## import

```js
import { CodeValidator } from "@ebao/captchajs";
```

## guide

```js
const cv = new CodeValidator();
const res = cv.random();
```

### in angular

```ts
import { Component, OnInit } from '@angular/core';
import { DomSanitizer, SafeUrl } from '@angular/platform-browser';
import { CodeValidator } from '@ebao/captchajs'
@Component({
  selector: 'my-app',
  template: `
  <img [src]="base64" (click)="random()"/>
  <h3>{{value}}</h3>
  `
})
export class AppComponent implements OnInit {
  base64: SafeUrl
  value: string
  cv = new CodeValidator({
    width:160,
    height:50,
    length:5
  })
  constructor(private sanitizer: DomSanitizer) { }
  ngOnInit() {
    this.random()
  }
  random() {
    let res = this.cv.random()
    this.base64 = this.sanitizer.bypassSecurityTrustUrl(res.base)
    this.value = res.value
  }
}
```

## more

> interface

```ts
export class CodeValidator {
  constructor(options?: { width?: number; height?: number; length?: number });
  random(): { base: string; value: string };
}
```

> constructor options
| 参数   | 默认值 | 说明       |
| :----- | :----- | :--------- |
| width  | 100    | 图片宽度   |
| height | 30     | 图片高度   |
| length | 4      | 验证码长度 |

> random return
| 参数  | 说明                     |
| :---- | :----------------------- |
| base  | 验证码图片的 base64 编码 |
| value | 图片高度                 |

## example

[![img1](./doc/code.png)](https://stackblitz.com/edit/code-validator)
[![img2](./doc/code1.png)](https://stackblitz.com/edit/code-validator)

npm publish --access public

---
_Source: https://npm.io/package/@ebao/captchajs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
