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

@jmcorp/har2mocks

v0.1.4

Published

A CLI tool to convert HAR files to JSON mocks

Downloads

10

Readme

@jmcorp/har2mocks

@jmcorp/har2mocks is a CLI tool that converts HAR (HTTP Archive) files to JSON mocks. It can also generate Cypress intercepts and MSW (Mock Service Worker) handlers.

Installation

You can install @jmcorp/har2mocks globally using npm:

npm install -g @jmcorp/har2mocks

Usage

har2mocks [options] <har_file_path> <output_directory>

Arguments

  • <har_file_path>: Path to the HAR file you want to convert
  • <output_directory>: Directory where the mocks will be generated

Options

  • --clean: Clean the output directory before generating mocks
  • --cypress: Generate Cypress intercepts in a file named cypress-intercept.js
  • --msw: Generate MSW (mock service worker) handlers in a file named msw-handlers.js

Examples

  1. Basic usage:

    har2mocks ./path/to/file.har ./mocks-output
  2. Clean output directory and generate Cypress intercepts:

    har2mocks --clean --cypress ./path/to/file.har ./mocks-output
  3. Generate both Cypress intercepts and MSW handlers:

    har2mocks --cypress --msw ./path/to/file.har ./mocks-output

Output

The tool will generate:

  • JSON mock files for each API endpoint
  • A file tree of the generated mocks
  • An API list table
  • Cypress intercepts file (if --cypress flag is used)
  • MSW handlers file (if --msw flag is used)

Example of output

API List:
| API                            | Method |
|--------------------------------|--------|
| /api/v1/auth/login             | POST   |
| /api/v1/notifications          | GET    |
| /api/v1/reviewable/reviews     | GET    |
| /api/v1/titles/1926514         | GET    |
| /api/v1/titles/1926514/related | GET    |
| /api/v1/users/me/ratings       | GET    |

Generated File Tree:
└── api
    └── v1
        ├── auth
        │   └── login
        │       └── POST.json
        ├── notifications
        │   └── GET.json
        ├── reviewable
        │   └── reviews
        │       └── GET.json
        ├── titles
        │   └── 1926514
        │       ├── GET.json
        │       └── related
        │           └── GET.json
        └── users
            └── me
                └── ratings
                    └── GET.json

cypress-intercept.js

// Cypress intercepts for mocked APIs

cy.intercept("GET", "/api/v1/notifications", { fixture: "api/v1/notifications/GET.json" });
cy.intercept("GET", "/api/v1/users/me/ratings", { fixture: "api/v1/users/me/ratings/GET.json" });
cy.intercept("GET", "/api/v1/users/me/watchlist", { fixture: "api/v1/users/me/watchlist/GET.json" });

msw-handlers.js

// This file contains handlers for Mock Service Worker (MSW) version 2.x
import { http, HttpResponse } from "msw";

import post_auth_loginMock from "./auth/login/POST.json";
import get_api_v1_notificationsMock from "./api/v1/notifications/GET.json";
import get_api_v1_reviewable_reviewsMock from "./api/v1/reviewable/reviews/GET.json";

export const handlers = [
  http.post("/api/v1/auth/login", () => {
    return HttpResponse.json(post_auth_loginMock);
  }),

  http.get("/api/v1/notifications", () => {
    return HttpResponse.json(get_api_v1_notificationsMock);
  }),

  http.get("/api/v1/reviewable/reviews", () => {
    return HttpResponse.json(get_api_v1_reviewable_reviewsMock);
  }),
];

## License

ISC