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 🙏

© 2024 – Pkg Stats / Ryan Hefner

network-speed-test

v1.0.1

Published

测算网速的JS库,采用ES6语法和Promise风格编码,通过img加载/AJAX/downlink等方式测算网速

Downloads

10

Readme

Network-Speed-Test

测算网速的JS库,采用ES6语法和Promise风格编码,通过img加载/AJAX/downlink等方式测算网速

Description

提供了四个API

  • getSpeedWithImg:借助img.onload测算网速。优点:没有跨域问题。缺点:要自己测文件大小并提供参数fileSize,且文件必须为图片,文件大小不能灵活控制
  • getSpeedWithAjax: 通过Ajax测算网速。 优点: 不用提供文件大小参数,测试的文件不一定要是图片,且数据量能灵活控制。缺点:可能需要跨域
  • getSpeedWithDnlink: 通过navigator.connection.downlink读取网速。优点:不需要任何参数。缺点:1.兼容性很有问题,2.带宽查询不是实时的,具有分钟级别的时间间隔
  • getNetSpeed:先尝试采用downlink测速,否则多次AJAX测速并求平均值

Usage

如果你只是想看看demo效果:

  • clone 项目
  • 运行 node server.js
  • 浏览器打开localhost:3000/
  • 在client.js调试并输出结果

如果你使用NPM: 先

npm i network-speed-test

然后

import * from 'network-speed-test';
getSpeedWithImg("https://s2.ax1x.com/2019/08/13/mPJ2iq.jpg", 8.97).then(
    speed => {
        console.log(speed);
    }
)

getSpeedWithAjax('./speed.jpg').then(speed => {
    console.log(speed);
});

getNetSpeed('./speed.jpg', 3).then(speed => {
    console.log(speed);
});

getSpeedWithDnlink();