← All tools

@stacksjs/ts-faker

Popularity 65 Updated Development & Build

ts-mocker is a performance-focused and lightweight faker/data mocking library for TypeScript.

npmauto-collected

Installation

npm
npm install -g @stacksjs/ts-faker

Install with npm.

<p align="center"<img src=".github/art/cover.jpg" alt="Social Card of this repo"</p

ts-mocker

A performance-focused and lightweight faker library for TypeScript with comprehensive locale support.

Features

  • ⚡️ Performance-focused - Built with speed and efficiency in mind
  • 🌍 Multi-locale Support - Complete translations for 28 languages with 22+ regional variants:
  • Afrikaans (af), Arabic (ar), Azerbaijani (az), Czech (cs), Danish (da), German (de), English (en), Esperanto (eo), Spanish (es), Persian/Farsi (fa), Finnish (fi), French (fr), Hebrew (he), Hindi (hi), Italian (it), Japanese (ja), Korean (ko), Dutch (nl), Norwegian (no), Polish (pl), Portuguese (pt), Swedish (sv), Filipino (tl), Turkish (tr), Ukrainian (uk), Chinese Simplified (zh-cn), Chinese Traditional (zh-tw), Zulu (zu)
  • Plus regional variants: en-us, en-gb, en-ca, en-ie, en-in, en-za, en-gh, en-ng, en-hk, fr-ca, fr-ch, fr-be, fr-lu, fr-sn, de-at, de-ch, es-mx, pt-mz, af-za, zu-za, and more!
  • 📦 Lightweight - Minimal dependencies and small bundle size
  • 💪 Fully Typed - Written in TypeScript with comprehensive type definitions
  • 🎯 Comprehensive Data - 16+ data categories including:
  • Person (names, job titles, genders)
  • Address (streets, cities, countries)
  • Company (names, industries, buzzwords)
  • Internet (emails, domains)
  • Phone numbers (numbers)
  • Food (dishes, ingredients, cuisines)
  • Animals (dogs, cats, birds, fish, etc.)
  • Sports (teams, athletes)
  • Music (genres, artists, songs)
  • Commerce (products, colors, materials)
  • Books (titles, authors, publishers)
  • Vehicles (manufacturers, models, types)
  • Words (adjectives, verbs, nouns, etc.)
  • Hacker/Tech (abbreviations, phrases)
  • System (file names, file types)
  • Science (elements, units, constants)

Installation

# npm
npm install ts-mocker

# pnpm
pnpm add ts-mocker

# bun
bun add ts-mocker

# yarn
yarn add ts-mocker

Usage

Basic Usage

import { faker } from 'ts-mocker'

// Generate random data with default locale (English)
const name = faker.person.fullName()
const email = faker.internet.email()
const address = faker.address.city()

console.log(name) // "John Doe"
console.log(email) // "john.doe@example.com"
console.log(address) // "New York"

Advanced Features

ts-mocker includes powerful advanced data generation features:

import { faker, globalProviderRegistry, ValidationRules, WeightedSelections } from 'ts-mocker'

// Conditional generation with constraints
const maleName = faker.person.firstNameAdvanced({
  constraints: { gender: 'male' }
})

// Weighted selection for realistic distribution
const commonName = faker.person.firstNameAdvanced({
  weighted: WeightedSelections.commonFirstNames
})

const validatedName = faker.person.firstNameAdvanced({ validation: { rules: [{ validator: ValidationRules.name }], strict: false } })

// Realistic relationships const family = faker.person.family({ constraints: { country: 'United States' }, size: 4 }) const customProvider = { name: 'Tech Company Generator', category: 'company', version: '1.0.0', generate: () = 'Cloud Tech Solutions' } globalProviderRegistry.register(customProvider)