Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
05e4293
Add typescript as devDependencies
mondwan Sep 30, 2025
97bb0c0
Move the index.js into the source folder
mondwan Sep 30, 2025
5fbffc9
Fill in missing jsdoc & rework module exports
mondwan Sep 30, 2025
4756c32
Fix bad eslint settings for mocha test
mondwan Sep 30, 2025
43830fe
Lint codes
mondwan Sep 30, 2025
b081723
Fix the eslint configuration
mondwan Sep 30, 2025
a0753e6
Centralise the PingConfig jsdoc
mondwan Sep 30, 2025
1406a7b
Further refine the jsdoc
mondwan Sep 30, 2025
b6c012f
Fix jsdoc
mondwan Sep 30, 2025
459f969
Publish the .d.ts for this library
mondwan Sep 30, 2025
14771e1
Reword the README
mondwan Sep 30, 2025
c7b154c
Add tests for .d.ts
mondwan Sep 30, 2025
48396d3
Fix tsconfig after adding tsd
mondwan Sep 30, 2025
69265dc
Mark PingConfig properties optional
mondwan Sep 30, 2025
9e53b5e
Update the ts files
mondwan Sep 30, 2025
52d145a
Add @type/grunt
mondwan Oct 2, 2025
b501e07
Add a bug report template
mondwan Oct 2, 2025
e98b887
Fix the property access issues
mondwan Oct 2, 2025
f24b603
Add grunt tasks
mondwan Oct 2, 2025
02198b6
Drop the config file check
mondwan Oct 2, 2025
dddb8df
Drop the outDir overriden
mondwan Oct 2, 2025
a3d8913
Lint codes
mondwan Oct 2, 2025
11776aa
Lint codes
mondwan Oct 2, 2025
fdbe869
Update mocha
mondwan Oct 2, 2025
c5ce2b1
Lint codes
mondwan Oct 2, 2025
39743fc
Fix rules
mondwan Oct 2, 2025
b7ea5d6
Lint codes
mondwan Oct 2, 2025
65f1ba0
Update Throw Error Type
mondwan Oct 2, 2025
248b3c1
Add DiffDTs task
mondwan Oct 2, 2025
a583631
Make it a valid standard json file
mondwan Oct 2, 2025
0b88263
Check DTS on CI
mondwan Oct 2, 2025
faa1846
Lint codes
mondwan Oct 2, 2025
8629697
Fix CICD typo
mondwan Oct 2, 2025
076ba3f
Add a section about typescript support
mondwan Oct 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
name: Bug Report
about: Create a report to help us improve
title: '[BUG] '
labels: bug
assignees: ''
---

## Bug Description

A clear and concise description of what the bug is.

## Expected Behavior

A clear and concise description of what you expected to happen.

## Actual Behavior

A clear and concise description of what actually happened.

## Code Sample

If applicable, add a minimal code sample that reproduces the issue:

```javascript
const ping = require('ping');

ping.sys.probe('google.com', function(isAlive) {
console.log(isAlive);
});
```

## Environment

- **OS**: [e.g. Windows 10, Ubuntu 20.04, macOS 12.0]
- **Node.js version**: [e.g. 18.17.0]
- **Package version**: [e.g. 0.4.4]
- **Platform**: [e.g. linux, win32, darwin] The output from nodejs `os.platform()`

## Error Output

If applicable, add error messages or stack traces:

```
Error: Platform |freebsd| is not support
at Object.factory.createParser (/path/to/file.js:42:15)
...
```

## Raw system ping output

Please paste your raw system ping that causing your issue below

```
RAW OUTPUT Ping example HERE
```
4 changes: 4 additions & 0 deletions .github/workflows/build-test-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ jobs:
npm run lint
npm run test

- name: DTS are up to date
run: |
npx grunt diffDts

- name: Covergae
run: |
npm run coverage
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ node_modules
npm-debug.log
dist/
.nyc_output/

*.d.ts.map
12 changes: 12 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
We welcome patches and features. There are however a few things that are
required before your pull request can be merged.

# Development

## About TypeScript Support

Currently, this is still a common js module or library. We provide typescript definitions only.

Please make sure to run following for updating the typescript definition files accordingly.

```shell
npx grunt makeDts
```

# Tests

## How to write a new test case
Expand Down
23 changes: 21 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
'use strict';

/**
* Grunt configuration
* @param {import('grunt')} grunt - The Grunt instance
*/
module.exports = function (grunt) {
grunt.initConfig({
eslint: {
src: ['lib/*.js', 'lib/**/*.js'],
src: ['Gruntfile.js', 'tasks/*.js', 'lib/*.js', 'lib/**/*.js'],
options: {
overrideConfigFile: 'eslint.config.js',
},
Expand Down Expand Up @@ -33,12 +37,27 @@ module.exports = function (grunt) {
src: 'dist/coverage/*.info',
options: {},
},
makeDts: {
options: {
config: 'tsconfig.json',
},
},
diffDts: {
options: {
config: 'tsconfig.json',
},
},
runTsdTest: {
options: {},
},
});

grunt.loadNpmTasks('grunt-eslint');
grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('grunt-nyc-mocha');
grunt.loadNpmTasks('grunt-coveralls');
grunt.registerTask('test', ['eslint', 'mochaTest']);

grunt.loadTasks('tasks');
grunt.registerTask('test', ['eslint', 'mochaTest', 'runTsdTest']);
grunt.registerTask('coverage', ['nyc_mocha']);
};
53 changes: 5 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ hosts.forEach(function (host) {


## Async-Await

```js
var ping = require('ping');

Expand All @@ -100,6 +101,7 @@ for(let host of hosts){
```

## Async-Await with configurable ping options

```js
var ping = require('ping');

Expand All @@ -116,62 +118,17 @@ for(let host of hosts){
```
### Support configuration

Below is the possible configuration

```js
/**
* Cross platform config representation
* @typedef {Object} PingConfig
* @property {boolean} numeric - Map IP address to hostname or not
* @property {number} timeout - Timeout in seconds for each ping request.
* Behaviour varies between platforms. Check platform ping documentation for more information.
* @property {number} deadline - Specify a timeout, in seconds, before ping exits regardless of
how many packets have been sent or received. In this case ping
does not stop after count packet are sent, it waits either for
deadline expire or until count probes are answered or for some
error notification from network. This option is only available on linux and mac.
* @property {number} min_reply - Exit after sending number of ECHO_REQUEST
* @property {boolean} v6 - Ping via ipv6 or not. Default is false
* @property {string} sourceAddr - source address for sending the ping
* @property {number} packetSize - Specifies the number of data bytes to be sent
Default: Linux / MAC: 56 Bytes, Windows: 32 Bytes
* @property {string[]} extra - Optional options does not provided
*/
```
See `PingConfig` in `types/index.d.ts`

### Output specification

* For callback based implementation:

```js
/**
* Callback after probing given host
* @callback probeCallback
* @param {boolean} isAlive - Whether target is alive or not
* @param {Object} error - Null if no error occurs
*/
```
See `probeCallback` in `types/ping-sys.d.ts`

* For promise based implementation

```js
/**
* Parsed response
* @typedef {object} PingResponse
* @param {string} inputHost - The input IP address or HOST
* @param {string} host - Parsed host from system command's output
* @param {string} numeric_host - Target IP address
* @param {boolean} alive - True for existed host
* @param {string} output - Raw stdout from system ping
* @param {number} time - Time (float) in ms for first successful ping response
* @param {Array} times - Array of Time (float) in ms for each ping response
* @param {string} min - Minimum time for collection records
* @param {string} max - Maximum time for collection records
* @param {string} avg - Average time for collection records
* @param {string} packetLoss - Packet Losses in percent (100% -> "100.000")
* @param {string} stddev - Standard deviation time for collected records
*/
```
See `PingResponse` in `types/ping-promise.d.ts`

#### Note

Expand Down
13 changes: 10 additions & 3 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

const babelParser = require('@babel/eslint-parser');
const jsdocPlugin = require('eslint-plugin-jsdoc');
const jsdoc = require('eslint-plugin-jsdoc');
const mochaPlugin = require('eslint-plugin-mocha').default;
const {defineConfig} = require('eslint/config');

const customGlobals = {
Expand Down Expand Up @@ -997,9 +998,15 @@ const jsdocRules = {
'jsdoc/require-param': 0,
};

const mochaRules = {
'mocha/no-setup-in-describe': 'off',
};

module.exports = defineConfig([
jsdoc.configs['flat/recommended'],
mochaPlugin.configs.recommended,
{
files: ['**/*.js'],
files: ['Gruntfile.js', '**/*.js'],
languageOptions: {
sourceType: 'commonjs',
parser: babelParser,
Expand All @@ -1019,11 +1026,11 @@ module.exports = defineConfig([
},
},
plugins: {
jsdoc: jsdocPlugin,
},
rules: {
...styleRules,
...jsdocRules,
...mochaRules,
},
},
]);
2 changes: 1 addition & 1 deletion examples/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

'use strict';

var ping = require('../index');
var ping = require('../lib/index');

var hosts = ['192.168.1.1', 'google.com', 'yahoo.com'];
hosts.forEach(function (host) {
Expand Down
14 changes: 7 additions & 7 deletions examples/example2.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var ping = require('../index');
var ping = require('../lib/index');

var hosts = ['192.168.1.1', 'google.com', 'yahoo.com'];

Expand All @@ -19,9 +19,9 @@ hosts.forEach(function (host) {
timeout: 10,
extra: ['-i', '2'],
})
.then(function (res) {
console.log(res);
});
.then(function (res) {
console.log(res);
});
});

// Running ping with some default argument gone
Expand All @@ -32,7 +32,7 @@ hosts.forEach(function (host) {
// Below extra arguments may not work in platforms other than linux
extra: ['-i', '2'],
})
.then(function (res) {
console.log(res);
});
.then(function (res) {
console.log(res);
});
});
10 changes: 5 additions & 5 deletions examples/example_win_de_v6.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

'use strict';

var ping = require('../index');
var ping = require('../lib/index');

var hosts = ['google.de']; // , '192.168.1.1', 'google.com', 'yahoo.com'];

Expand All @@ -14,10 +14,10 @@ hosts.forEach(function (host) {
sourceAddr: 'your NIC\'s IPv6 address',
// sourceAddr: false,
})
.then(function (res) {
console.log('\n');
console.log(res);
});
.then(function (res) {
console.log('\n');
console.log(res);
});

// Running ping with some default argument gone
ping.sys.probe(host, function (isAlive) {
Expand Down
7 changes: 0 additions & 7 deletions index.js

This file was deleted.

Loading