Download the PHP package bert-w/typomaniac without Composer
On this page you can find all versions of the php package bert-w/typomaniac. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Please rate this library. Is it a good library?
Informations about the package typomaniac
bert-w/typomaniac
A library that creates deliberate spelling mistakes/typos for you.
Installation instructions
composer require bert-w/typomaniac
Quick start
Code Samples
It has a convenient __toString() method to get the actual string output:
$result also has more properties that could be useful:
Explanation of the various Mistake types
CharacterAccents: Make a mistake for misentered accent characters.ü => "u || u".CharacterRepeat: Repeat a character.a => aaCharactersFlip: Flip a character with the previous one.af => faCharacterSkip: Skip a key stroke (simply returns an empty string).a => (empty)KeyboardTypo: Choose a random key that is physically near another key on a QWERTY keyboard.a => qCharacterChangeCapitalization: Change the character capitalization to either lower or uppercase.A => a
Adding your own mistake type
Before trying to add your own mistake class, please read the Inner workings below first.
To add your own spelling mistake, simply create a class and extend it from BertW\Typomaniac\Mistakes\Mistake. See the
source code for examples.
Inner workings
- Typomaniac loops your input string one character at a time.
- Per each character, the
$chanceproperty is used to determine whether a mistake should take place. - Once this happens, one of the
Mistakeclasses is randomly chosen as the current active Mistake. - As long as the
Mistake->end()function returnsfalse, it will continue to push characters to the Mistakeinput. This allows us to send a substring of arbitrary length of the input to the Mistake class. For instance, theCharactersFlipclass expects 2 characters and returns the 2 characters but flipped. - Once the
Mistake->end()function returnstrue, the Mistake class is asked to make a mistake on the received input. i.e.CharactersFlipwould return'af'for a given input string'fa'. - The loop is continued, so a new Mistake can take place (or the end is reached, in which case, it stops).
All versions of typomaniac with dependencies
PHP Build Version
Package Version
Requires
php Version
>=5.6.0
ext-mbstring Version *
ext-mbstring Version *
The package bert-w/typomaniac contains the following files
Loading the files please wait ...