@blackblock/slow-network-checker

0.1.2 • Public • Published

Slow Network Detector

Maintainability Test Coverage Known Vulnerabilities Codacy Badge

A simple package that uses NetworkInformation API to check if the user's network is slow.

Usage

import {
  isSlowNetwork
} from '@blackblock/slow-network-checker'

const slowNetworkDefinition = {
  effectiveType: '2g',
  downlink: 1,
  saveData: true,
  rtt: 1000
}

const networkInformation = navigator.connection || navigator.mozConnection || navigator.webkitConnection

const result = isSlowNetwork(slowNetworkDefinition)(networkInformation) //Return Boolean

Installation

npm i @blackblock/slow-network-checker

API Reference

Type Definition

Definition

An object that lists the definition of a slow network based on different metrics.

type Definition = { effectiveType :: String,
saveData :: Boolean,
downlink :: Int,
rtt :: Int}

NetworkPerformance

An object that records the performance of a network in different metrics. The NetworkInformation object should be passed in here.

You should also pass in the online status from Navigator.onLine in the performance object as online, so that the status of offline and slow network can be differentiated.

type NetworkPerformance = {
online :: Boolean,
effectiveType :: String,
saveData :: Boolean,
downlink :: Int,
rtt :: Int}

Function

isSlowNetwork

Main function of this package. Test if the NetworkInformation object met the definition of a slow network.

If the actual network performance is slower or equal to your definition defined as Definition, it will be regarded as a slow network and return true, false otherwise.

If the user is offline, isSlowNetwork will always return false, so that the status of offline and slow network can be differentiated.

isSlowNetwork :: Definition -> NetworkPerformance -> Boolean

Package Sidebar

Install

npm i @blackblock/slow-network-checker

Weekly Downloads

25

Version

0.1.2

License

MIT

Unpacked Size

11.5 kB

Total Files

5

Last publish

Collaborators

  • johnwinston0410