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

@gongxh/bit-net

v0.0.12

Published

网络相关

Readme

bit-net

网络通信库,提供 HTTP 请求和 WebSocket 连接的封装,支持跨平台使用。

简介

bit-net 是一个网络通信库,封装了 HTTP 和 WebSocket 功能,抹平了浏览器、原生平台和小游戏平台之间的 API 差异。提供统一、简洁的接口用于网络通信。

核心特性

  • 🌐 HTTP 模块 - 封装 XMLHttpRequest,支持 POST/GET/PUT/HEAD 等方法
  • 🔌 WebSocket 模块 - 统一的 Socket 接口,兼容各平台
  • 📡 支持 JSON、文本、二进制数据传输
  • ⚡ 请求超时控制和错误处理
  • 🎯 全局事件和回调两种响应方式

安装

npm install @gongxh/bit-net

使用说明

HTTP 模块 (HttpManager)

提供 HTTP 请求功能,支持多种请求方法和响应类型。

请求方法

  • post(url, data, responseType?, event?, headers?, timeout?) - POST 请求
  • get(url, data, responseType?, event?, headers?, timeout?) - GET 请求
  • put(url, data, responseType?, event?, headers?, timeout?) - PUT 请求
  • head(url, data, responseType?, event?, headers?, timeout?) - HEAD 请求

响应类型

  • 'json' - JSON 格式(默认)
  • 'text' - 文本格式
  • 'arraybuffer' - 二进制数据

响应处理方式

  1. 回调方式 - 通过 IHttpEvent 接口设置成功和失败回调
  2. 全局事件 - 通过 HttpManager.HttpEvent 监听所有请求响应

接口定义

  • IHttpRequest - 请求配置接口
  • IHttpResponse - 响应数据接口
  • IHttpEvent - 请求事件接口

WebSocket 模块 (Socket)

提供统一的 WebSocket 接口,兼容浏览器、原生平台和小游戏平台。

主要功能

  • new Socket(url, options) - 创建 WebSocket 连接
  • send(data) - 发送字符串消息
  • sendBuffer(buffer) - 发送二进制数据(常用于 ProtoBuf)
  • close(code, reason) - 关闭连接

事件监听

  • onopen - 连接成功回调
  • onmessage - 接收消息回调
  • onclose - 连接关闭回调
  • onerror - 连接错误回调

配置选项

  • binaryType - 二进制数据类型('arraybuffer' | 'blob'

详细 API 请查看 bit-net.d.ts 类型定义文件。

许可证

MIT License

作者

bit老宫 (gongxh)
邮箱: [email protected]

源码仓库