API reference
On this page 296
Every declaration below is extracted from zig-faker's source, with the doc comments as written there. A declaration listed without prose is public but undocumented in the source.
Root
Random
const Random = @import("random.zig").Random
locale
const locale = @import("locale.zig")
LocaleDefinition
const LocaleDefinition = locale.LocaleDefinition
locale_utils
const locale_utils = @import("locale_utils.zig")
LocaleInfo
const LocaleInfo = locale_utils.LocaleInfo
LocaleLoader
const LocaleLoader = @import("locale_loader.zig").LocaleLoader
locales
const locales = struct
en
const en = @import("locales/en.zig").en
en_AU
const en_AU = @import("locales/en_AU.zig").en_AU
en_CA
const en_CA = @import("locales/en_CA.zig").en_CA
en_GB
const en_GB = @import("locales/en_GB.zig").en_GB
en_GH
const en_GH = @import("locales/en_GH.zig").en_GH
en_HK
const en_HK = @import("locales/en_HK.zig").en_HK
en_IE
const en_IE = @import("locales/en_IE.zig").en_IE
en_IN
const en_IN = @import("locales/en_IN.zig").en_IN
en_NG
const en_NG = @import("locales/en_NG.zig").en_NG
en_US
const en_US = @import("locales/en_US.zig").en_US
en_ZA
const en_ZA = @import("locales/en_ZA.zig").en_ZA
es
const es = @import("locales/es.zig").es
es_ES
const es_ES = @import("locales/es_ES.zig").es_ES
es_MX
const es_MX = @import("locales/es_MX.zig").es_MX
de
const de = @import("locales/de.zig").de
de_AT
const de_AT = @import("locales/de_AT.zig").de_AT
de_CH
const de_CH = @import("locales/de_CH.zig").de_CH
de_DE
const de_DE = @import("locales/de_DE.zig").de_DE
fr
const fr = @import("locales/fr.zig").fr
fr_BE
const fr_BE = @import("locales/fr_BE.zig").fr_BE
fr_CA
const fr_CA = @import("locales/fr_CA.zig").fr_CA
fr_CH
const fr_CH = @import("locales/fr_CH.zig").fr_CH
fr_FR
const fr_FR = @import("locales/fr_FR.zig").fr_FR
fr_LU
const fr_LU = @import("locales/fr_LU.zig").fr_LU
fr_SN
const fr_SN = @import("locales/fr_SN.zig").fr_SN
pt
const pt = @import("locales/pt.zig").pt
pt_BR
const pt_BR = @import("locales/pt_BR.zig").pt_BR
pt_MZ
const pt_MZ = @import("locales/pt_MZ.zig").pt_MZ
pt_PT
const pt_PT = @import("locales/pt_PT.zig").pt_PT
zh
const zh = @import("locales/zh.zig").zh
zh_CN
const zh_CN = @import("locales/zh_CN.zig").zh_CN
zh_TW
const zh_TW = @import("locales/zh_TW.zig").zh_TW
af
const af = @import("locales/af.zig").af
af_ZA
const af_ZA = @import("locales/af_ZA.zig").af_ZA
zu
const zu = @import("locales/zu.zig").zu
zu_ZA
const zu_ZA = @import("locales/zu_ZA.zig").zu_ZA
it
const it = @import("locales/it.zig").it
nl
const nl = @import("locales/nl.zig").nl
ja
const ja = @import("locales/ja.zig").ja
ko
const ko = @import("locales/ko.zig").ko
uk
const uk = @import("locales/uk.zig").uk
pl
const pl = @import("locales/pl.zig").pl
sv
const sv = @import("locales/sv.zig").sv
no
const no = @import("locales/no.zig").no
da
const da = @import("locales/da.zig").da
fi
const fi = @import("locales/fi.zig").fi
cs
const cs = @import("locales/cs.zig").cs
tr
const tr = @import("locales/tr.zig").tr
ar
const ar = @import("locales/ar.zig").ar
he
const he = @import("locales/he.zig").he
hi
const hi = @import("locales/hi.zig").hi
az
const az = @import("locales/az.zig").az
eo
const eo = @import("locales/eo.zig").eo
fa
const fa = @import("locales/fa.zig").fa
tl
const tl = @import("locales/tl.zig").tl
parseLocale
const parseLocale = locale_utils.parseLocale
getLocaleFallbackChain
const getLocaleFallbackChain = locale_utils.getLocaleFallbackChain
freeLocaleFallbackChain
const freeLocaleFallbackChain = locale_utils.freeLocaleFallbackChain
detectSystemLocale
const detectSystemLocale = locale_utils.detectSystemLocale
mergeLocaleDefinitions
const mergeLocaleDefinitions = locale_utils.mergeLocaleDefinitions
isLocaleAvailable
const isLocaleAvailable = locale_utils.isLocaleAvailable
PersonOptions
const PersonOptions = @import("modules/person.zig").PersonOptions
FullNameOptions
const FullNameOptions = @import("modules/person.zig").FullNameOptions
StreetAddressOptions
const StreetAddressOptions = @import("modules/address.zig").StreetAddressOptions
Gender
const Gender = locale.Gender
ValidationMode
const ValidationMode = @import("modules/validation.zig").ValidationMode
ValidationResult
const ValidationResult = @import("modules/validation.zig").ValidationResult
ValidationRule
const ValidationRule = @import("modules/validation.zig").ValidationRule
ValidatorType
const ValidatorType = @import("modules/validation.zig").ValidatorType
ValidatorFn
const ValidatorFn = @import("modules/validation.zig").ValidatorFn
Faker
const Faker = struct
Main Faker struct providing access to all data generation modules
init
fn init(allocator: std.mem.Allocator, seed_value: ?u64, locale_def: ?*const LocaleDefinition) Faker
Initialize Faker with optional seed and locale
seed
fn seed(self: *Faker, seed_value: u64) void
Set a new seed for reproducible generation
setLocale
fn setLocale(self: *Faker, new_locale: *const LocaleDefinition) void
Set a new locale
Random
Random
const Random = struct
Random number generator with optional seeding support
init
fn init(seed: ?u64) Random
number
fn number(self: *Random) f64
Generate a random float between 0.0 and 1.0
int
fn int(self: *Random, min: i64, max: i64) i64
Generate a random integer in the range [min, max] inclusive
float
fn float(self: *Random, min: f64, max: f64) f64
Generate a random float in the range [min, max]
arrayElement
fn arrayElement(self: *Random, comptime T: type, array: []const T) T
Pick a random element from a slice
arrayElements
fn arrayElements(self: *Random, comptime T: type, allocator: std.mem.Allocator, array: []const T, count: usize) ![]T
Pick multiple random elements from a slice
shuffle
fn shuffle(self: *Random, comptime T: type, array: []T) void
Shuffle an array using Fisher-Yates algorithm
boolean
fn boolean(self: *Random, weight: f64) bool
Generate a random boolean with optional weight (0.0 to 1.0, default 0.5)
replaceSymbols
fn replaceSymbols(self: *Random, allocator: std.mem.Allocator, format: []const u8) ![]u8
Replace # with digits and ? with letters in a format string
hex
fn hex(self: *Random, allocator: std.mem.Allocator, length: usize) ![]u8
Generate a hexadecimal string of specified length
locale
Gender
const Gender = enum
PersonLocale
const PersonLocale = struct
AddressLocale
const AddressLocale = struct
CompanyLocale
const CompanyLocale = struct
InternetLocale
const InternetLocale = struct
PhoneLocale
const PhoneLocale = struct
FoodLocale
const FoodLocale = struct
AnimalLocale
const AnimalLocale = struct
LocaleDefinition
const LocaleDefinition = struct
locale_utils
LocaleInfo
const LocaleInfo = struct
Information about a parsed locale code
deinit
fn deinit(self: *LocaleInfo, allocator: std.mem.Allocator) void
parseLocale
fn parseLocale(allocator: std.mem.Allocator, locale: []const u8) !LocaleInfo
Parse a locale code into its components Supports both underscore (en_US) and hyphen (en-US) formats
Examples: parseLocale("en_US") -> { language: "en", region: "US", normalized: "en_US" } parseLocale("en-GB") -> { language: "en", region: "GB", normalized: "en_GB" } parseLocale("es") -> { language: "es", region: null, normalized: "es" }
getLocaleFallbackChain
fn getLocaleFallbackChain(allocator: std.mem.Allocator, locale: []const u8) ![][]const u8
Get the fallback chain for a locale Returns array of locale codes to try in order
Examples: getLocaleFallbackChain("en_US") -> ["en_US", "en"] getLocaleFallbackChain("es_MX") -> ["es_MX", "es"] getLocaleFallbackChain("en") -> ["en"]
freeLocaleFallbackChain
fn freeLocaleFallbackChain(allocator: std.mem.Allocator, chain: [][]const u8) void
Free memory allocated by getLocaleFallbackChain
detectSystemLocale
fn detectSystemLocale(allocator: std.mem.Allocator) ![]const u8
Detect system locale from environment variables Checks in order: LANG, LC_ALL, LC_MESSAGES, LANGUAGE Returns "en" as fallback if none found
mergeLocaleDefinitions
fn mergeLocaleDefinitions(
Merge two locale definitions Variant takes precedence over base for any defined fields
AVAILABLE_BASE_LOCALES
const AVAILABLE_BASE_LOCALES = [_][]const u8
Base locales available (excluding Russian per requirements)
AVAILABLE_LOCALE_VARIANTS
const AVAILABLE_LOCALE_VARIANTS = [_][]const u8
Available locale variants (region-specific)
isBaseLocale
fn isBaseLocale(locale: []const u8) bool
Check if a locale code is a supported base locale
isLocaleVariant
fn isLocaleVariant(locale: []const u8) bool
Check if a locale code is a supported locale variant
isLocaleAvailable
fn isLocaleAvailable(locale: []const u8) bool
Check if a locale is available (base or variant)
LocaleLoader
LocaleLoader
const LocaleLoader = struct
Locale loader with caching and fallback chain support
init
fn init(allocator: std.mem.Allocator) LocaleLoader
deinit
fn deinit(self: *LocaleLoader) void
load
fn load(self: *LocaleLoader, locale_code: []const u8) !*const LocaleDefinition
Load a locale by code, using cache if available
loadWithFallback
fn loadWithFallback(self: *LocaleLoader, locale_code: []const u8) !*const LocaleDefinition
Load a locale with fallback chain Tries each locale in the fallback chain until one is found
isCached
fn isCached(self: *LocaleLoader, locale_code: []const u8) bool
Check if a locale is cached
clearCache
fn clearCache(self: *LocaleLoader) void
Clear the cache
getCacheSize
fn getCacheSize(self: *LocaleLoader) usize
Get number of cached locales
getGlobalLoader
fn getGlobalLoader(allocator: std.mem.Allocator) *LocaleLoader
Get or initialize the global locale loader
deinitGlobalLoader
fn deinitGlobalLoader() void
Clean up the global locale loader
en
en
const en: LocaleDefinition = .
en_AU
en_AU
const en_AU: locale.LocaleDefinition = .
en_CA
en_CA
const en_CA: locale.LocaleDefinition = .
en_GB
en_GB
const en_GB: locale.LocaleDefinition = .
en_GH
en_GH
const en_GH: locale.LocaleDefinition = .
en_HK
en_HK
const en_HK: locale.LocaleDefinition = .
en_IE
en_IE
const en_IE: locale.LocaleDefinition = .
en_IN
en_IN
const en_IN: locale.LocaleDefinition = .
en_NG
en_NG
const en_NG: locale.LocaleDefinition = .
en_US
en_US
const en_US: locale.LocaleDefinition = .
en_ZA
en_ZA
const en_ZA: locale.LocaleDefinition = .
es
es
const es: locale.LocaleDefinition = .
es_ES
es_ES
const es_ES: locale.LocaleDefinition = .
es_MX
es_MX
const es_MX: locale.LocaleDefinition = .
de
de
const de: locale.LocaleDefinition = .
de_AT
de_AT
const de_AT: locale.LocaleDefinition = .
de_CH
de_CH
const de_CH: locale.LocaleDefinition = .
de_DE
de_DE
const de_DE: locale.LocaleDefinition = .
fr
fr
const fr: locale.LocaleDefinition = .
fr_BE
fr_BE
const fr_BE: locale.LocaleDefinition = .
fr_CA
fr_CA
const fr_CA: locale.LocaleDefinition = .
fr_CH
fr_CH
const fr_CH: locale.LocaleDefinition = .
fr_FR
fr_FR
const fr_FR: locale.LocaleDefinition = .
fr_LU
fr_LU
const fr_LU: locale.LocaleDefinition = .
fr_SN
fr_SN
const fr_SN: locale.LocaleDefinition = .
pt
pt
const pt: locale.LocaleDefinition = .
pt_BR
pt_BR
const pt_BR: locale.LocaleDefinition = .
pt_MZ
pt_MZ
const pt_MZ: locale.LocaleDefinition = .
pt_PT
pt_PT
const pt_PT: locale.LocaleDefinition = .
zh
zh
const zh: locale.LocaleDefinition = .
zh_CN
zh_CN
const zh_CN: locale.LocaleDefinition = .
zh_TW
zh_TW
const zh_TW: locale.LocaleDefinition = .
af
af
const af: locale.LocaleDefinition = .
af_ZA
af_ZA
const af_ZA: locale.LocaleDefinition = .
zu
zu
const zu: locale.LocaleDefinition = .
zu_ZA
zu_ZA
const zu_ZA: locale.LocaleDefinition = .
it
it
const it: locale.LocaleDefinition = .
nl
nl
const nl: locale.LocaleDefinition = .
ja
ja
const ja: locale.LocaleDefinition = .
ko
ko
const ko: locale.LocaleDefinition = .
uk
uk
const uk: locale.LocaleDefinition = .
pl
pl
const pl: locale.LocaleDefinition = .
sv
sv
const sv: locale.LocaleDefinition = .
no
no
const no: locale.LocaleDefinition = .
da
da
const da: locale.LocaleDefinition = .
fi
fi
const fi: locale.LocaleDefinition = .
cs
cs
const cs: locale.LocaleDefinition = .
tr
tr
const tr: locale.LocaleDefinition = .
ar
ar
const ar: locale.LocaleDefinition = .
he
he
const he: locale.LocaleDefinition = .
hi
hi
const hi: locale.LocaleDefinition = .
az
az
const az: locale.LocaleDefinition = .
eo
eo
const eo: locale.LocaleDefinition = .
fa
fa
const fa: locale.LocaleDefinition = .
tl
tl
const tl: locale.LocaleDefinition = .
PersonOptions
PersonOptions
const PersonOptions = struct
FullNameOptions
const FullNameOptions = struct
Person
const Person = struct
init
fn init(allocator: std.mem.Allocator, locale_def: *const LocaleDefinition) Person
firstName
fn firstName(self: *Person, random: *Random, options: PersonOptions) []const u8
Generate a random first name
lastName
fn lastName(self: *Person, random: *Random) []const u8
Generate a random last name
fullName
fn fullName(self: *Person, random: *Random, options: FullNameOptions) ![]u8
Generate a full name
prefix
fn prefix(self: *Person, random: *Random) []const u8
Generate a name prefix (Mr., Mrs., etc.)
suffix
fn suffix(self: *Person, random: *Random) []const u8
Generate a name suffix (Jr., Sr., etc.)
gender
fn gender(self: *Person, random: *Random) []const u8
Generate a random gender
jobTitle
fn jobTitle(self: *Person, random: *Random) []const u8
Generate a random job title
firstNameWeighted
fn firstNameWeighted(self: *Person, random: *Random, options: PersonOptions) ![]const u8
Generate a weighted first name (uses frequency data if available) Common names like "James" and "Mary" appear more frequently
lastNameWeighted
fn lastNameWeighted(self: *Person, random: *Random) ![]const u8
Generate a weighted last name (uses frequency data if available) Common surnames like "Smith" and "Johnson" appear more frequently
fullNameWeighted
fn fullNameWeighted(self: *Person, random: *Random, options: FullNameOptions) ![]u8
Generate a realistic full name using weighted selection
StreetAddressOptions
StreetAddressOptions
const StreetAddressOptions = struct
Address
const Address = struct
init
fn init(allocator: std.mem.Allocator, locale_def: *const LocaleDefinition) Address
streetName
fn streetName(self: *Address, random: *Random) []const u8
Generate a street name
buildingNumber
fn buildingNumber(self: *Address, random: *Random) ![]u8
Generate a building number
streetAddress
fn streetAddress(self: *Address, random: *Random, options: StreetAddressOptions) ![]u8
Generate a street address
city
fn city(self: *Address, random: *Random) []const u8
Generate a city name
state
fn state(self: *Address, random: *Random) []const u8
Generate a state name
stateAbbr
fn stateAbbr(self: *Address, random: *Random) []const u8
Generate a state abbreviation
country
fn country(self: *Address, random: *Random) []const u8
Generate a country name
postalCode
fn postalCode(self: *Address, random: *Random) ![]u8
Generate a postal code
direction
fn direction(self: *Address, random: *Random) []const u8
Generate a direction (North, South, etc.)
fullAddress
fn fullAddress(self: *Address, random: *Random) ![]u8
Generate a full address
countryWeighted
fn countryWeighted(self: *Address, random: *Random) ![]const u8
Generate a weighted country name (uses population data if available) More populous countries like China and India appear more frequently
ValidationMode
ValidationMode
const ValidationMode = enum
Validation mode determines how strict validation should be
ValidationResult
const ValidationResult = struct
Validation result
deinit
fn deinit(self: *ValidationResult, allocator: std.mem.Allocator) void
ValidatorFn
const ValidatorFn = *const fn (value: []const u8) bool
Custom validator function type
ValidationRule
const ValidationRule = struct
Validation rule
Validation
const Validation = struct
Main validation module
init
fn init(allocator: std.mem.Allocator, mode: ValidationMode) Validation
validateEmail
fn validateEmail(value: []const u8) bool
Validate email address format
validateUrl
fn validateUrl(value: []const u8) bool
Validate URL format
validatePhone
fn validatePhone(value: []const u8) bool
Validate phone number (US format)
validateUuid
fn validateUuid(value: []const u8) bool
Validate UUID format
validateHexColor
fn validateHexColor(value: []const u8) bool
Validate hexadecimal color format (#RGB or #RRGGBB)
validateCreditCard
fn validateCreditCard(value: []const u8) bool
Validate credit card number using Luhn algorithm
validateIpv4
fn validateIpv4(value: []const u8) bool
Validate IPv4 address
validateIpv6
fn validateIpv6(value: []const u8) bool
Validate IPv6 address (simplified check)
validateNotEmpty
fn validateNotEmpty(value: []const u8) bool
Validate that string is not empty
validateMinLength
fn validateMinLength(value: []const u8, min_length: usize) bool
Validate minimum length
validateMaxLength
fn validateMaxLength(value: []const u8, max_length: usize) bool
Validate maximum length
validateLength
fn validateLength(value: []const u8, exact_length: usize) bool
Validate exact length
validateAlphanumeric
fn validateAlphanumeric(value: []const u8) bool
Validate that string contains only alphanumeric characters
validateAlphabetic
fn validateAlphabetic(value: []const u8) bool
Validate that string contains only alphabetic characters
validateNumeric
fn validateNumeric(value: []const u8) bool
Validate that string contains only numeric characters
validatePattern
fn validatePattern(value: []const u8, pattern: []const u8) bool
Validate that value matches a pattern (wildcard matching with * support) Supports: "prefix*", "suffix", "middle", "prepost", etc.
validateWithRules
fn validateWithRules(
Validate a value against multiple rules
validateCustom
fn validateCustom(
Validate using a custom validator function
validate
fn validate(
Quick validation helper for single validator
ValidatorType
const ValidatorType = enum
Built-in validator types