randino for Dart
π randino.cdget.com
Every option and every example, with Dart picked in the sidebar. This README is just the quick start.
randino generates random person names and nicknames in the language you ask for.
- Person names read like names people actually carry β κΉλ―Όμ€, Emma Clover, ΠΠ²Π°Π½ΠΎΠ² ΠΠ²Π°Π½ β and come with their English pronunciation. 9 languages.
- Nicknames are the handles you would pick for a game or a website β λ©μ§μ¬μ, MistyOwl, κ³ μμ΄κΌ¬λ¦¬. Built from everyday words across fourteen themes, never from person names.
- Words are those fourteen themes on their own β
randWord, plusrandAnimal,randFoodand twelve more. - Decorators attach something to a string you already have:
randSuffix,randPrefixandrandModifier. - Every parameter is named and optional, and a null enum means "every one of them" β
randName()on its own works. - Pure Dart, no dependencies. It imports nothing but
dart:math, so it runs on the VM, on the web and inside Flutter on every platform.
This is the Dart half. The npm package is the other one, and the two generate from the same datasets under the same rules. They version independently, so this package's number and the npm one's will not always agree.
Install
dart pub add randino
Requires Dart 3.7 or newer (Flutter 3.29). There is nothing else to install.
Person names
import 'package:randino/randino.dart';
randName();
// ['Emma Clover']
randName(language: NameLanguage.ko, count: 3);
// ['κΉνμ€', 'μλν', 'μ‘°μ§μ°']
randName(language: NameLanguage.ko, script: NameScript.roman);
// ['Kim Minjun']
randName(
language: NameLanguage.en,
gender: NameGender.female,
includeMiddleName: true,
);
// ['Grace Amelia Bennett']
randNameDetails(language: NameLanguage.ko).first;
// NameDetail(μ¬λ―Έμ£Ό, Yeo Miju, ko, female)
| Parameter | Type | Default |
|---|---|---|
language |
NameLanguage? |
null β every one |
gender |
NameGender? |
null β one per name |
count |
int |
1 |
style |
int (0 real β¦ 100 invented) |
0 |
minLength / maxLength |
int? |
language |
includeSurname |
bool |
true |
includeMiddleName |
bool |
false |
script |
NameScript |
NameScript.native |
startsWith |
String? |
null |
unique |
bool |
false |
randNameDetails takes the same parameters except script, and returns a NameDetail β native, roman, language and gender β for each name.
Nicknames
randNickname(language: WordLanguage.ko, count: 3);
// ['μ€λλκ³°', 'μμνλλ§λ±', 'κ·μ¬μ΄μ νλ€λ°']
randNickname(language: WordLanguage.en, count: 2);
// ['FoggyHillside', 'CraneVoyage']
randNickname(language: WordLanguage.ko, theme: WordTheme.animal, count: 2);
// ['κΉμμ°μ΄', 'νμμ¬μ°κ°κΈ°']
randNicknameDetails(language: WordLanguage.ko).first;
// NicknameDetail(μ€λλλ°κ²¬, [μ€λλ, λ°κ²¬], ko, concept)
| Parameter | Type | Default |
|---|---|---|
language |
WordLanguage? |
null β every one |
theme |
WordTheme? |
null β every one |
count |
int |
1 |
style |
int (0 real β¦ 100 invented) |
0 |
minLength / maxLength |
int? |
language |
wordSeparator |
String? |
language |
startsWith |
String? |
null |
unique |
bool |
false |
Themes: animal, object, nature, plant, gem, concept, myth, job, music, place, food, sport, vehicle, product.
Words
The pools the nicknames are built from, on their own. Fourteen themes, four languages, and a function per theme.
randWord(language: WordLanguage.ko, theme: WordTheme.animal, count: 3);
// [μ¬μ°, κ³ λ, μλ¬]
randAnimal(language: WordLanguage.en, count: 2); // [Otter, Falcon]
randFood(language: WordLanguage.ko, count: 2); // [λ‘λ³Άμ΄, λ
Ήμ°¨]
randWordDetails(language: WordLanguage.ko, theme: WordTheme.plant).first;
// WordDetail(λ―Όλ€λ , ko, plant)
wordLengthRange(language: WordLanguage.ko); // LengthRange(1, 4)
| Parameter | Type | Default |
|---|---|---|
language |
WordLanguage? |
null β every one |
theme |
WordTheme? |
null β every one |
count |
int |
1 |
style |
int |
0 |
minLength / maxLength |
int? |
pools |
startsWith |
String? |
null |
unique |
bool |
false |
One function per theme: randAnimal, randObject, randNature, randPlant, randGem, randConcept, randMyth, randJob, randMusic, randPlace, randFood, randSport, randVehicle, randProduct. They return List<String>; for the detail form, pass the theme to randWordDetails.
Decorators
randSuffix, randPrefix and randModifier attach something to a string you already have, rather than generating one. They take anything, not just this library's output, which is why none of them is a parameter on a generator β and each of them works with no value at all, handing back the thing it would have attached.
randSuffix(value: 'λ©μ§μ¬μ'); // 'λ©μ§μ¬μ_nVtRC'
randSuffixAll(randNickname(language: WordLanguage.ko, count: 2));
// [λ¬λ ₯_U7aNZ, μ‘°μ©νλ°κ΅¬λ_RUKAP]
randPrefix(value: 'order-4021', length: 4, separator: '-'); // 'k3Rm-order-4021'
randSuffix(value: 'MistyOwl', length: 8, charset: '0123456789'); // 'MistyOwl_40218836'
randSuffix(); // 'nVtRC' β the token on its own
| Parameter | Type | Default |
|---|---|---|
length |
int |
5 |
separator |
String |
'_' |
charset |
String? |
built-in |
A fresh token per value, never one for the batch. The default charset leaves out 0O1lI, because these end up in names people read aloud and type back in. The β¦All forms are Dart's answer to a signature the other two packages write as String | List<String>, and value is named rather than positional because Dart cannot make a positional parameter optional alongside named ones.
randModifier attaches a word instead of a token β what randNickname's includeModifier used to do, for any string:
randModifier(value: 'μ¬μ'); // 'λ©μ§μ¬μ'
randModifier(value: 'Owl', separator: ' '); // 'Misty Owl'
randModifier(); // 'λ©μ§'
randModifierAll(randAnimal(language: WordLanguage.ko, count: 2));
// [μ€λλκ³°, μμνλλ§λ±]
| Parameter | Type | Default |
|---|---|---|
value |
String? |
null |
language |
WordLanguage? |
script |
style |
int |
0 |
separator |
String? |
language |
With no language, the script of the value picks one, so 'κ³ μμ΄' is never handed an English modifier.
Helpers and constants
nameLengthRange(language: NameLanguage.ko); // LengthRange(3, 3)
nameLengthRange(language: NameLanguage.en, includeMiddleName: true); // LengthRange(12, 24)
nameSupportsMiddleName(NameLanguage.ko); // false
nameSupportsRoman(NameLanguage.en); // false
nicknameLengthRange(language: WordLanguage.ko); // LengthRange(1, 12)
nameLanguages, wordLanguages and wordThemes list what the generators accept; randCountMax, randLengthMin / Max, affixLengthDefault / Max, affixSeparatorDefault and affixCharset are the bounds and defaults every parameter is clamped to.
Differences from the npm package
The two generate the same output from the same data, and only the surface is Dart's rather than JavaScript's.
| npm | pub.dev |
|---|---|
| One options object | Named parameters |
language: 'ko' |
language: NameLanguage.ko |
language: 'all' (the default) |
language left out, or null |
[number, number] |
LengthRange, which compares by value |
NameDetail / NicknameDetail interfaces |
The same two names, as classes |
output: 'detail' |
randNameDetails / randNicknameDetails / randWordDetails |
randModifier('μ¬μ') |
randModifier(value: 'μ¬μ') β every parameter is named |
randSuffix(['a', 'b']) |
randSuffixAll(['a', 'b']) |
The last two are the same limitation twice: Dart has neither overloads nor union types, so one function cannot return List<String> for one argument and List<NameDetail> for another. Where npm and PyPI pick the shape with an option, pub.dev picks it with a second function.
Development
dart pub get
dart test
dart analyze
dart format .
License
MIT Β© CDGet
Libraries
- randino
- randino generates random person names and nicknames in the language you ask for.