Comparing version 1.0.1 to 1.0.5
{ | ||
"name": "rcaptcha", | ||
"version": "v1.0.1", | ||
"version": "v1.0.5", | ||
"description": "rCaptcha Human Verification | by Swôth#9990 & Loiren#0555 & Roalia#0001", | ||
@@ -8,3 +8,4 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"build": "tsc" | ||
"build": "tsc", | ||
"test": "ts-node test/index.ts" | ||
}, | ||
@@ -11,0 +12,0 @@ "repository": { |
@@ -18,7 +18,8 @@ ## rCaptcha® | Human Verification | ||
```js | ||
import { rCaptcha } from 'rcaptcha'; // ESM | ||
const { rCaptcha } = require('rcaptcha') // CJS | ||
import { Captcha } from 'rcaptcha'; // ESM | ||
const { Captcha } = require('rcaptcha') // CJS | ||
const newCaptcha = new rCaptcha({ | ||
difficulty: "VERYHARD", // EASY, MEDIUM, HARD, VERYHARD is available... | ||
length: 10, //Length can be minimum 5, maximum 10. | ||
keywords: 'super-secret-keywords', // optional | ||
captcha: { | ||
@@ -37,5 +38,5 @@ backgroundColor: '#296CBC', | ||
{ | ||
difficulty: "HARD", | ||
difficulty: "VERYHARD", | ||
length: 10, | ||
code: "csf3#", // random | ||
code: "super-secret-keywords", // random | ||
response: { | ||
@@ -42,0 +43,0 @@ dataURL: "imageurl", |
import { IrCaptcha } from "./interfaces"; | ||
import Canvas from 'canvas'; | ||
export class rCaptcha implements IrCaptcha { | ||
export class Captcha implements IrCaptcha { | ||
public difficulty: IrCaptcha['difficulty']; | ||
public length: IrCaptcha['length']; | ||
public captcha?: IrCaptcha['captcha']; | ||
public keywords?: IrCaptcha['keywords']; | ||
constructor(rCaptcha: IrCaptcha) { | ||
@@ -12,2 +13,3 @@ this.difficulty = rCaptcha.difficulty; | ||
this.captcha = rCaptcha.captcha; | ||
this.keywords = rCaptcha.keywords; | ||
}; | ||
@@ -18,4 +20,5 @@ | ||
if (this.length > 10) throw new Error('Length must be less than 10'); | ||
if (this.keywords && this.keywords.length < 5) throw new Error('Keywords must be greater than 5.'); | ||
let captcha = generateCaptcha(this.difficulty, this.length); | ||
let captcha = generateCaptcha(this.difficulty, this.length, this.keywords); | ||
@@ -76,39 +79,48 @@ if (this.captcha?.backgroundImage) { | ||
function generateCaptcha(difficulty: 'KOLAY' | 'ORTA' | 'ZOR' | 'ÇOKZOR' | 'EASY' | 'MEDIUM' | 'HARD' | 'VERYHARD', length: number): string { | ||
function generateCaptcha(difficulty: 'KOLAY' | 'ORTA' | 'ZOR' | 'ÇOKZOR' | 'EASY' | 'MEDIUM' | 'HARD' | 'VERYHARD', length: number, isCustomKeywords?: string): string { | ||
let keywords; | ||
switch (difficulty) { | ||
case 'KOLAY': | ||
keywords = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
break; | ||
case 'ORTA': | ||
keywords = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
break; | ||
case 'ZOR': | ||
keywords = "01234567890123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
break; | ||
case 'ÇOKZOR': | ||
keywords = "!+#>-<@&%01234567890123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
break; | ||
case 'EASY': | ||
keywords = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
break; | ||
case 'MEDIUM': | ||
keywords = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
break; | ||
case 'HARD': | ||
keywords = "01234567890123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
break; | ||
case 'VERYHARD': | ||
keywords = "!+#>-<@&%01234567890123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
break; | ||
default: | ||
keywords = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
break; | ||
}; | ||
let captcha = ''; | ||
for (let i = 0; i < length; i++) { | ||
captcha += keywords.charAt(Math.floor(Math.random() * keywords.length)); | ||
}; | ||
return captcha; | ||
}; | ||
if (isCustomKeywords) { | ||
keywords = isCustomKeywords; | ||
let captcha = ''; | ||
for (let i = 0; i < length; i++) { | ||
captcha += keywords.charAt(Math.floor(Math.random() * keywords.length)); | ||
}; | ||
return captcha; | ||
} else { | ||
switch (difficulty) { | ||
case 'KOLAY': | ||
keywords = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
break; | ||
case 'ORTA': | ||
keywords = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
break; | ||
case 'ZOR': | ||
keywords = "01234567890123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
break; | ||
case 'ÇOKZOR': | ||
keywords = "!+#>-<@&%01234567890123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
break; | ||
case 'EASY': | ||
keywords = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
break; | ||
case 'MEDIUM': | ||
keywords = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
break; | ||
case 'HARD': | ||
keywords = "01234567890123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
break; | ||
case 'VERYHARD': | ||
keywords = "!+#>-<@&%01234567890123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
break; | ||
default: | ||
keywords = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
break; | ||
}; | ||
let captcha = ''; | ||
for (let i = 0; i < length; i++) { | ||
captcha += keywords.charAt(Math.floor(Math.random() * keywords.length)); | ||
}; | ||
return captcha; | ||
} | ||
}; |
@@ -6,2 +6,3 @@ import { Difficulty } from "src/utils"; | ||
length: number; | ||
keywords?: string; | ||
captcha?: { | ||
@@ -8,0 +9,0 @@ backgroundColor?: string; |
@@ -1,6 +0,7 @@ | ||
import { rCaptcha } from "../src"; | ||
import { Captcha } from "../src"; | ||
let cp = new rCaptcha({ | ||
let cp = new Captcha({ | ||
difficulty: "VERYHARD", | ||
length: 10, | ||
keywords: 'casgws!$½&/()=?^*+~#', | ||
captcha: { | ||
@@ -14,4 +15,4 @@ backgroundColor: "#E0E0E0", | ||
(async () => { | ||
let captcha = await cp.generate(); | ||
let captcha = await cp.generate(); | ||
console.log(captcha); | ||
})(); |
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
48
8815
9
173