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

resply

v0.1.1

Published

Standardized API response structure

Readme

Resply

A lightweight TypeScript/JavaScript package for standardizing API responses with automatic case style transformation.

Installation

npm install resply

Features

  • ✨ Standardized success and error response formats
  • 🔄 Automatic case transformation (camelCase, snake_case, kebab-case)
  • 📦 TypeScript support with full type definitions
  • 🪶 Zero dependencies
  • 🎯 Simple and intuitive API

Quick Start

import { initResply, SuccessReply, ErrorReply } from "resply";

// Initialize with your preferred case style (default: camelCase)
initResply({ caseStyle: "camelCase" });

// Create a success response
const response = SuccessReply(
  { user_id: 123, user_name: "Alice" },
  "User fetched"
);
// Output: { success: true, message: 'User fetched', data: { userId: 123, userName: 'Alice' } }

// Create an error response
const error = ErrorReply({ field: "email" }, "Invalid email", 400);
// Output: { success: false, error: { message: 'Invalid email', details: { field: 'email' }, statusCode: 400 } }

API Reference

initResply(options)

Initialize the package with your preferred configuration.

Parameters:

  • options.caseStyle (optional): 'camelCase' | 'snake_case' | 'kebab-case' (default: 'camelCase')

Example:

import { initResply } from "resply";

// Use snake_case for all responses
initResply({ caseStyle: "snake_case" });

// Use kebab-case
initResply({ caseStyle: "kebab-case" });

// Use camelCase (default)
initResply({ caseStyle: "camelCase" });

SuccessReply<T>(data, message?)

Create a standardized success response.

Parameters:

  • data: The response data (will be transformed to the configured case style)
  • message (optional): Success message (default: "Success")

Returns:

{
  success: true,
  message: string,
  data: T
}

Example:

const user = {
  user_id: 123,
  first_name: "Alice",
  last_name: "Johnson",
};

const response = SuccessReply(user, "User created successfully");
// With camelCase:
// {
//   success: true,
//   message: 'User created successfully',
//   data: { userId: 123, firstName: 'Alice', lastName: 'Johnson' }
// }

ErrorReply<T>(data?, message?, statusCode?)

Create a standardized error response.

Parameters:

  • data (optional): Additional error data (will be transformed to the configured case style)
  • message (optional): Error message (default: "Error")
  • statusCode (optional): HTTP status code (default: 500)

Returns:

{
  success: false,
  error: {
    message: string,
    details?: T,
    statusCode: number
  }
}

Example:

const validationErrors = {
  email_field: "Invalid format",
  phone_number: "Required",
};

const response = ErrorReply(validationErrors, "Validation failed", 400);
// With camelCase:
// {
//   success: false,
//   error: {
//     message: 'Validation failed',
//     data: { emailField: 'Invalid format', phoneNumber: 'Required' },
//     statusCode: 400
//   }
// }

Case Style Examples

camelCase (default)

initResply({ caseStyle: "camelCase" });

const data = { user_id: 1, first_name: "Alice", "home-address": "123 Main St" };
SuccessReply(data);
// Result: { userId: 1, firstName: 'Alice', homeAddress: '123 Main St' }

snake_case

initResply({ caseStyle: "snake_case" });

const data = { userId: 1, firstName: "Alice", "home-address": "123 Main St" };
SuccessReply(data);
// Result: { user_id: 1, first_name: 'Alice', home_address: '123 Main St' }

kebab-case

initResply({ caseStyle: "kebab-case" });

const data = { user_id: 1, firstName: "Alice" };
SuccessReply(data);
// Result: { user-id: 1, first-name: 'Alice' }

Usage with Express

import express from "express";
import { initResply, SuccessReply, ErrorReply } from "resply";

const app = express();

// Initialize with snake_case for API responses
initResply({ caseStyle: "snake_case" });

app.get("/api/users/:id", async (req, res) => {
  try {
    const user = await getUserById(req.params.id);

    if (!user) {
      return res.status(404).json(ErrorReply(null, "User not found", 404));
    }

    res.json(SuccessReply(user, "User fetched successfully"));
  } catch (error) {
    res
      .status(500)
      .json(ErrorReply({ error: error.message }, "Internal server error", 500));
  }
});

Nested Objects and Arrays

Resply automatically transforms nested objects and arrays:

initResply({ caseStyle: "camelCase" });

const data = {
  user_id: 1,
  user_profile: {
    first_name: "Alice",
    contact_info: {
      email_address: "[email protected]",
    },
  },
  user_orders: [
    { order_id: 101, order_total: 99.99 },
    { order_id: 102, order_total: 149.99 },
  ],
};

SuccessReply(data);
// All keys transformed to camelCase recursively

TypeScript Support

Resply is written in TypeScript and provides full type definitions:

import {
  SuccessResponse,
  ErrorResponse,
  SuccessReply,
  ErrorReply,
} from "resply";

interface User {
  id: number;
  name: string;
}

const response: SuccessResponse<User> = SuccessReply({ id: 1, name: "Alice" });
const error: ErrorResponse = ErrorReply(null, "Not found", 404);

License

MIT

Contributing

Contributions are welcome! Please open an issue or submit a pull request.