Version v2.2.0 Size 9.8 KB gzip
Why Illusionist?
Illusionist generates realistic fake data from a single seeded random source. The same seed always produces the same output, so test fixtures and snapshots stay reproducible across runs, machines, and CI. Every category shares one bound instance with one locale, so a person, their email, and their address stay internally consistent.
ts
// Before
const user = {
name: 'Test User',
email: 'test@example.com',
address: '123 Main St',
};
// After
import { createIllusion } from '@vielzeug/illusionist';
import { en } from '@vielzeug/illusionist/locales';
const illusion = createIllusion({ seed: 12345, locale: en });
const user = {
name: illusion.person.fullName(),
email: illusion.internet.email(),
address: illusion.location.streetAddress(),
};
illusion.dispose();| Feature | Illusionist | Faker.js | @faker-js/faker |
|---|---|---|---|
| Bundle size | 9.8 KB | External dependency | External dependency |
| Zero external dependencies | |||
| Seeded determinism | Partial | ||
| Locale-aware datasets | |||
| TypeScript-native types |
Use Illusionist when test fixtures, mock APIs, or database seeds must be realistic and reproducible from a single seed value.
Consider @faker-js/faker when you need a large catalog of locale datasets beyond en and de or a community plugin ecosystem.
Installation
sh
pnpm add @vielzeug/illusionistsh
npm install @vielzeug/illusionistsh
yarn add @vielzeug/illusionistQuick Start
Create a bound instance with a seed and locale. All categories share that seed, so output is deterministic.
ts
import { createIllusion } from '@vielzeug/illusionist';
import { en } from '@vielzeug/illusionist/locales';
const illusion = createIllusion({ seed: 12345, locale: en });
illusion.person.fullName(); // 'Ashley Harris'
illusion.internet.email(); // 'samantha.sanchez@mail.com'
illusion.commerce.price(); // Money { amount: 76640n, currency: USD }
illusion.date.past({ years: 2 }); // Temporal.ZonedDateTime
illusion.dispose(); // release the instance; [Symbol.dispose]() also worksFeatures
person: names, gender, prefixes, suffixes, job titlesinternet: emails, usernames, passwords, URLs, IPs, MACs, HTTP metadatacommerce: product names, departments, prices as coinsMoneydate: past, future, recent, between, birthday as tempoTemporalobjectsfinance: amounts, IBANs, BICs, credit cards, crypto addresseslocation: cities, streets, states, countries, GPS coordinateslorem: words, sentences, paragraphs, slugssystem: file paths, semver, UUIDs, ports, cron expressions