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

kitch

v1.3.0

Published

The Kitchen Pattern: Making POJO's easier

Downloads

53

Readme

kitch

A simple POJO creation pattern

NPM Version

Install

npm i kitch

What

This package provides a teeny-tiny set of utilities to create and populate simple POJOs.

I found myself repeating the same type of code over and over. I wanted a quicker way to do it that was less prone to human error.

Kitch runs off the assumption that you know how you want your POJOs to look... that is, you could provide a recipe for them. And that's where the name comes from: it's a recipe kitchen without the ennoying bits!

Usage

To use kitch you will need to create an interface of the POJO you want to use. You then create a Recipe<interface> of your interface. A recipe defines how to create one of your interface. It is not a function, it is an object of functions. This means you can mix, mash and extend recipes easily.

When you have a Recipe, create a new Kitchen<interface>. This will be an object of functions that can take overwrite data and produce a new instance of interface by utilizing one or your Recipes. You can quickly create a simple Kitchen by calling the kitch function.

With a kitchen created you can create a new POJO by simply calling .new(). You can pass additional data to the .new() function to overwrite the recipe.

Example

To truly utilize kitch you will need an interface of your POJO.

interface User {
    name: string
    age: number
    status: 'active' | 'disabled'
}

Now, provide a recipe of how to create one of your POJOs. A recipe is a typesafe object of functions that can create a valid instance of your interface. You'll even get typehinting.

const emptyRecipe: Recipe<User> = {
    age: () => 0, // number
    name: () => '', // string
    status: () => 'active', // 'active' | 'disabled'
}

Okay, so you have a recipe. Now you need a way to make it! Is that gonna be hard? Absolutely not:

export const UserKitchen: Kitchen<User> = {
    new: data => cook(data, emptyRecipe),
}


// ...

const myNewUser: User = UserKitchen.new()
const myNewUserWithName: User = UserKitchen.new({name: 'Sean'})
const myNewUserFromForm: User = UserKitchen.new({
    name: this.state.inputs.name
    age: this.state.inputs.age,
    /* in this one we still want to include default fields like
     * status without having to enter them manually all the time!
     * The recipe and kitchen will handle that for us.
     */
})

And that's it. Now you can generate your new User POJOs.

And if you will never need anything other than a single .new() function you can generate your kitchen even quicker with a single recipe:

export const UserKitchen = kitch(emptyRecipe)
const myNewUser = UserKitchen.new()

Now you have a UserKitchen, and can generate as many new Users as you want.

But, we haven't really got any of the juice out of this yet. The real benefit is when you want to quickly generate POJOs with different recipes. With the below example we can quickly define how to seed a random user and then quickly generate them.


const fakerRecipe: Recipe<User> = {
    ...emptyRecipe, // not needed in this example, but shows how you can quickly create extensible recipes
    age: generateRandomAge,
    name: generateRandomName,
    status: () => (Math.random() > 0.5 ? 'active' : 'disabled'),
}

export const UserKitchen: Kitchen<User> = {
    namedJohn: () => cook({ name: 'John' }, emptyRecipe),
    new: data => cook(data, emptyRecipe),
    seed: data => cook(data, fakerRecipe),
}

const mySeededUsers: User[] = [
    UserKitchen.namedJohn(),
    UserKitchen.seed(),
    UserKitchen.seed(),
    UserKitchen.seed({status: 'active'}), // Disregard the seeded value for status and set it to active
    UserKitchen.seed({status: 'disabled'}),
]