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 🙏

© 2025 – Pkg Stats / Ryan Hefner

mock-objects

v0.2.2

Published

A javascript/typescript library for mocking objects

Readme

mock-objects: A javascript/typescript library for mocking objects

This library includes full typings for projects that use typescript. An object/entity is immutable, so making any changes will return a new object/entity.

Built on top of object-recipes by simply re-exporting functions/types, in addition to providing some local utility functions.
Detailed usage can be found in the object-recipes repository.

Since this library doesn't really provide much in terms of api/utilities, it's main value proposition is the documentation itself.
Hopefully this can inspire you to structure your mock-data.

Installation

npm i mock-objects
yarn add mock-objects
bun add mock-objects

Usage

import { entity, Recipe, Shape } from 'mock-objects';

// Initialize the entity
const person = entity({
  name: '',
  age: 0,
  address: { street: '', zip: 0, country: '' },
  ...50_more_properties,
});

// Retrieve the plain object
person.get();

// Or retrieve a deep-clone of the plain object
person.getClone();

// To infer the type of the underlying object.
type PersonObject = Shape<typeof person>;

// Define a recipe for updating address. 
const addressRecipe = (
  street: string, zip: number, country: string
): Recipe<typeof person> => (entity) => entity.set(
  { address: { street, zip, country } }
);

// Use the recipe to udate address.
const recipeUpdate = person.recipe(
  addressRecipe('Teststreet 1', 1000, 'Norway')
);

// A mock-address recipe that re-uses the above recipe.
const testAddressRecipe = (): Recipe<typeof person> => (entity) =>
  entity.recipe(addressRecipe('Teststreet 1', 1000, 'Norway')); 

// Another mock-recipe that sets name/age.
const testNameAndAgeRecipe = (): Recipe<typeof person> => (entity) =>
  entity.set({ name: 'John Doe', age: 20 }); 

// A mock-recipe that utilizes the two recipes above.
const testPersonRecipe = (): Recipe<typeof person> => (entity) => 
  entity.recipe(testAddressRecipe()).recipe(testNameAndAgeRecipe());

const testResult = person.recipe(testPersonRecipe()) // Finally we run all the recipes
.get(); // and retrieve the resulting object 

// The idea is that you can create lots of different entity-objects with recipes, and
// then utilize these in for example mock-apis to provide test data.
// By using recipes you can easily simulate CRUD-operations.
// 
// You could also pass entity-objects directly to react-components, after applying the
// appropriate recipes.

Utils

Here are some util-functions provided by mock-objects itself, to generate random values.

import { randomNumber, randomHash, randomUuid, hash } from 'mock-objects';

// Generate a random number between 1-9999
// If you want a bigger/smaller range you can input your desired max-value as an argument. 
randomNumber();

// Generate a random hash with a length of 35 chars, using an insecure 32-bit algorithm.
randomHash();

// Generate a random Uuid v4. 
randomUuid();

// Generate a hash from your string, using an insecure 32-bit algorithm. 
// Hash length will always be 7 chars.
hash('some string to hash');