spellText function

String? spellText(
  1. String text, {
  2. String? language,
  3. bool vertical = true,
  4. List<String>? variants,
  5. int? seed,
})

Spells full text, spelling each token and joining results with spaces. Returns null if any token cannot be spelled.

A single seeded rng is shared across tokens so the whole text spells deterministically.

Implementation

String? spellText(
  String text, {
  String? language,
  bool vertical = true,
  List<String>? variants,
  int? seed,
}) {
  final rng = seed != null ? Random(seed) : null;
  final spellings = [
    for (final token in tokenize(text))
      spell(token,
          language: language, vertical: vertical, variants: variants, rng: rng)
  ];
  if (spellings.any((s) => s == null)) return null;
  return spellings.join(' ');
}