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

wsmock-js

v1.1.1

Published

Mock WebSocket in the browser without a server.

Downloads

9

Readme

wsmock-js

npm Build Status

Mock WebSocket in the browser without a server.

Getting-started

Install

yarn:

yarn add wsmock-js --dev

with <script> tag:

<script src="wsmock.min.js"></script>

Define mock settings

import wsm from 'wsmock-js'

wsm.mock({
  url: 'ws://some.mock.url',
  sendInterval: 'onreceive',
  receiver (data) { // 'data' is sent by webSocket.send in browser
    console.log(data)
  },
  sender () { // Simulating server send
    this.response = 'This is a message sent by server.'
  },
})

Then just use WebSocket as usual.

API

/**
 * Add a new mock setting.
 */
wsm.mock({
  // [String|RegExp] Mock url. Note: Url validation will not proceed if WHATWG URL API is not supported by browser (e.g. IE).
  url: /wss:\/\/xxx\.(xxxx|regexp)\.xxx/,

  /** 
   * [Array|Number|String] Define when server would send a message to the browser. 
   * [Array]: A set of numbers representing interval time.
   * [Number]: Interval time.
   * [String]: 'onreceive', server send message imediately once receive data from the browser.
   */
  sendInterval: 1000,

  // [Function] Simulate receive method invoked by server.
  receiver (data) {
    
  },

  // [Function] Simulate send method invoked by server.
  // * Note: You'd better not use an arrow function in case that 'this' does not point to setting object.
  sender () {
    this.response = 'This is a message sent by server.'
  },
})

/**
 * Global settings of wsmock-js
 */
wsm.config({
  // [Number] Default: '100', time (ms) cost of connection.
  CONNECTING_TIME: 100,

  // [Number] Default: '100', time (ms) cost of disconnection.
  CLOSING_TIME: 100,

  // [Number] Default: '1 * 1024 * 1024', send rate, bytes per second
  SEND_RATE: 1 * 1024 * 1024,
})

Attention

THIS MODULE IS USED TO MOCK WEBSOCKET BEHAVIORS IN DEVELOPMENT

DO NOT USE IT IN PRODUCTION

Todo

  • [x] Mock url regular expression support
  • [ ] Socket.io support?
  • [ ] Better test cases