What is DataFaker?
Introduction
DataFaker is a mock data generator that is built on top of faker.js (as its underlying dependency). It extends faker.js with template syntax and decorator syntax, enabling you to quickly define various types of data models and generate scenario-specific data—including referenced data and recursive data. This meets your data generation needs across different scenarios. It is particularly suitable for the following use cases:
- Mock data for front-end development
- Unit testing and integration testing
- API interface prototyping
- Database sample data generation
- Demonstration and teaching use cases
Features
- Non-intrusive:
DataFakeronly enhancesfaker.jswithout making modifications to it. You can still usefaker.jsthe way you did before. - Template syntax:
DataFakerdefines data structures in the form of templates, similar to defining database table structures. Each data template is aschema. - Model-oriented:
DataFakerencapsulates templates into models, using models as the basic unit. It provides a model reuse mechanism, allowing your data templates to be reused at minimum cost. - Context mechanism:
DataFakeradopts a context mechanism to maintain the correlation between different data points. - Multi-language support: Leveraging the underlying capabilities of
faker.js,DataFakersupports more than 70 language environments and multiple configuration methods. - Multi-data source: With the help of
faker.js's underlying database,DataFakerhas 26 preset categories covering over 300 types of data. - Hook functions:
DataFakerprovides four types of hook functions, allowing you to modify the way data is generated during the data generation process. - Configurable:
DataFakersupports multiple personalized configuration methods.
Database
By leveraging faker.js's underlying database, DataFaker can generate data across 26 categories, including animals, books, and more. The following example shows flight information data:
// Airline Module
'airline.aircraftType'
'airline.airline'
'airline.airplane'
'airline.airport'
'airline.flightNumber'
'airline.recordLocator'
'airline.seat'For more preset data, please refer to the API (Note: The original Chinese path "/zh/预设数据.md" is adjusted to the English path convention here; retain the original path if the English version uses the same Chinese path)
Language Environments
Benefiting from faker.js's robust language environment support, DataFaker currently supports more than 70 language environments. For details, please refer to the Multi-language Section (Note: Similarly, the path is adjusted to the English path convention; keep the original if the English documentation uses the Chinese path)