1.0.3 • Published 5 years ago

ping-url v1.0.3

Weekly downloads
77
License
MIT
Repository
github
Last release
5 years ago

CircleCI Coverage Status NPM version download license

English | 中文简体

:sparkles:Features

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

:traffic_light:Environment Support

IE / EdgeFirefoxChromeSafariOpera
IE9, IE10, IE11, Edgelast 2 versionslast 2 versionslast 2 versionslast 2 versions

:rocket: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>

:books: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}`);
});

:page_facing_up:LICENSE

MIT

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago