index.d.ts
1 /** 2 * config captcha generation options 3 */ 4 declare class ConfigObject { 5 /** 6 * default: true 7 * The length of the random string 8 */ 9 size?: number; 10 /** 11 * width of captcha 12 */ 13 width?: number; 14 /** 15 * height of captcha 16 */ 17 height?: number; 18 /** 19 * captcha text size 20 */ 21 fontSize?: number; 22 /** 23 * random character preset 24 */ 25 charPreset?: string; 26 /** 27 * default: false 28 * if false, captcha will be black and white 29 * otherwise, it will be randomly colorized 30 */ 31 color?: boolean; 32 /** 33 * default: false 34 * if set to true, it will draw with light grey color 35 * use if you have a site with dark theme 36 * only active when color is set to false 37 */ 38 inverse?: boolean; 39 /** 40 * default: '' 41 * filter out some characters 42 */ 43 ignoreChars?: string; 44 /** 45 * default: 1 46 * number of noise lines 47 */ 48 noise?: number; 49 /** 50 * default: white 51 * background color of svg image 52 */ 53 background?: string; 54 /** 55 * default: + 56 * the math operator to use, "+", "-" or "+/-" 57 * if unknown operator passed defaults to "+/-" 58 */ 59 mathOperator?: string; 60 /** 61 * default: 1 62 * min value of the math expression 63 */ 64 mathMin?: number; 65 /** 66 * default: 9 67 * max value of the math expression 68 */ 69 mathMax?: number; 70 } 71 /** 72 * result of captcha generation 73 */ 74 interface CaptchaObj { 75 /** 76 * the captcha text, 77 * store this in your session 78 */ 79 text: string, 80 /** 81 * the svg image in string, 82 * set type of image/svg before send to client side 83 */ 84 data: string 85 } 86 /** 87 * This method returns a object that has two props: 88 * data: svg image string 89 * text: captcha text 90 * @param {ConfigObject} [options] 91 * @return {CaptchaObj} 92 */ 93 export function create(options?: ConfigObject): CaptchaObj; 94 /** 95 * This method returns a object that has two props: 96 * data: svg image string 97 * text: captcha text 98 * note that this method generate a math expression 99 * this means that text is the result of the math expression 100 * @param {ConfigObject} [options] 101 * @return {CaptchaObj} 102 */ 103 export function createMathExpr(options?: ConfigObject): CaptchaObj; 104 /** 105 * Override the default font with your own 106 * @param {string} url 107 */ 108 export function loadFont(url: string): void; 109 /** 110 * captcha generation global setting 111 */ 112 export const options: ConfigObject; 113 /** 114 * return a random string 115 * @param {number} size 116 * @return {string} 117 */ 118 export function randomText(size: number): string;