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

@itrocks/edit

v0.1.0

Published

Generic action-based object edit form in HTML and JSON

Readme

npm version npm downloads GitHub issues discord

edit

Generic action-based object edit form in HTML and JSON.

This documentation was written by an artificial intelligence and may contain errors or approximations. It has not yet been fully reviewed by a human. If anything seems unclear or incomplete, please feel free to contact the author of this package.

Installation

npm i @itrocks/edit

Usage

@itrocks/edit provides a generic Edit action that renders a form to view and update an existing domain object in HTML or JSON.

You typically:

  1. Define a domain class (for example User).
  2. Attach an Edit<User> action to this class.
  3. Use the html method for the classic HTML form and the json method for API‑driven or SPA front‑ends.

Minimal example

import { Edit } from '@itrocks/edit'
import type { Request } from '@itrocks/action-request'

class User {
	name  = ''
	email = ''
}

// Action responsible for editing existing User instances
const editUser = new Edit<User>()

// HTML edit form endpoint
async function editUserHtml (request: Request<User>) {
	return editUser.html(request)
}

// JSON endpoint (for SPA / XHR based UI)
async function editUserJson (request: Request<User>) {
	return editUser.json(request)
}

The Request<User> is generally created by @itrocks/action-request from an incoming HTTP request and contains all the information needed to load the object and apply edits.

API

class Edit<T extends object = object> extends Action<T>

Edit is a subclass of @itrocks/action's Action. It focuses on the "edit existing object" use case and is reused by other higher‑level actions such as New.

From the type declarations you can see that it works with a Request<T> and returns responses from @itrocks/core-responses.

Type parameter

  • T – The domain object type being edited (for example User).

Methods

html(request: Request<T>): Promise<HtmlResponse>

Builds an HTML form for editing an existing instance of T.

Typical usage in a route handler:

fastify.get('/users/:id/edit', async (req, reply) => {
	const request = toActionRequest<User>(req)
	const response = await editUser.html(request)
	reply
		.status(response.status)
		.headers(response.headers)
		.type('text/html')
		.send(response.body)
})

Internally, Edit relies on the it.rocks action stack to:

  • locate and load the object to edit (for example by ID),
  • bind incoming data to this object,
  • prepare the view model and HTML template for the form.
json(request: Request<T>): Promise<JsonResponse>

Builds a JSON representation of the same edit form/state. This is useful for SPA or mobile clients that render their own UI while keeping validation and persistence logic on the server.

fastify.get('/api/users/:id/edit', async (req, reply) => {
	const request = toActionRequest<User>(req)
	const response = await editUser.json(request)
	reply
		.status(response.status)
		.headers(response.headers)
		.send(response.body)
})

Typical use cases

  • Provide a conventional "edit" screen for any business entity (users, products, orders, etc.).
  • Expose a JSON API for editing existing objects from rich front‑end applications while reusing the same server‑side action.
  • Factor common edit behaviour once in Edit<T> and reuse it in specialised actions (for example New<T>).