README
CircleCI">

English | 中文简体
:sparkles:Features
- Check the url is normally accessible or not.
- Check url network latency.
:traffic_light:Environment Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
IE9, IE10, IE11, Edge | last 2 versions | last 2 versions | last 2 versions | last 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']
- option.protocol {string} protocol
- 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 accessedfalse
: Can not be accessed - response.time {number} Network delay (millisecond), when inaccessible, the default is' -1 '
- response.status {boolean}
- response(reject status)
- response.status {boolean}
false
: Can not be accessed - response.msg {string} Error message
- response.status {boolean}
- response(resolve status)
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