@autheur/generator
Random french sentence generator
Installation
npm i @autheur/generator
Usage
The core function is generate
: it permits to generate a sentence given a pattern
import { generate, determinant, noun, adverb, adjective } from '@autheur/generator';
const sentence = generate([determinant(), noun(), adverb(), adjective()]);
console.log(sentence);
Generators
A generator permits to define a portion of the sentence
determinant
Generate a determinant (un, une, le, les, cette, ...)
import { generate, determinant } from '@autheur/generator';
generate([determinant()]);
You can specify which types of determinant you want between undefined, defined, possessive, demonstrative
import { generate, determinant } from '@autheur/generator';
generate([determinant({ types: ['possessive'] })]);
noun
Generate a noun.
- the noun generated will impose its form (gender + plurality) to the rest of the sentence.
- by default the plurality is randomly chosen
import { generate, noun } from '@autheur/generator';
generate([noun()]);
You can force the plurality with a parameter
import { generate, determinant } from '@autheur/generator';
generate([noun({ isPlural: true })]);
generate([noun({ isPlural: false })]);
comma
Generate a comma.
import { generate, comma } from '@autheur/generator';
generate([comma()]);
adverb
Generate an adverb.
import { generate, adverb } from '@autheur/generator';
generate([adverb()]);
word
Generate an word that you specify.
import { generate, word } from '@autheur/generator';
generate([word('foobar')]);
You can specify if your word is preceded or followed by a space if their is another word
import { generate, word } from '@autheur/generator';
generate([word("l'", { noSpaceAfter: true }), word('arbre')]);
generate([word("l'"), word('arbre', { noSpaceBefore: true })]);
oneOf
Get a random word/sentence from a list that you specify.
import { generate, oneOf } from '@autheur/generator';
generate([oneOf(['foobar', 'yolo'])]);
Other packages
This is a from a monorepo with the following packages:
Credits
Coded with ❤️ by Corentin Thomasset.
License
This project is under the MIT license.