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

@janindu-pathirana/message-builder

v1.0.2

Published

A simple TypeScript utility for generating reusable success, error, validation, and resource messages.

Readme

@janindu-pathirana/message-builder

A lightweight TypeScript utility for creating consistent API and service messages.

MessageBuilder helps you generate reusable success, error, validation, and resource messages around a resource name such as user, order, product, or invoice.

Installation

npm install @janindu-pathirana/message-builder

Quick Start

import MessageBuilder from "@janindu-pathirana/message-builder";

const messages = new MessageBuilder("user");

messages.success("create");
// "Create user was successful."

messages.notFound();
// "The user you are looking for could not be found."

messages.invalid("email", "Use a valid email address.");
// "The email provided for the user is invalid. Hint: Use a valid email address."

CommonJS

const MessageBuilder = require("@janindu-pathirana/message-builder").default;

const messages = new MessageBuilder("product");

console.log(messages.notFound());
// "The product you are looking for could not be found."

API

new MessageBuilder(resource?)

Creates a new message builder for a resource.

const userMessages = new MessageBuilder("user");
const orderMessages = new MessageBuilder("order");

For best results, pass a resource name. If resource is omitted, methods that use the resource name will include undefined in the generated message.

Methods

| Method | Description | | --- | --- | | success(action) | Creates a success message and capitalizes the action. | | error(action, hint?) | Creates a general error message for an action. | | badRequest(action, hint?) | Creates an invalid request message for an action. | | notFound() | Creates a resource not found message. | | unauthorized() | Creates an authorization failure message. | | alreadyExists() | Creates a duplicate resource message. | | somethingWentWrong(hint?) | Creates a generic unexpected error message. | | failedToInsert(field) | Creates an insert failure message for a field. | | failedToUpdate(field) | Creates an update failure message for a field. | | failedToDelete(field) | Creates a delete failure message for a field. | | invalid(field, hint?) | Creates an invalid field message. | | customMessage(message) | Returns a custom message unchanged. |

Message Examples

const messages = new MessageBuilder("user");

messages.success("create");
// "Create user was successful."

messages.error("update");
// "There was an error while trying to update the user. Please try again later."

messages.error("update", "The user ID must exist.");
// "There was an error while trying to update the user. Please try again later. Hint: The user ID must exist."

messages.badRequest("create");
// "The request to create the user was invalid. Please check the data and try again."

messages.badRequest("create", "Email is required.");
// "The request to create the user was invalid. Please check the data and try again. Hint: Email is required."

messages.notFound();
// "The user you are looking for could not be found."

messages.unauthorized();
// "You are not authorized to perform this action on user."

messages.alreadyExists();
// "The user already exists."

messages.somethingWentWrong();
// "Something went wrong with the request. Please try again later or contact support if the problem persists."

messages.somethingWentWrong("Try again after a few minutes.");
// "Something went wrong with the request. Please try again later or contact support if the problem persists. Hint: Try again after a few minutes."

messages.failedToInsert("email");
// "Failed to insert data into the user for the field 'email'. Please check the data and try again."

messages.failedToUpdate("password");
// "Failed to update the user for the field 'password'. Please check the data and try again."

messages.failedToDelete("id");
// "Failed to delete the user for the field 'id'. Please try again later."

messages.invalid("email");
// "The email provided for the user is invalid."

messages.invalid("email", "Use a valid email address.");
// "The email provided for the user is invalid. Hint: Use a valid email address."

messages.customMessage("Your custom response message.");
// "Your custom response message."

Development

Install dependencies:

npm install

Build the package:

npm run build

The build uses tsup to generate ESM, CommonJS, and TypeScript declaration files in dist.

Package Output

This package ships:

| Format | Path | | --- | --- | | ESM | dist/index.js | | CommonJS | dist/index.cjs | | TypeScript declarations | dist/index.d.ts |

License

MIT