pingman 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +211 -204
  3. package/dist/src/builder/builder.d.ts +3 -3
  4. package/dist/src/builder/builder.js +30 -30
  5. package/dist/src/builder/linux.d.ts +3 -3
  6. package/dist/src/builder/linux.js +82 -82
  7. package/dist/src/builder/mac.d.ts +3 -3
  8. package/dist/src/builder/mac.js +88 -88
  9. package/dist/src/builder/windows.d.ts +3 -3
  10. package/dist/src/builder/windows.js +93 -93
  11. package/dist/src/errors.d.ts +10 -10
  12. package/dist/src/errors.js +25 -25
  13. package/dist/src/helper.d.ts +2 -2
  14. package/dist/src/helper.js +33 -33
  15. package/dist/src/helper.js.map +1 -1
  16. package/dist/src/index.d.ts +4 -4
  17. package/dist/src/index.js +56 -56
  18. package/dist/src/log.d.ts +7 -7
  19. package/dist/src/log.js +25 -25
  20. package/dist/src/messages.d.ts +9 -9
  21. package/dist/src/messages.js +12 -12
  22. package/dist/src/parser/clonePingResponse.d.ts +3 -3
  23. package/dist/src/parser/clonePingResponse.js +20 -20
  24. package/dist/src/parser/linux.d.ts +7 -7
  25. package/dist/src/parser/linux.js +30 -30
  26. package/dist/src/parser/mac.d.ts +11 -11
  27. package/dist/src/parser/mac.js +46 -46
  28. package/dist/src/parser/parser.interface.d.ts +8 -8
  29. package/dist/src/parser/parser.interface.js +2 -2
  30. package/dist/src/parser/parserFactory.d.ts +3 -3
  31. package/dist/src/parser/parserFactory.js +124 -124
  32. package/dist/src/parser/windows.d.ts +13 -13
  33. package/dist/src/parser/windows.js +110 -110
  34. package/dist/src/ping.d.ts +3 -3
  35. package/dist/src/ping.js +22 -22
  36. package/dist/src/types.d.ts +44 -44
  37. package/dist/src/types.js +2 -2
  38. package/package.json +58 -58
@@ -1,125 +1,125 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const helper_1 = require("../helper");
7
- const errors_1 = require("../errors");
8
- const windows_1 = __importDefault(require("./windows"));
9
- const mac_1 = __importDefault(require("./mac"));
10
- const linux_1 = __importDefault(require("./linux"));
11
- const messages_1 = require("../messages");
12
- const clonePingResponse_1 = __importDefault(require("./clonePingResponse"));
13
- //create instance of parser based on operating system
14
- function parserFactory(platform, output, options) {
15
- let parser;
16
- let isWindows = false;
17
- const baseReponse = (0, clonePingResponse_1.default)(defaultResponse);
18
- if (!(0, helper_1.isPlatformSupported)(platform)) {
19
- throw new errors_1.supportedError(messages_1.ERROR_MESSAGES.PLATFORM_NOT_SUPPORTED.replace('platform', platform));
20
- }
21
- if (platform === 'win32') {
22
- parser = new windows_1.default(baseReponse, options);
23
- isWindows = true;
24
- }
25
- else if (platform === 'darwin') {
26
- parser = new mac_1.default(baseReponse, options);
27
- }
28
- else {
29
- parser = new linux_1.default(baseReponse, options);
30
- }
31
- let result = parseOutput(parser, isWindows, output);
32
- return result;
33
- }
34
- //parsing output line by line
35
- function parseOutput(parser, isWindows, output) {
36
- let lines = output === null || output === void 0 ? void 0 : output.join('').split('\n');
37
- let state = 0;
38
- let parsedOutput = defaultResponse;
39
- lines === null || lines === void 0 ? void 0 : lines.forEach((line) => {
40
- line = line.replace(stripRegex, '');
41
- if (line.length === 0) {
42
- // Do nothing if this is an empty line
43
- }
44
- else if (state === states.HEADER) {
45
- parser.processHeader(line);
46
- state = states.BODY;
47
- }
48
- else if (state === states.BODY) {
49
- (!checkIfBodyEnded(line, isWindows)) ? parser.processBody(line) : state = states.FOOTER;
50
- }
51
- else if (state === states.FOOTER) {
52
- parsedOutput = parser.processFooter(line);
53
- }
54
- });
55
- let result = createResult(parsedOutput, lines);
56
- return result;
57
- }
58
- //function to check if body ended and footer began
59
- function checkIfBodyEnded(line, windows) {
60
- if (windows) {
61
- let isPingSummaryLineShown = line.slice(-1) === ':';
62
- if (isPingSummaryLineShown) {
63
- return true;
64
- }
65
- }
66
- else {
67
- // Change state if it see a '---'
68
- if (line.indexOf('---') >= 0) {
69
- return true;
70
- }
71
- }
72
- return false;
73
- }
74
- //Function to calculate and create the result
75
- function createResult(result, lines) {
76
- var _a;
77
- // Concat output
78
- result.output = lines === null || lines === void 0 ? void 0 : lines.join('\n');
79
- // Determine alive
80
- result.alive = ((_a = result === null || result === void 0 ? void 0 : result.times) === null || _a === void 0 ? void 0 : _a.length) > 0;
81
- // Update time at first successful line
82
- if (result.alive) {
83
- result.time = result.times[0];
84
- }
85
- // Get stddev
86
- if (result.stddev === undefined && result.alive) {
87
- let N = result.times.length;
88
- const mean = result.times.reduce((a, b) => a + b) / N;
89
- const stddev = Math.sqrt(result.times.map(x => Math.pow(x - mean, 2)).reduce((a, b) => a + b) / N);
90
- result.stddev = stddev;
91
- }
92
- // Fix min, avg, max, stddev up to 3 decimal points
93
- ['min', 'avg', 'max', 'stddev', 'packetLoss'].forEach((key) => {
94
- let v = result[key];
95
- if (typeof v === 'number') {
96
- result[key] = v.toFixed(3);
97
- }
98
- });
99
- return result;
100
- }
101
- //Default response object
102
- const defaultResponse = {
103
- host: undefined,
104
- numericHost: undefined,
105
- alive: false,
106
- output: undefined,
107
- time: undefined,
108
- times: [],
109
- min: undefined,
110
- max: undefined,
111
- avg: undefined,
112
- stddev: undefined,
113
- packetLoss: undefined,
114
- bufferSize: undefined
115
- };
116
- //to strip space present at end of string
117
- const stripRegex = /[ ]*\r?\n?$/g;
118
- //States of parsing - local use only
119
- const states = {
120
- HEADER: 0,
121
- BODY: 1,
122
- FOOTER: 2
123
- };
124
- exports.default = parserFactory;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const helper_1 = require("../helper");
7
+ const errors_1 = require("../errors");
8
+ const windows_1 = __importDefault(require("./windows"));
9
+ const mac_1 = __importDefault(require("./mac"));
10
+ const linux_1 = __importDefault(require("./linux"));
11
+ const messages_1 = require("../messages");
12
+ const clonePingResponse_1 = __importDefault(require("./clonePingResponse"));
13
+ //create instance of parser based on operating system
14
+ function parserFactory(platform, output, options) {
15
+ let parser;
16
+ let isWindows = false;
17
+ const baseReponse = (0, clonePingResponse_1.default)(defaultResponse);
18
+ if (!(0, helper_1.isPlatformSupported)(platform)) {
19
+ throw new errors_1.supportedError(messages_1.ERROR_MESSAGES.PLATFORM_NOT_SUPPORTED.replace('platform', platform));
20
+ }
21
+ if (platform === 'win32') {
22
+ parser = new windows_1.default(baseReponse, options);
23
+ isWindows = true;
24
+ }
25
+ else if (platform === 'darwin') {
26
+ parser = new mac_1.default(baseReponse, options);
27
+ }
28
+ else {
29
+ parser = new linux_1.default(baseReponse, options);
30
+ }
31
+ let result = parseOutput(parser, isWindows, output);
32
+ return result;
33
+ }
34
+ //parsing output line by line
35
+ function parseOutput(parser, isWindows, output) {
36
+ let lines = output === null || output === void 0 ? void 0 : output.join('').split('\n');
37
+ let state = 0;
38
+ let parsedOutput = defaultResponse;
39
+ lines === null || lines === void 0 ? void 0 : lines.forEach((line) => {
40
+ line = line.replace(stripRegex, '');
41
+ if (line.length === 0) {
42
+ // Do nothing if this is an empty line
43
+ }
44
+ else if (state === states.HEADER) {
45
+ parser.processHeader(line);
46
+ state = states.BODY;
47
+ }
48
+ else if (state === states.BODY) {
49
+ (!checkIfBodyEnded(line, isWindows)) ? parser.processBody(line) : state = states.FOOTER;
50
+ }
51
+ else if (state === states.FOOTER) {
52
+ parsedOutput = parser.processFooter(line);
53
+ }
54
+ });
55
+ let result = createResult(parsedOutput, lines);
56
+ return result;
57
+ }
58
+ //function to check if body ended and footer began
59
+ function checkIfBodyEnded(line, windows) {
60
+ if (windows) {
61
+ let isPingSummaryLineShown = line.slice(-1) === ':';
62
+ if (isPingSummaryLineShown) {
63
+ return true;
64
+ }
65
+ }
66
+ else {
67
+ // Change state if it see a '---'
68
+ if (line.indexOf('---') >= 0) {
69
+ return true;
70
+ }
71
+ }
72
+ return false;
73
+ }
74
+ //Function to calculate and create the result
75
+ function createResult(result, lines) {
76
+ var _a;
77
+ // Concat output
78
+ result.output = lines === null || lines === void 0 ? void 0 : lines.join('\n');
79
+ // Determine alive
80
+ result.alive = ((_a = result === null || result === void 0 ? void 0 : result.times) === null || _a === void 0 ? void 0 : _a.length) > 0;
81
+ // Update time at first successful line
82
+ if (result.alive) {
83
+ result.time = result.times[0];
84
+ }
85
+ // Get stddev
86
+ if (result.stddev === undefined && result.alive) {
87
+ let N = result.times.length;
88
+ const mean = result.times.reduce((a, b) => a + b) / N;
89
+ const stddev = Math.sqrt(result.times.map(x => Math.pow(x - mean, 2)).reduce((a, b) => a + b) / N);
90
+ result.stddev = stddev;
91
+ }
92
+ // Fix min, avg, max, stddev up to 3 decimal points
93
+ ['min', 'avg', 'max', 'stddev', 'packetLoss'].forEach((key) => {
94
+ let v = result[key];
95
+ if (typeof v === 'number') {
96
+ result[key] = v.toFixed(3);
97
+ }
98
+ });
99
+ return result;
100
+ }
101
+ //Default response object
102
+ const defaultResponse = {
103
+ host: undefined,
104
+ numericHost: undefined,
105
+ alive: false,
106
+ output: undefined,
107
+ time: undefined,
108
+ times: [],
109
+ min: undefined,
110
+ max: undefined,
111
+ avg: undefined,
112
+ stddev: undefined,
113
+ packetLoss: undefined,
114
+ bufferSize: undefined
115
+ };
116
+ //to strip space present at end of string
117
+ const stripRegex = /[ ]*\r?\n?$/g;
118
+ //States of parsing - local use only
119
+ const states = {
120
+ HEADER: 0,
121
+ BODY: 1,
122
+ FOOTER: 2
123
+ };
124
+ exports.default = parserFactory;
125
125
  //# sourceMappingURL=parserFactory.js.map
@@ -1,13 +1,13 @@
1
- import { extendedPingOptions, pingResponse } from "../types";
2
- import parser from "./parser.interface";
3
- declare class windows implements parser {
4
- config: extendedPingOptions | undefined;
5
- response: pingResponse;
6
- constructor(response: pingResponse, options?: extendedPingOptions);
7
- processHeader(line: string): void;
8
- processBody(line: string): void;
9
- processFooter(line: string): pingResponse;
10
- processIPV4Body(dataFields: string[]): void;
11
- processIPV6Body(dataFields: string[]): void;
12
- }
13
- export default windows;
1
+ import { extendedPingOptions, pingResponse } from "../types";
2
+ import parser from "./parser.interface";
3
+ declare class windows implements parser {
4
+ config: extendedPingOptions | undefined;
5
+ response: pingResponse;
6
+ constructor(response: pingResponse, options?: extendedPingOptions);
7
+ processHeader(line: string): void;
8
+ processBody(line: string): void;
9
+ processFooter(line: string): pingResponse;
10
+ processIPV4Body(dataFields: string[]): void;
11
+ processIPV6Body(dataFields: string[]): void;
12
+ }
13
+ export default windows;
@@ -1,111 +1,111 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class windows {
4
- constructor(response, options) {
5
- this.config = options;
6
- this.response = response;
7
- this.response.times = [];
8
- }
9
- processHeader(line) {
10
- let isPingNumeric = line.indexOf('[') === -1;
11
- const ipv4v6Regex = /((^\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\s*$)|(^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$))/;
12
- // Get host and numeric_host
13
- let words = line.split(' ');
14
- if (isPingNumeric) {
15
- // For those missing [***], get the first token which match IPV4 regex
16
- this.response.host = words.find((word) => {
17
- return ipv4v6Regex.test(word);
18
- });
19
- this.response.numericHost = this.response.host;
20
- }
21
- else {
22
- // For those has [***], anchor with such token
23
- let numericHost = words.find(function (word) {
24
- return word.indexOf('[') !== -1;
25
- });
26
- if (numericHost) {
27
- let numericHostIndex = words.indexOf(numericHost);
28
- let match = /\[(.*)\]/.exec(numericHost);
29
- if (match) {
30
- // Capture IP inside [] only. refs #71
31
- this.response.numericHost = match[1];
32
- }
33
- this.response.host = words[numericHostIndex - 1];
34
- }
35
- }
36
- }
37
- processBody(line) {
38
- var _a;
39
- let isIPV6 = (_a = this.config) === null || _a === void 0 ? void 0 : _a.IPV6;
40
- let words = line.split(' ');
41
- let dataFields = words.filter((word) => {
42
- let isDataField = word.indexOf('=') >= 0 || word.indexOf('<') >= 0;
43
- return isDataField;
44
- });
45
- //if IPV6, body does not have as many fields as IPV4 based on testing
46
- if (isIPV6) {
47
- this.processIPV6Body(dataFields);
48
- }
49
- else {
50
- this.processIPV4Body(dataFields);
51
- }
52
- }
53
- processFooter(line) {
54
- let packetLoss = line.match(/([\d.]+)%/);
55
- if (packetLoss) {
56
- this.response.packetLoss = packetLoss[1];
57
- }
58
- // XXX: Assume there is a keyword ms
59
- if (line.search(/(ms|мсек)/i) >= 0) {
60
- // XXX: Assume the ordering is Min Max Avg
61
- let regExp = /([0-9.]+)/g;
62
- let m1 = regExp.exec(line);
63
- let m2 = regExp.exec(line);
64
- let m3 = regExp.exec(line);
65
- m1 ? this.response.min = parseFloat(m1[1]) : null;
66
- m2 ? this.response.max = parseFloat(m2[1]) : null;
67
- m3 ? this.response.avg = parseFloat(m3[1]) : null;
68
- }
69
- return this.response;
70
- }
71
- //method to process IPV4 Specific Body
72
- processIPV4Body(dataFields) {
73
- var _a, _b;
74
- const expectDataFieldInReplyLine = 3;
75
- let isReplyLine = dataFields.length >= expectDataFieldInReplyLine;
76
- if (isReplyLine) {
77
- // XXX: Assume time will alaways get keyword ms for all language
78
- let timeField = dataFields.find((field) => {
79
- return field.search(/(ms|мс)/i) >= 0;
80
- });
81
- if (timeField) {
82
- let regExp = /([0-9.]+)/;
83
- let match = regExp.exec(timeField);
84
- let timeFieldIndex = dataFields.indexOf(timeField);
85
- match ? (_b = (_a = this.response) === null || _a === void 0 ? void 0 : _a.times) === null || _b === void 0 ? void 0 : _b.push(parseFloat(match[1])) : null;
86
- // XXX: Assume byte field will be just before the time field
87
- let bytesField = dataFields[timeFieldIndex - 1];
88
- match = regExp.exec(bytesField);
89
- match ? this.response.bufferSize = parseFloat(match[1]) : null;
90
- }
91
- }
92
- }
93
- //method to process IPV6 Specific Body
94
- processIPV6Body(dataFields) {
95
- var _a, _b;
96
- let expectDataFieldInReplyLine = 1;
97
- if (dataFields.length >= expectDataFieldInReplyLine) {
98
- // XXX: Assume time will alaways get keyword ms for all language
99
- let timeField = dataFields.find((dataField) => {
100
- return dataField.search(/(ms|мс)/i) >= 0;
101
- });
102
- const regExp = /([0-9.]+)/;
103
- if (timeField) {
104
- let match = regExp.exec(timeField);
105
- match ? (_b = (_a = this.response) === null || _a === void 0 ? void 0 : _a.times) === null || _b === void 0 ? void 0 : _b.push(parseFloat(match[1])) : null;
106
- }
107
- }
108
- }
109
- }
110
- exports.default = windows;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class windows {
4
+ constructor(response, options) {
5
+ this.config = options;
6
+ this.response = response;
7
+ this.response.times = [];
8
+ }
9
+ processHeader(line) {
10
+ let isPingNumeric = line.indexOf('[') === -1;
11
+ const ipv4v6Regex = /((^\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\s*$)|(^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$))/;
12
+ // Get host and numeric_host
13
+ let words = line.split(' ');
14
+ if (isPingNumeric) {
15
+ // For those missing [***], get the first token which match IPV4 regex
16
+ this.response.host = words.find((word) => {
17
+ return ipv4v6Regex.test(word);
18
+ });
19
+ this.response.numericHost = this.response.host;
20
+ }
21
+ else {
22
+ // For those has [***], anchor with such token
23
+ let numericHost = words.find(function (word) {
24
+ return word.indexOf('[') !== -1;
25
+ });
26
+ if (numericHost) {
27
+ let numericHostIndex = words.indexOf(numericHost);
28
+ let match = /\[(.*)\]/.exec(numericHost);
29
+ if (match) {
30
+ // Capture IP inside [] only. refs #71
31
+ this.response.numericHost = match[1];
32
+ }
33
+ this.response.host = words[numericHostIndex - 1];
34
+ }
35
+ }
36
+ }
37
+ processBody(line) {
38
+ var _a;
39
+ let isIPV6 = (_a = this.config) === null || _a === void 0 ? void 0 : _a.IPV6;
40
+ let words = line.split(' ');
41
+ let dataFields = words.filter((word) => {
42
+ let isDataField = word.indexOf('=') >= 0 || word.indexOf('<') >= 0;
43
+ return isDataField;
44
+ });
45
+ //if IPV6, body does not have as many fields as IPV4 based on testing
46
+ if (isIPV6) {
47
+ this.processIPV6Body(dataFields);
48
+ }
49
+ else {
50
+ this.processIPV4Body(dataFields);
51
+ }
52
+ }
53
+ processFooter(line) {
54
+ let packetLoss = line.match(/([\d.]+)%/);
55
+ if (packetLoss) {
56
+ this.response.packetLoss = packetLoss[1];
57
+ }
58
+ // XXX: Assume there is a keyword ms
59
+ if (line.search(/(ms|мсек)/i) >= 0) {
60
+ // XXX: Assume the ordering is Min Max Avg
61
+ let regExp = /([0-9.]+)/g;
62
+ let m1 = regExp.exec(line);
63
+ let m2 = regExp.exec(line);
64
+ let m3 = regExp.exec(line);
65
+ m1 ? this.response.min = parseFloat(m1[1]) : null;
66
+ m2 ? this.response.max = parseFloat(m2[1]) : null;
67
+ m3 ? this.response.avg = parseFloat(m3[1]) : null;
68
+ }
69
+ return this.response;
70
+ }
71
+ //method to process IPV4 Specific Body
72
+ processIPV4Body(dataFields) {
73
+ var _a, _b;
74
+ const expectDataFieldInReplyLine = 3;
75
+ let isReplyLine = dataFields.length >= expectDataFieldInReplyLine;
76
+ if (isReplyLine) {
77
+ // XXX: Assume time will alaways get keyword ms for all language
78
+ let timeField = dataFields.find((field) => {
79
+ return field.search(/(ms|мс)/i) >= 0;
80
+ });
81
+ if (timeField) {
82
+ let regExp = /([0-9.]+)/;
83
+ let match = regExp.exec(timeField);
84
+ let timeFieldIndex = dataFields.indexOf(timeField);
85
+ match ? (_b = (_a = this.response) === null || _a === void 0 ? void 0 : _a.times) === null || _b === void 0 ? void 0 : _b.push(parseFloat(match[1])) : null;
86
+ // XXX: Assume byte field will be just before the time field
87
+ let bytesField = dataFields[timeFieldIndex - 1];
88
+ match = regExp.exec(bytesField);
89
+ match ? this.response.bufferSize = parseFloat(match[1]) : null;
90
+ }
91
+ }
92
+ }
93
+ //method to process IPV6 Specific Body
94
+ processIPV6Body(dataFields) {
95
+ var _a, _b;
96
+ let expectDataFieldInReplyLine = 1;
97
+ if (dataFields.length >= expectDataFieldInReplyLine) {
98
+ // XXX: Assume time will alaways get keyword ms for all language
99
+ let timeField = dataFields.find((dataField) => {
100
+ return dataField.search(/(ms|мс)/i) >= 0;
101
+ });
102
+ const regExp = /([0-9.]+)/;
103
+ if (timeField) {
104
+ let match = regExp.exec(timeField);
105
+ match ? (_b = (_a = this.response) === null || _a === void 0 ? void 0 : _a.times) === null || _b === void 0 ? void 0 : _b.push(parseFloat(match[1])) : null;
106
+ }
107
+ }
108
+ }
109
+ }
110
+ exports.default = windows;
111
111
  //# sourceMappingURL=windows.js.map
@@ -1,3 +1,3 @@
1
- import { commandBuilder } from "./types";
2
- declare const execute: (builtCommand: commandBuilder) => Promise<any>;
3
- export default execute;
1
+ import { commandBuilder } from "./types";
2
+ declare const execute: (builtCommand: commandBuilder) => Promise<any>;
3
+ export default execute;
package/dist/src/ping.js CHANGED
@@ -1,23 +1,23 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const child_process_1 = require("child_process");
4
- const errors_1 = require("./errors");
5
- const messages_1 = require("./messages");
6
- const execute = async (builtCommand) => {
7
- let output = [];
8
- return new Promise((resolve, reject) => {
9
- var _a;
10
- const ping = (0, child_process_1.spawn)(builtCommand.command, builtCommand.arguments);
11
- ping.once("error", () => {
12
- reject(new errors_1.pingError(messages_1.ERROR_MESSAGES.GENERAL_PING_ERROR.replace("cmd", builtCommand.command).replace("args", builtCommand.arguments.toString())));
13
- });
14
- (_a = ping.stdout) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
15
- output.push(String(data));
16
- });
17
- ping.on("close", () => {
18
- resolve(output);
19
- });
20
- });
21
- };
22
- exports.default = execute;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const child_process_1 = require("child_process");
4
+ const errors_1 = require("./errors");
5
+ const messages_1 = require("./messages");
6
+ const execute = async (builtCommand) => {
7
+ let output = [];
8
+ return new Promise((resolve, reject) => {
9
+ var _a;
10
+ const ping = (0, child_process_1.spawn)(builtCommand.command, builtCommand.arguments);
11
+ ping.once("error", () => {
12
+ reject(new errors_1.pingError(messages_1.ERROR_MESSAGES.GENERAL_PING_ERROR.replace("cmd", builtCommand.command).replace("args", builtCommand.arguments.toString())));
13
+ });
14
+ (_a = ping.stdout) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
15
+ output.push(String(data));
16
+ });
17
+ ping.on("close", () => {
18
+ resolve(output);
19
+ });
20
+ });
21
+ };
22
+ exports.default = execute;
23
23
  //# sourceMappingURL=ping.js.map
@@ -1,44 +1,44 @@
1
- export interface extendedPingOptions extends pingOptions {
2
- recordRouteHops?: number;
3
- hopTimestamp?: number;
4
- interval?: number;
5
- soDebugOption?: boolean;
6
- floodPing?: boolean;
7
- interfaceAddress?: string;
8
- suppressLoopback?: boolean;
9
- pattern?: string;
10
- quiet?: boolean;
11
- timeBeforeExit?: number;
12
- verboseOutput?: boolean;
13
- doNotFragment?: boolean;
14
- srcAddr?: string;
15
- }
16
- export interface pingOptions {
17
- numeric?: boolean;
18
- bufferSize?: number;
19
- logToFile?: boolean;
20
- logFilePath?: string;
21
- IPV6?: boolean;
22
- IPV4?: boolean;
23
- numberOfEchos?: number;
24
- TTL?: number;
25
- timeout?: number;
26
- }
27
- export type commandBuilder = {
28
- command: string;
29
- arguments: string[];
30
- };
31
- export type pingResponse = {
32
- host: string | undefined;
33
- numericHost: string | undefined;
34
- alive: boolean | undefined;
35
- output: string | undefined;
36
- time: number | undefined;
37
- times: Array<number>;
38
- min: number | undefined;
39
- max: number | undefined;
40
- avg: number | undefined;
41
- bufferSize: number | undefined;
42
- stddev: number | undefined;
43
- packetLoss: string | undefined;
44
- };
1
+ export interface extendedPingOptions extends pingOptions {
2
+ recordRouteHops?: number;
3
+ hopTimestamp?: number;
4
+ interval?: number;
5
+ soDebugOption?: boolean;
6
+ floodPing?: boolean;
7
+ interfaceAddress?: string;
8
+ suppressLoopback?: boolean;
9
+ pattern?: string;
10
+ quiet?: boolean;
11
+ timeBeforeExit?: number;
12
+ verboseOutput?: boolean;
13
+ doNotFragment?: boolean;
14
+ srcAddr?: string;
15
+ }
16
+ export interface pingOptions {
17
+ numeric?: boolean;
18
+ bufferSize?: number;
19
+ logToFile?: boolean;
20
+ logFilePath?: string;
21
+ IPV6?: boolean;
22
+ IPV4?: boolean;
23
+ numberOfEchos?: number;
24
+ TTL?: number;
25
+ timeout?: number;
26
+ }
27
+ export type commandBuilder = {
28
+ command: string;
29
+ arguments: string[];
30
+ };
31
+ export type pingResponse = {
32
+ host: string | undefined;
33
+ numericHost: string | undefined;
34
+ alive: boolean | undefined;
35
+ output: string | undefined;
36
+ time: number | undefined;
37
+ times: Array<number>;
38
+ min: number | undefined;
39
+ max: number | undefined;
40
+ avg: number | undefined;
41
+ bufferSize: number | undefined;
42
+ stddev: number | undefined;
43
+ packetLoss: string | undefined;
44
+ };
package/dist/src/types.js CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  //# sourceMappingURL=types.js.map