English | 中文简体
✨Features
- Check the url is normally accessible or not.
- Check url network latency.
🚥Environment Support
IE / Edge |
Firefox |
Chrome |
Safari |
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 = ;
For webpack or similar environment:
;
For requirejs environment:
For browser environment:
📚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
; Ping;
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
; Ping;
📄LICENSE
MIT