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

ws-json-wrapper

v0.1.1

Published

<br>

Readme

wsjson 函数执行后生成一个websocket实例,集成了心跳检测、断线重连和事件的功能。

说明:
一、传输的消息体格式:

约定前后端传输格式如下

{
    type:xxx
    data:{
        ...
    }
}

默认配置下会在发送时进行JSON序列化,收到消息时进行JSON反序列化
二、检测服务端断线的心跳检测功能

默认配置下,服务端会定时发出

{
    type:'PING'
}

要求服务端在接收到消息后返回

{
    type:'PONG',
    ...
}

要求后端代码中判断,如果客户端发送的消息体的type是'PING',就返回type为'PONG'的消息体

使用方法:
一、创建连接

const ws = webSocket(url) // 使用默认配置  
const ws = webSocket(url,options) // 传入参数 

interface options{ 


}

二、发送消息

// 使用send方法
ws.send({type:1,data:{msg:'hello'}})

三、接收消息

用法一:同原生websocketAPI

ws.onmessage=function(e){
    ...
}
ws.onerror=function(e){
    ...
}

用法二:使用事件

ws.on(type,cb) 第一个参数是type字段的内容,第二个回调接收了data的内容

ws.on(/* type */,(data)=>{

})

ws.on('NEW_MESSAGE',(data)=>{

})

ws.on('PULL_MESSAGE',(data)=>{

})

用法三:监听实例内部latestState字段获取状态

$store.state.wsState = ws.latestState  // 例如 在Vue中,可以作为一个可监听的全局响应式数据
...
watch:{
    'wsState':(n,o){
        if(n){
            const {type,data} = n
            if(type === "NEW_MESSAGE"){
                ...
            }
        }
    }
}