Skip to content

text()

Creates a TextFaker. Default: random alphanumeric string, length [1, 20].

Mixins: Excludable, Measurable, Nullable, Seedable

For semantic strings (names, emails, cities), see semantic domains.

Length

MethodDescriptionExample
.length(n)Exact lengthtext().length(10)
.minLength(n)Minimum lengthtext().minLength(5)
.maxLength(n)Maximum lengthtext().maxLength(20)

Charset

MethodDescriptionExample
.alpha()Letters onlytext().alpha()
.alphanumeric()Letters + digits (default)text().alphanumeric()
.digits()Digits onlytext().digits().length(6)"048271"
.lowercase()Force lowercasetext().alpha().lowercase()
.uppercase()Force uppercasetext().alpha().uppercase()
.fromCharacters(chars)Custom charsettext().fromCharacters('abc123')

Identifiers

MethodDescriptionExample
.uuid()UUID v4text().uuid()"550e8400-..."
.ulid()ULIDtext().ulid()
.nanoid(size?)NanoID (default 21)text().nanoid()
.cuid()CUIDtext().cuid()
.objectId()MongoDB ObjectIdtext().objectId()
.slug()URL-safe slugtext().slug()

Pattern

MethodDescriptionExample
.regex(pattern)Match a regextext().regex(/[A-Z]{3}-\d{4}/)
.template(str)Template with placeholderstext().template('user-')

Exclusion

MethodDescriptionExample
.not(v)Exclude value(s)text().not(['admin', 'root'])

← Back to Faker API