- Introduction
- Key Features
- ๐ Usage and Documentation
- ๐ Modules
- Consuming the library with CMake
- โ๏ธ Compiler support
- Dependencies
- ๐ฆ Building the library with Conan
- Installing the library with Conan
- Building the library with Bazel
- โจ Contributing
- ๐ Credits
- Examples
- ๐ Changelog
- ๐ License
Faker C++ is a C++ library inspired by the popular Faker.js, aimed at providing developers with a robust tool for generating fake (but realistic) data. Whether you're building test suites, populating databases, or creating demos, Faker C++ has got you covered.
๐ Realistic Data Generation: Generate various types of data including names, addresses, emails, dates, and more.
๐ Modular Design: Choose from a wide range of modules like Internet, Location, String, Date, and more to generate specific types of data.
๐ Easy Integration: Seamlessly integrate with CMake, and it supports major compilers like MSVC, GCC, Clang, and Apple Clang.
To properly use Faker C++ you must first consume the Faker library (see Consuming Library with CMake).
Once that is done, you need to include the proper header file
depending on the module you wish to generate data from or use general include file faker-cxx/faker.h
.
All the docs can be found here.
Below is an example of how to use Faker C++ in your code.
#include <iostream>
#include "faker-cxx/faker.h" // or include specific module
int main()
{
const auto id = faker::string::uuid();
const auto email = faker::internet::email();
const auto password = faker::internet::password();
const auto city = faker::location::city();
const auto streetAddress = faker::location::streetAddress();
const auto bornDate = faker::date::birthdateByYear(1970, 2000);
std::cout << id << std::endl; // 59990db5-3a5f-40bf-8af0-7834c29ee884
std::cout << email << std::endl; // hills.rita@gmail.com
std::cout << password << std::endl; // Mf+*[(_'lHfM.$v{
std::cout << city << std::endl; // Rochester
std::cout << streetAddress << std::endl; // 643 Ricardo Creek
std::cout << bornDate << std::endl; // 1973-12-03T11:07:02Z
return 0;
}
- ๐ฉ Airline - aircraft types, airlines, airports, flight numbers
- ๐ผ Animal - animal types and species
- ๐ Book - book title, genre, author, publisher, ISBN
- ๐จ Color - color names, rgb, hex, hcl
- ๐ Commerce - commerce department, product name, sku, price
- ๐ข Company - company name, type, industry, catchphrase, buzz phrase
- ๐ฅ๏ธ Computer - type, manufacturer, model, CPU info, GPU info
- ๐ Crypto - sha256, md5
- ๐พ Database - column names, column types, database engines
- โน๏ธ Datatype - booleans
- ๐ Date - past, future dates
- ๐ฆ Finance - currency, IBAN, BIC, account name, account number, pin, credit card numbers
- ๐ Food - food category, vegetables, fruits, meats, dishes
- ๐ Git - branch names, commit messages, commit hash
- ๐จโ๐ป Hacker - hacker words
- โ Helper - random element from container
- ๐ Internet - emails, usernames, passwords, IP, HTTP
- ๐ผ๏ธ Image - images urls, github avatar urls, image dimensions
- ๐ Location - countries, cities, zip codes, street addresses
- ๐ Lorem - lorem words, sentences, paragraphs
- ๐ฅ Medicine - conditions, medical tests, specialties
- ๐ฅ Movie - actors, actresses, genres, movie titles
- ๐ถ Music - artists, song names, genres
- ๐ข Number - random integers, floating point numbers
- ๐ง Person - first, last names, job titles, hobby, genders, sex, nationality, language
- ๐ Phone - phone number, IMEI
- ๐ชด Plant - plant type, trees, flowers
- โฝ Sport - sport names, athletes, events
- ๐ข String - uuids, alphanumeric, numeric, hexadecimal
- ๐ป System - file paths, file extensions, file names, directories, semantic version
- ๐ Vehicle - vehicle types, makes, models, fuel types, license plates
- ๐ฎ Video game - title, genre, platform, studio
- ๐ค๏ธ Weather - temperature, pressure, humidity, weather description
- ๐ฌ Word - sample words, nouns, verbs
-
Add faker to git submodules (execute in project root):
mkdir externals && cd externals git submodule add https://github.com/cieslarmichal/faker-cxx.git git submodule update --init --recursive
-
Link with library:
set(BUILD_TESTING OFF) add_subdirectory(externals/faker-cxx) add_executable(main Main.cpp) target_link_libraries(main faker-cxx)
- MSVCโ version 143 or newer.
- GCCโ version 12 or newer.
- Clangโ version 16 or newer.
- Apple Clangโ version 16 or newer.
- GTest (set
BUILD_TESTING=OFF
CMake flag to disable this dependency) - fmt (only for compilers that don't support std::format)
In order to use external dependencies installed in your system, you can set the USE_SYSTEM_DEPENDENCIES
CMake flag
to ON
.
๐ฆ Building the library with Conan
The library can be built using Conan package manager to solve external dependencies. To build the library with Conan, follow the steps below:
-
Install required dependencies:
conan install conanfile.txt --build=missing
-
Build the library:
cmake --preset=conan-release -DUSE_SYSTEM_DEPENDENCIES:BOOL=ON cmake --build --preset=conan-release
Installing the library with Conan
You can install pre-built binaries for faker-cxx or build it from source using Conan. Use the following command:
conan install --requires="faker-cxx/[*]" --build=missing
The faker-cxx Conan recipe is kept up to date by Conan maintainers and community contributors. If the version is out of date, please create an issue or pull request on the ConanCenterIndex repository.
Building the library with Bazel
As alternative, this project can be built using Bazel. The dependencies are managed directly by Bazel modules, downloading and building all external dependencies. Follow the steps below to build the project:
-
Navigate to the project directory:
cd /path/to/faker-cxx
-
Build the project:
bazel build //:faker-cxx
We would love it if you contributed to Faker C++! ๐
Check our guides on how to build the project locally:
Please make sure to read the Contributing Guide before making a pull request.
Additionally, we encourage you to join our Discord Channel for contributors.
Thanks to all the people who already contributed to Faker!
This project offers examples to demonstrate how to use the Faker C++ library. These examples can be found in the examples folder of the project repository. The examples showcase various modules of the library and provide code snippets that illustrate how to generate fake data using Faker C++.
Detailed changes for each release are documented in the release notes.
This project is under MIT license.