Functions
learn
An alias for learnRight.
learnRight
Teaches the generator a new word (left -> right).
Syntax
randomTextGenerator.learn(example, origin, multiplier, isRaw);
// or
randomTextGenerator.learnRight(example, origin, multiplier, isRaw);
example - string or array of strings
origin - optional, string, by default "_default"
Specifies the origin of a word.
multiplier - optional, number, by default 1
The importance of this example.
isRaw - optional, boolean, by default false
If true the input is not treated like a word, but rather like a part of a word.
Returns nothing.
Example
randomTextGenerator.learnRight("Mark");
randomTextGenerator.learnRight("Henry");
randomTextGenerator.learnRight("Bob");
randomTextGenerator.learnRight("John");
randomTextGenerator.learn("David"); // learn is an alias for learnRight.
randomTextGenerator.learn("James");
for (let i=0; i<8; ++i) {
let name=randomTextGenerator.generate();
console.log(name);
}
// Jamen
// Mary
// Jark
// Job
// Bohn
// Dark
// John
// Jamen
// You can also provide starting letters
for (let i=0; i<4; ++i) {
let name=randomTextGenerator.generate("J");
console.log(name);
}
// Job
// Jary
// Javid
// James
learnLeft
Teaches the generator a new word (right -> left).
Syntax
randomTextGenerator.learnLeft(example, origin, multiplier, isRaw);
example - string or array of strings
origin - optional, string, by default "_default"
Specifies the origin of a word.
multiplier - optional, number, by default 1
The importance of this example.
isRaw - optional, boolean, by default false
If true the input is not treated like a word, but rather like a part of a word.
Returns nothing.
Example
randomTextGenerator.learnLeft("Mark");
randomTextGenerator.learnLeft("Henry");
randomTextGenerator.learnLeft("Bob");
randomTextGenerator.learnLeft("John");
randomTextGenerator.learnLeft("David");
randomTextGenerator.learnLeft("James");
for (let i=0; i<4; ++i) {
let name=randomTextGenerator.generateLeft();
console.log(name);
}
// David
// Henry
// Jark
// Bob
// All the names are going to end with "k"
for (let i=0; i<4; ++i) {
let name=randomTextGenerator.generateLeft("k");
console.log(name);
}
// Dark
// Bohnrk
// Henrk
// Jark
for (let i=0; i<4; ++i) {
let name=randomTextGenerator.generateLeft("y");
console.log(name);
}
// Johnry
// Bohnry
// Jary
// Dary
learnBoth
Calls both learnRight and learnLeft.
Syntax
randomTextGenerator.learnBoth(example, origin, multiplier, isRaw);
example - string or array of strings
origin - optional, string, by default "_default"
Specifies the origin of a word.
multiplier - optional, number, by default 1
The importance of this example.
isRaw - optional, boolean, by default false
If true the input is not treated like a word, but rather like a part of a word.