ping-url
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

CircleCI Coverage Status NPM version download license

English | 中文简体

✨Features

  • Check the url is normally accessible or not.
  • Check url network latency.

🚥Environment Support

IE / Edge
IE / Edge
Firefox
Firefox
Chrome
Chrome
Safari
Safari
Opera
Opera
IE9, IE10, IE11, Edge last 2 versions last 2 versions last 2 versions last 2 versions

🚀Install

Using npm, download and install the code.

npm install --save ping-url

For node environment:

var base = require('ping-url');

For webpack or similar environment:

import base from 'ping-url';

For requirejs environment:

requirejs(['node_modules/ping-url/dist/ping-url.cjs.js'], function (base) {
    // do something...
})

For browser environment:

<script src="node_modules/ping-url/dist/iping-url.min.js"></script>

📚API

Ping.config

Customize the protocol name

The default protocol for Ping is http. If customization is required, use this method to set it up before use.

  • param {object} option
    • option.protocol {string} protocol values:['http', 'https']
  • return {string} The protocol name of the final setting

example

import Ping from 'ping-url';
 
Ping.config({
    protocol: 'https'
});

Ping.check

Checks the availability of the url and returns the check information.

Check its accessibility and network latency by requesting the url.

  • param {string} url the url to detect
  • return {object} return Promise object
    • response(resolve status)
      • response.status {boolean} true: Can be accessed false: Can not be accessed
      • response.time {number} Network delay (millisecond), when inaccessible, the default is' -1 '
    • response(reject status)
      • response.status {boolean} false: Can not be accessed
      • response.msg {string} Error message

example

import Ping from 'ping-url';
 
Ping.check('https://wangxiaokai.vip').then(res => {
    console.log(`status: ${res.status} and time: ${res.time}`);
}, res => {
    console.log(`error msg: ${res.msg}`);
});

📄LICENSE

MIT

Readme

Keywords

Package Sidebar

Install

npm i ping-url

Weekly Downloads

66

Version

1.0.3

License

MIT

Unpacked Size

42.1 kB

Total Files

18

Last publish

Collaborators

  • wallxiaokai