npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

js-mock-object

v1.0.0

Published

A simple JavaScript library for generating mock objects with smart patterns and locale-aware data.

Readme

js-mock-object

The most intuitive, type-safe mock data generator for Node.js.

js-mock-object allows you to generate realistic test data using a clean, expressive builder API. It features localized dictionaries, smart address correlation, and technical generators for modern development.

✨ Features

  • 🧠 Type-safe API: Full TypeScript inference out of the box.
  • 🌍 Smart Addresses: Automatically correlates City, ZIP, and Country. Supports localized street patterns (e.g., "Lisa-Müller-Straße" vs "Church Square").
  • 📖 Dictionary Support: Real words and sentences via gen.word() (localized).
  • 🛠️ OCP Architecture: Every generator is a self-contained class, making it easy to extend.
  • 📦 Zero Dependencies: Tiny footprint, maximum speed.

📦 Installation

npm install js-mock-object

🧱 Builder API Reference

Primitive Types

  • gen.string(): Random alphanumeric string.
  • gen.int(): Random integer.
  • gen.float(): Random floating point number.
  • gen.bool(): Random boolean (true/false).
  • gen.uuid(): RFC4122 compliant UUID (do not use this UUID for productive use!).
  • gen.binary(): Random bit string (e.g., "10101100").
  • gen.rgb(): Random CSS-ready color string (e.g., "rgb(12, 255, 0)").

Date & Time

  • gen.date(): Returns a native JavaScript Date object.
  • gen.timestamp(): Returns a Unix timestamp in milliseconds.

Text & Dictionary (Locale-aware)

  • gen.word(): Returns a single real word from the localized dictionary.
  • gen.sentence(): Returns a chain of words built from random dictionary words.

Personal Data

  • gen.firstName(): A random first name.
  • gen.lastName(): A random last name.
  • gen.fullName(): Combines first and last name.
  • gen.email(): A random example email address.
  • gen.phone(): A localized phone number string.

Location (Smart & Correlated)

  • gen.address(countryCode?): Generates a full object:
    {
      street: string,  
      city: string,    
      zip: string,     
      country: string  
    }
    

🎯 Constraints

Chain methods to refine your requirements:

  • .min(number) / .max(number)
  • .length(number)
  • .oneOf([...values])

🚀 Examples

Standard Usage

import { mock, gen } from "js-mock-object";

const user = mock({
  id: gen.uuid(),
  name: gen.fullName(),
  email: gen.email(),
});

The "Everything" Mock

const bigMock = mock({
  id: gen.uuid(),
  binaryCode: gen.binary().length(12),
  themeColor: gen.rgb(),
  timestamp: gen.timestamp(),
  createdAt: gen.date(),
  appointment: gen.time(),
  user: {
    fullName: gen.fullName(),
    email: gen.email(),
    phone: gen.phone()
  },
  content: {
    favoriteWord: gen.word(),
    shortBio: gen.sentence(),
  },
  locationDe: gen.address("de"),
  locationJp: gen.address("jp"),
  settings: {
    age: gen.int().min(18).max(99),
    status: gen.string().oneOf(["active", "pending", "banned"]),
    tags: [gen.string().length(5)] 
  }
}, { locale: "de" });

console.log(JSON.stringify(bigMock, null, 2));

🔁 Deterministic Seeding

One of the core strengths of js-mock-object is its ability to produce consistent results. By providing a seed, the generator will always produce the exact same data in the same order. This is essential for:

  • 🧪 Reproducible Tests: Ensure your tests don't fail randomly.
  • 📸 Snapshot Testing: Keep your UI snapshots consistent.
  • 🐛 Bug Hunting: Recreate the exact dataset that caused an error.

How to use a Seed

Simply pass a seed (any number) into the mock options:

import { mock, gen } from "js-mock-object";

const schema = { id: gen.uuid(), name: gen.fullName() };

// This will always produce the same user
const userA = mock(schema, { seed: 12345 });
const userB = mock(schema, { seed: 12345 });

// userA and userB are now identical!