├── .babelrc
├── .browserslistrc
├── .circleci
└── config.yml
├── .commitlintrc.js
├── .coveralls.yml
├── .cz-config.js
├── .editorconfig
├── .eslintignore
├── .eslintrc.js
├── .gitignore
├── .npmrc
├── CHANGELOG.md
├── LICENSE
├── README.md
├── README.zh_CN.md
├── example
├── index.html
└── index.js
├── package-lock.json
├── package.json
├── scripts
├── config.js
└── rollup
│ ├── rollup.config.base.js
│ ├── rollup.config.dev.js
│ └── rollup.config.prod.js
├── src
├── main.ts
└── utils
│ ├── check.ts
│ └── is.ts
├── test
├── check.test.ts
├── config.test.ts
└── mocha.opts
├── tsconfig.build.json
├── tsconfig.json
└── typings
└── .gitkeep
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | ["@babel/preset-env", {
4 | "modules": false
5 | }]
6 | ],
7 | "plugins": [
8 |
9 | ]
10 | }
--------------------------------------------------------------------------------
/.browserslistrc:
--------------------------------------------------------------------------------
1 | > 0.5%
2 | last 2 versions
3 | not ie <= 8
4 | not dead
--------------------------------------------------------------------------------
/.circleci/config.yml:
--------------------------------------------------------------------------------
1 | # Javascript Node CircleCI 2.0 configuration file
2 | #
3 | # Check https://circleci.com/docs/2.0/language-javascript/ for more details
4 | #
5 | version: 2
6 | jobs:
7 | build:
8 | docker:
9 | # specify the version you desire here
10 | - image: circleci/node:latest
11 | filters:
12 | branches:
13 | only: master
14 |
15 | # Specify service dependencies here if necessary
16 | # CircleCI maintains a library of pre-built images
17 | # documented at https://circleci.com/docs/2.0/circleci-images/
18 | # - image: circleci/mongo:3.4.4
19 |
20 | working_directory: ~/repo
21 |
22 | steps:
23 | - checkout
24 |
25 | # Download and cache dependencies
26 | - restore_cache:
27 | keys:
28 | - v1-dependencies-{{ checksum "package.json" }}
29 | # fallback to using the latest cache if no exact match is found
30 | - v1-dependencies-
31 |
32 | - run: npm install
33 |
34 | - save_cache:
35 | paths:
36 | - node_modules
37 | key: v1-dependencies-{{ checksum "package.json" }}
38 |
39 | - run: npm run build
40 | # run tests!
41 | - run: npm run coveralls
42 |
--------------------------------------------------------------------------------
/.commitlintrc.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | module.exports = {
4 | extends: [
5 | 'cz'
6 | ],
7 | rules: {
8 | }
9 | };
--------------------------------------------------------------------------------
/.coveralls.yml:
--------------------------------------------------------------------------------
1 | repo_token: TFbUzLlEXxWMQbaJT5kQrWriw70K4RNcy
--------------------------------------------------------------------------------
/.cz-config.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | module.exports = {
4 |
5 | types: [
6 | {
7 | value: ':construction: WIP',
8 | name : '💪 WIP: Work in progress'
9 | },
10 | {
11 | value: ':sparkles: feat',
12 | name : '✨ feat: A new feature'
13 | },
14 | {
15 | value: ':bug: fix',
16 | name : '🐛 fix: A bug fix'
17 | },
18 | {
19 | value: ':hammer: refactor',
20 | name : '🔨 refactor: A code change that neither fixes a bug nor adds a feature'
21 | },
22 | {
23 | value: ':pencil: docs',
24 | name : '📝 docs: Documentation only changes'
25 | },
26 | {
27 | value: ':white_check_mark: test',
28 | name : '✅ test: Add missing tests or correcting existing tests'
29 | },
30 | {
31 | value: ':thought_balloon: chore',
32 | name : '🗯 chore: Changes that don\'t modify src or test files. Such as updating build tasks, package manager'
33 | },
34 | {
35 | value: ':lipstick: ui',
36 | name: '💄 Updating the UI and style files.',
37 | },
38 | {
39 | value: ':art: style',
40 | name:
41 | '🎨 Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)',
42 | },
43 | {
44 | value: 'revert',
45 | name : '⏪ revert: Revert to a commit'
46 | },
47 | {
48 | value: ':package: dep_up',
49 | name: '📦 Updating compiled files or packages.',
50 | },
51 | {
52 | value: ':green_heart: fixci',
53 | name: '💚 Fixing CI Build.',
54 | },
55 | {
56 | value: ':truck: mv',
57 | name: '🚚 Moving or renaming files.',
58 | },
59 | {
60 | value: ':fire: prune',
61 | name: '🔥 Removing code or files.',
62 | },
63 | {
64 | value: ':bookmark: release',
65 | name: '🔖 Releasing / Version tags.',
66 | }
67 | ],
68 |
69 | scopes: [],
70 |
71 | allowCustomScopes: true,
72 | allowBreakingChanges: ["feat", "fix"]
73 | };
74 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | end_of_line = lf
5 | charset = utf-8
6 | indent_style = space
7 | indent_size = 4
8 | trim_trailing_whitespace = true
9 | insert_final_newline = true
10 |
11 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | dist/*.js
2 | examples/*.js
3 | rollup.config.*.js
4 |
--------------------------------------------------------------------------------
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | "root": true,
3 | "parser": "@typescript-eslint/parser", // 支持新的es7属性
4 | "parserOptions": {
5 | "ecmaVersion": 6, // 指定你使用的 ECMAScript 版本
6 | "sourceType": "module", // 代码是 ECMAScript 模块
7 | "ecmaFeatures": { // 额外的语言特性
8 | "experimentalObjectRestSpread": true // 支持新的es7属性
9 | },
10 | "project": "./tsconfig.json"
11 | },
12 | "env":{
13 | "es6": true, // 启用除了 modules 以外的所有 ECMAScript 6 特性(该选项会自动设置 ecmaVersion 解析器选项为 6
14 | "browser": true, // 浏览器环境中的全局变量
15 | "node":true,
16 | "commonjs": true,
17 | "mocha": true
18 | },
19 | "extends": [
20 | "eslint:recommended",
21 | "plugin:@typescript-eslint/recommended"
22 | ], // 核心规则
23 | "globals": { // 全局变量
24 |
25 | },
26 | "plugins": [ // 第三方插件
27 | "@typescript-eslint"
28 | ],
29 | "rules": {
30 | "prefer-const": "off",
31 | "no-unused-vars": "warn",
32 | "no-console": "off",
33 | "generator-star-spacing": "off",
34 | "@typescript-eslint/no-explicit-any": "off",
35 | "@typescript-eslint/explicit-function-return-type": "off",
36 | }
37 | };
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # General
2 | .DS_Store
3 | .AppleDouble
4 | .LSOverride
5 |
6 | # Thumbnails
7 | ._*
8 |
9 | # Files that might appear in the root of a volume
10 | .DocumentRevisions-V100
11 | .fseventsd
12 | .Spotlight-V100
13 | .TemporaryItems
14 | .Trashes
15 | .VolumeIcon.icns
16 | .com.apple.timemachine.donotpresent
17 |
18 | # Directories potentially created on remote AFP share
19 | .AppleDB
20 | .AppleDesktop
21 | Network Trash Folder
22 | Temporary Items
23 | .apdisk
24 |
25 | # Logs
26 | logs
27 | *.log
28 | npm-debug.log*
29 |
30 | # Runtime data
31 | pids
32 | *.pid
33 | *.seed
34 |
35 | # Editor directories and files
36 | .idea
37 | .vscode
38 |
39 | # Dependency directories
40 | node_modules
41 |
42 | # Optional
43 | .npm
44 | .node_repl_history
45 |
46 | # assets publish
47 | # you can ignore dist Folder if you publish your assets with CI to CDN
48 |
49 | # Project specific stuff
50 | .rpt2_cache
51 | .nyc_output
52 | lib
53 | dist
54 | .mocha_test
55 | coverage
--------------------------------------------------------------------------------
/.npmrc:
--------------------------------------------------------------------------------
1 | //registry=https://registry.npm.taobao.org
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4 |
5 | ### [1.0.3](https://github.com/wall-wxk/ping-url/compare/v1.0.2...v1.0.3) (2019-08-09)
6 |
7 | ### [1.0.2](https://github.com/wall-wxk/ping-url/compare/v1.0.1...v1.0.2) (2019-08-08)
8 |
9 | ### [1.0.1](https://github.com/wall-wxk/ping-url/compare/v1.0.0...v1.0.1) (2019-08-08)
10 |
11 | ## 1.0.0 (2019-08-08)
12 |
13 |
14 | ### Features
15 |
16 | * ping url first release! ([2382187](https://github.com/wall-wxk/ping-url/commit/2382187))
17 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Leon Wang
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # [](https://circleci.com/gh/wall-wxk/ping-url/tree/master) [](https://coveralls.io/github/wall-wxk/ping-url?branch=master) [](https://www.npmjs.com/package/ping-url) [](https://www.npmjs.com/package/ping-url) [](https://github.com/wall-wxk/ping-url/blob/master/LICENSE)
2 |
3 | English | [中文简体](https://github.com/wall-wxk/ping-url/blob/master/README.zh_CN.md)
4 |
5 | ## :sparkles:Features
6 |
7 | - Check the url is normally accessible or not.
8 | - Check url network latency.
9 |
10 | ## :traffic_light:Environment Support
11 |
12 | | [
](http://godban.github.io/browsers-support-badges/)IE / Edge | [
](http://godban.github.io/browsers-support-badges/)Firefox | [
](http://godban.github.io/browsers-support-badges/)Chrome | [
](http://godban.github.io/browsers-support-badges/)Safari | [
](http://godban.github.io/browsers-support-badges/)Opera |
13 | | --- | --- | --- | --- | --- |
14 | | IE9, IE10, IE11, Edge | last 2 versions | last 2 versions | last 2 versions | last 2 versions |
15 |
16 | ## :rocket:Install
17 |
18 | Using npm, download and install the code.
19 | ```bash
20 | npm install --save ping-url
21 | ```
22 | For node environment:
23 | ```js
24 | var base = require('ping-url');
25 | ```
26 | For webpack or similar environment:
27 | ```js
28 | import base from 'ping-url';
29 | ```
30 | For requirejs environment:
31 | ```js
32 | requirejs(['node_modules/ping-url/dist/ping-url.cjs.js'], function (base) {
33 | // do something...
34 | })
35 | ```
36 | For browser environment:
37 | ```html
38 |
39 | ```
40 |
41 | ## :books:API
42 |
43 | ### `Ping.config`
44 | > Customize the protocol name
45 |
46 | The default protocol for Ping is `http`. If customization is required, use this method to set it up before use.
47 |
48 | - param {object} option
49 | - option.protocol {string} protocol `values:['http', 'https']`
50 | - return {string} The protocol name of the final setting
51 |
52 | #### example
53 | ```javascript
54 | import Ping from 'ping-url';
55 |
56 | Ping.config({
57 | protocol: 'https'
58 | });
59 | ```
60 |
61 | ### `Ping.check`
62 | > Checks the availability of the url and returns the check information.
63 |
64 | Check its accessibility and network latency by requesting the url.
65 |
66 | - param {string} url the url to detect
67 | - return {object} return `Promise` object
68 | - response(resolve status)
69 | - response.status {boolean} `true`: Can be accessed `false`: Can not be accessed
70 | - response.time {number} Network delay (millisecond), when inaccessible, the default is' -1 '
71 | - response(reject status)
72 | - response.status {boolean} `false`: Can not be accessed
73 | - response.msg {string} Error message
74 |
75 | #### example
76 | ```javascript
77 | import Ping from 'ping-url';
78 |
79 | Ping.check('https://wangxiaokai.vip').then(res => {
80 | console.log(`status: ${res.status} and time: ${res.time}`);
81 | }, res => {
82 | console.log(`error msg: ${res.msg}`);
83 | });
84 | ```
85 |
86 |
87 | ## :page_facing_up:LICENSE
88 | MIT
89 |
90 |
--------------------------------------------------------------------------------
/README.zh_CN.md:
--------------------------------------------------------------------------------
1 | # [](https://circleci.com/gh/wall-wxk/ping-url/tree/master) [](https://coveralls.io/github/wall-wxk/ping-url?branch=master) [](https://www.npmjs.com/package/ping-url) [](https://www.npmjs.com/package/ping-url) [](https://github.com/wall-wxk/ping-url/blob/master/LICENSE)
2 |
3 | [English](https://github.com/wall-wxk/ping-url/blob/master/README.md) | 中文简体
4 |
5 | ## :sparkles:特性
6 |
7 | - 检测url是否可正常访问
8 | - 检测url网络延时
9 |
10 | ## :traffic_light:兼容性
11 |
12 | | [
](http://godban.github.io/browsers-support-badges/)IE / Edge | [
](http://godban.github.io/browsers-support-badges/)Firefox | [
](http://godban.github.io/browsers-support-badges/)Chrome | [
](http://godban.github.io/browsers-support-badges/)Safari | [
](http://godban.github.io/browsers-support-badges/)Opera |
13 | | --- | --- | --- | --- | --- |
14 | | IE9, IE10, IE11, Edge | last 2 versions | last 2 versions | last 2 versions | last 2 versions |
15 |
16 | ## :rocket:安装
17 |
18 | 通过npm安装
19 | ```bash
20 | npm install --save ping-url
21 | ```
22 | node环境
23 | ```js
24 | var base = require('ping-url');
25 | ```
26 | webpack及其类似的环境
27 | ```js
28 | import base from 'ping-url';
29 | ```
30 | require.js环境
31 | ```js
32 | requirejs(['node_modules/ping-url/dist/ping-url.cjs.js'], function (base) {
33 | // do something...
34 | })
35 | ```
36 | 浏览器环境
37 | ```html
38 |
39 | ```
40 |
41 | ## :books:文档
42 |
43 | ### `Ping.config`
44 | > 自定义协议名
45 |
46 | Ping的默认协议是`http`。如果需要自定义,在使用之前用该方法进行设置即可。
47 |
48 | - param {object} option
49 | - option.protocol {string} 协议 `取值:['http', 'https']`
50 | - return {string} 最终设置的协议名
51 |
52 | #### 例子
53 | ```javascript
54 | import Ping from 'ping-url';
55 |
56 | Ping.config({
57 | protocol: 'https'
58 | });
59 | ```
60 |
61 | ### `Ping.check`
62 | > 检测url的可用性,并返回检测信息
63 |
64 | 通过请求url,检测其可访问性和网络延时。
65 |
66 | - param {string} url 要检测的url
67 | - return {object} 返回`Promise`对象
68 | - response(resolve状态)
69 | - response.status {boolean} `true`:可访问 `false`:不可访问
70 | - response.time {number} 网络延时(毫秒),不可访问时,默认为`-1`
71 | - response(reject状态)
72 | - response.status {boolean} `false`:不可访问
73 | - response.msg {string} 错误信息
74 |
75 | #### 例子
76 | ```javascript
77 | import Ping from 'ping-url';
78 |
79 | Ping.check('https://wangxiaokai.vip').then(res => {
80 | console.log(`status: ${res.status} and time: ${res.time}`);
81 | }, res => {
82 | console.log(`error msg: ${res.msg}`);
83 | });
84 | ```
85 |
86 |
87 | ## :page_facing_up:许可证
88 | MIT
89 |
90 |
--------------------------------------------------------------------------------
/example/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |