From 4385c6d0e3747994c3deccc4545a3621bf7310dd Mon Sep 17 00:00:00 2001 From: Zion Ng Date: Mon, 25 Jul 2022 23:36:01 +0800 Subject: [PATCH] Update usage docs --- README.md | 49 ++++++++++++++++++++++++++++++++++++++++++++----- src/index.js | 4 ++++ 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 76089c6..6d46afd 100644 --- a/README.md +++ b/README.md @@ -27,11 +27,11 @@ repository. Shell commands, if any, are run from the root of the repository. - The difficulty level for solving the generated CAPTCHA is akin to a Level 3: + Level 1: Generate random text. User sees the shown text and keys in the shown text. Machine learning can easily be used to crack this. - + Level 2: Generate Math equation using numbers. User sees the shown text, - solves it and keys in the result. - + Level 3: Generate Math equation and spell out the numbers in English. - User sees the shown text, converts the words back to numbers, solves the - equation and keys in the result. + + Level 2: Generate random Math equation using numbers. User sees the shown + text, solves the equation and keys in the result. + + Level 3: Generate random Math equation and spell out the numbers in + English. User sees the shown text, converts the words back to numbers, + solves the equation and keys in the result. ## Font - The primary font bundled with this project in `assets/Marius1.ttf` is the @@ -40,6 +40,7 @@ repository. Shell commands, if any, are run from the root of the repository. and irregular glyphs. ## Usage +- See docblocks in `src/index.js` for detailed documentation. - Node.js: const OpenType = require('opentype.js'); @@ -70,6 +71,44 @@ repository. Shell commands, if any, are run from the root of the repository. })(); +- Constructor: `ZnJsCaptcha(OpenTypeJs, config)`. + + `OpenTypeJs`: Object returned by OpenType.js library. + + `config`: Configuration object used for generating CAPTCHA. + + { + // Colors + colorBackground: '#ffffff', + colorForeground: '#000000', + + // Font + fontPath: '../assets/Marius1.ttf', + fontSize: 50, + + // In "2 + 3", 2 is the augend and 3 is the addend + mathAugendMin: 10, + mathAugendMax: 99, + mathAddendMin: 1, + mathAddendMax: 9, + mathOperator: '+', + + // No. of lines/dots to add to output SVG as noise + noiseLines: 10, + noiseDots: 1000, + + // Dimensions of output SVG + outputWidth: 480, + outputHeight: 120, + } + +- Public methods: + + `generate()`: Async function that returns an object when the Promise is + resolved: + + { + data: '', + result: 28, + } + ## Installation - This section is meant for developers. - Clone this repository. diff --git a/src/index.js b/src/index.js index 1213ee4..cc7c61e 100644 --- a/src/index.js +++ b/src/index.js @@ -67,9 +67,11 @@ */ const self = { config: { + // Colors colorBackground: '#ffffff', colorForeground: '#000000', + // Font fontPath: '../assets/Marius1.ttf', fontSize: 50, @@ -80,9 +82,11 @@ mathAddendMax: 9, mathOperator: '+', + // No. of lines/dots to add to output SVG as noise noiseLines: 10, noiseDots: 1000, + // Dimensions of output SVG outputWidth: 480, outputHeight: 120, },