Socket
Socket
Sign inDemoInstall

svg-captcha

Package Overview
Dependencies
2
Maintainers
2
Versions
33
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.3.12 to 1.4.0

5

HISTORY.md

@@ -0,1 +1,6 @@

1.4.0 / 2019-05-03
===================
* Fixed #33 https://github.com/lemonce/svg-captcha/pull/33
1.3.11 / 2017-08-23

@@ -2,0 +7,0 @@ ===================

@@ -54,2 +54,18 @@ /**

background?: string;
/**
* default: +
* the math operator to use, "+", "-" or "+/-"
* if unknown operator passed defaults to "+/-"
*/
mathOperator?: string;
/**
* default: 1
* min value of the math expression
*/
mathMin?: number;
/**
* default: 9
* max value of the math expression
*/
mathMax?: number;
}

@@ -56,0 +72,0 @@ /**

2

lib/index.js

@@ -79,3 +79,3 @@ 'use strict';

const createMathExpr = function (options) {
const expr = random.mathExpr();
const expr = random.mathExpr(options.mathMin, options.mathMax, options.mathOperator);
const text = expr.text;

@@ -82,0 +82,0 @@ const data = createCaptcha(expr.equation, options);

@@ -47,13 +47,35 @@ 'use strict';

const mathExprPlus = function(leftNumber, rightNumber){
const text = (leftNumber + rightNumber).toString();
const equation = leftNumber + '+' + rightNumber;
return {text, equation}
}
const mathExprMinus = function(leftNumber, rightNumber){
const text = (leftNumber - rightNumber).toString();
const equation = leftNumber + '-' + rightNumber;
return {text, equation}
}
/**
* Returns an object that has the following props:
* text, equation
* Creates a simple math expression using either the + or - operator
* @param {number} [min] - The min value of the math expression defaults to 1
* @param {number} [max] - The max value of the math expression defaults to 9
* @param {string} [operator] - The operator(s) to use
* @returns {{equation: string, text: string}}
*/
exports.mathExpr = function () {
const left = randomInt(1, 9);
const right = randomInt(1, 9);
const text = (left + right).toString();
const equation = left + '+' + right;
return {text, equation};
exports.mathExpr = function (min, max, operator) {
min = min || 1;
max = max || 9;
operator = operator || '+';
const left = randomInt(min, max);
const right = randomInt(min, max);
switch(operator){
case '+':
return mathExprPlus(left, right)
case '-':
return mathExprMinus(left, right)
default:
return (randomInt(1, 2) % 2) ? mathExprPlus(left, right) : mathExprMinus(left, right);
}
};

@@ -60,0 +82,0 @@

{
"name": "svg-captcha",
"version": "1.3.12",
"version": "1.4.0",
"description": "generate svg captcha in node.js or express.js",

@@ -23,4 +23,3 @@ "main": "index.js",

"name": "Weilin Shi",
"email": "934587911@qq.com",
"url": "weilinshi.org"
"email": "934587911@qq.com"
},

@@ -27,0 +26,0 @@ "engines": {

@@ -63,7 +63,11 @@ ![svg-captcha](media/header.png)

#### `svgCaptcha.createMathExpr(options)`
Similar to create api, you have the same options and return value.
The difference is that data is a svg will be an math equation on screen
and text will be the result of that equation in string, otherwise the usage
is the same as above.
Similar to create api, you have the above options plus 3 additional:
* `mathMin`: 1 // the minimum value the math expression can be
* `mathMax`: 9 // the maximum value the math expression can be
* `mathOperator`: + // The operator to use, `+`, `-` or `+-` (for random `+` or `-`)
This function returns an object that has the following property:
* `data`: string // svg of the math expression
* `text`: string // the answer of the math expression
#### `svgCaptcha.loadFont(url)`

@@ -70,0 +74,0 @@ Load your own font and override the default font.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc