pingman 1.2.0 → 2.1.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.
- package/LICENSE +21 -21
- package/README.md +57 -45
- package/dist/src/builder/builder.d.ts +3 -3
- package/dist/src/builder/builder.js +31 -30
- package/dist/src/builder/builder.js.map +1 -0
- package/dist/src/builder/linux.d.ts +3 -3
- package/dist/src/builder/linux.js +83 -82
- package/dist/src/builder/linux.js.map +1 -0
- package/dist/src/builder/mac.d.ts +3 -3
- package/dist/src/builder/mac.js +89 -88
- package/dist/src/builder/mac.js.map +1 -0
- package/dist/src/builder/windows.d.ts +3 -3
- package/dist/src/builder/windows.js +94 -93
- package/dist/src/builder/windows.js.map +1 -0
- package/dist/src/errors.d.ts +10 -10
- package/dist/src/errors.js +26 -25
- package/dist/src/errors.js.map +1 -0
- package/dist/src/helper.d.ts +2 -2
- package/dist/src/helper.js +34 -33
- package/dist/src/helper.js.map +1 -0
- package/dist/src/index.d.ts +4 -4
- package/dist/src/index.js +57 -56
- package/dist/src/index.js.map +1 -0
- package/dist/src/log.d.ts +7 -7
- package/dist/src/log.js +26 -25
- package/dist/src/log.js.map +1 -0
- package/dist/src/messages.d.ts +9 -9
- package/dist/src/messages.js +13 -12
- package/dist/src/messages.js.map +1 -0
- package/dist/src/parser/clonePingResponse.d.ts +3 -0
- package/dist/src/parser/clonePingResponse.js +21 -0
- package/dist/src/parser/clonePingResponse.js.map +1 -0
- package/dist/src/parser/linux.d.ts +7 -7
- package/dist/src/parser/linux.js +31 -30
- package/dist/src/parser/linux.js.map +1 -0
- package/dist/src/parser/mac.d.ts +11 -11
- package/dist/src/parser/mac.js +47 -46
- package/dist/src/parser/mac.js.map +1 -0
- package/dist/src/parser/parser.interface.d.ts +8 -8
- package/dist/src/parser/parser.interface.js +3 -2
- package/dist/src/parser/parser.interface.js.map +1 -0
- package/dist/src/parser/parserFactory.d.ts +3 -3
- package/dist/src/parser/parserFactory.js +125 -122
- package/dist/src/parser/parserFactory.js.map +1 -0
- package/dist/src/parser/windows.d.ts +13 -13
- package/dist/src/parser/windows.js +111 -110
- package/dist/src/parser/windows.js.map +1 -0
- package/dist/src/ping.d.ts +3 -3
- package/dist/src/ping.js +23 -22
- package/dist/src/ping.js.map +1 -0
- package/dist/src/types.d.ts +44 -44
- package/dist/src/types.js +3 -2
- package/dist/src/types.js.map +1 -0
- package/package.json +6 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clonePingResponse.js","sourceRoot":"","sources":["../../../src/parser/clonePingResponse.ts"],"names":[],"mappings":";;AAEA,SAAS,iBAAiB,CAAC,GAAiB;;IAC1C,OAAO;QACL,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,WAAW,EAAE,GAAG,CAAC,WAAW;QAC5B,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,KAAK,EAAE,CAAA,MAAA,GAAG,CAAC,KAAK,0CAAE,MAAM,EAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;QAC9C,GAAG,EAAE,GAAG,CAAC,GAAG;QACZ,GAAG,EAAE,GAAG,CAAC,GAAG;QACZ,GAAG,EAAE,GAAG,CAAC,GAAG;QACZ,UAAU,EAAE,GAAG,CAAC,UAAU;QAC1B,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,UAAU,EAAE,GAAG,CAAC,UAAU;KAC3B,CAAC;AACJ,CAAC;AAED,kBAAe,iBAAiB,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import mac from "./mac";
|
|
2
|
-
import { pingResponse, extendedPingOptions } from "../types";
|
|
3
|
-
declare class linux extends mac {
|
|
4
|
-
constructor(response: pingResponse, options?: extendedPingOptions);
|
|
5
|
-
processHeader(line: string): void;
|
|
6
|
-
}
|
|
7
|
-
export default linux;
|
|
1
|
+
import mac from "./mac";
|
|
2
|
+
import { pingResponse, extendedPingOptions } from "../types";
|
|
3
|
+
declare class linux extends mac {
|
|
4
|
+
constructor(response: pingResponse, options?: extendedPingOptions);
|
|
5
|
+
processHeader(line: string): void;
|
|
6
|
+
}
|
|
7
|
+
export default linux;
|
package/dist/src/parser/linux.js
CHANGED
|
@@ -1,30 +1,31 @@
|
|
|
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 mac_1 = __importDefault(require("./mac"));
|
|
7
|
-
//extends mac as body and footer identical for mac and linux.Can use mac functions
|
|
8
|
-
class linux extends mac_1.default {
|
|
9
|
-
constructor(response, options) {
|
|
10
|
-
super(response, options);
|
|
11
|
-
}
|
|
12
|
-
processHeader(line) {
|
|
13
|
-
// Get host and numeric_host
|
|
14
|
-
let tokens = line.split(' ');
|
|
15
|
-
let isProbablyIPv4 = tokens[1].indexOf('(') === -1;
|
|
16
|
-
if (isProbablyIPv4) {
|
|
17
|
-
this.response.host = tokens[1];
|
|
18
|
-
this.response.numericHost = tokens[2].slice(1, -1);
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
// Normalise into either a 2 or 3 element array
|
|
22
|
-
let foundAddresses = tokens.slice(1, -3).join('').match(/([^\s()]+)/g);
|
|
23
|
-
if (foundAddresses) {
|
|
24
|
-
this.response.host = foundAddresses.shift();
|
|
25
|
-
this.response.numericHost = foundAddresses.pop();
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
exports.default = linux;
|
|
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 mac_1 = __importDefault(require("./mac"));
|
|
7
|
+
//extends mac as body and footer identical for mac and linux.Can use mac functions
|
|
8
|
+
class linux extends mac_1.default {
|
|
9
|
+
constructor(response, options) {
|
|
10
|
+
super(response, options);
|
|
11
|
+
}
|
|
12
|
+
processHeader(line) {
|
|
13
|
+
// Get host and numeric_host
|
|
14
|
+
let tokens = line.split(' ');
|
|
15
|
+
let isProbablyIPv4 = tokens[1].indexOf('(') === -1;
|
|
16
|
+
if (isProbablyIPv4) {
|
|
17
|
+
this.response.host = tokens[1];
|
|
18
|
+
this.response.numericHost = tokens[2].slice(1, -1);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
// Normalise into either a 2 or 3 element array
|
|
22
|
+
let foundAddresses = tokens.slice(1, -3).join('').match(/([^\s()]+)/g);
|
|
23
|
+
if (foundAddresses) {
|
|
24
|
+
this.response.host = foundAddresses.shift();
|
|
25
|
+
this.response.numericHost = foundAddresses.pop();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.default = linux;
|
|
31
|
+
//# sourceMappingURL=linux.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"linux.js","sourceRoot":"","sources":["../../../src/parser/linux.ts"],"names":[],"mappings":";;;;;AAAA,gDAAwB;AAGxB,kFAAkF;AAClF,MAAM,KAAM,SAAQ,aAAG;IACnB,YAAY,QAAsB,EAAE,OAA6B;QAC7D,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC7B,CAAC;IAED,aAAa,CAAC,IAAY;QACtB,4BAA4B;QAC5B,IAAI,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,cAAc,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;QAEnD,IAAI,cAAc,EAAE;YAChB,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YAC/B,IAAI,CAAC,QAAQ,CAAC,WAAW,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;SACtD;aAAM;YACH,+CAA+C;YAC/C,IAAI,cAAc,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;YACvE,IAAG,cAAc,EAAC;gBACd,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,cAAc,CAAC,KAAK,EAAE,CAAC;gBAC5C,IAAI,CAAC,QAAQ,CAAC,WAAW,GAAG,cAAc,CAAC,GAAG,EAAE,CAAC;aACpD;SACJ;IACL,CAAC;CACJ;AAED,kBAAe,KAAK,CAAC"}
|
package/dist/src/parser/mac.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { extendedPingOptions, pingResponse } from "../types";
|
|
2
|
-
import parser from "./parser.interface";
|
|
3
|
-
declare class mac 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
|
-
}
|
|
11
|
-
export default mac;
|
|
1
|
+
import { extendedPingOptions, pingResponse } from "../types";
|
|
2
|
+
import parser from "./parser.interface";
|
|
3
|
+
declare class mac 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
|
+
}
|
|
11
|
+
export default mac;
|
package/dist/src/parser/mac.js
CHANGED
|
@@ -1,46 +1,47 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
class mac {
|
|
4
|
-
constructor(response, options) {
|
|
5
|
-
this.config = options;
|
|
6
|
-
this.response = response;
|
|
7
|
-
this.response.times = [];
|
|
8
|
-
}
|
|
9
|
-
processHeader(line) {
|
|
10
|
-
// Get host and numeric_host
|
|
11
|
-
let tokens = line.split(' ');
|
|
12
|
-
this.response.host = tokens[1];
|
|
13
|
-
this.response.numericHost = tokens[2].slice(1, -2);
|
|
14
|
-
}
|
|
15
|
-
processBody(line) {
|
|
16
|
-
// XXX: Assume there is at least 3 '=' can be found
|
|
17
|
-
let count = (line.match(/=/g) || []).length;
|
|
18
|
-
if (count >= 3) {
|
|
19
|
-
let regExp = /([0-9.]+)[ ]*ms/;
|
|
20
|
-
let match = regExp.exec(line);
|
|
21
|
-
match ? this.response.times.push(parseFloat(match[1])) : null;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
processFooter(line) {
|
|
25
|
-
let packetLoss = line.match(/ ([\d.]+)%/);
|
|
26
|
-
if (packetLoss) {
|
|
27
|
-
this.response.packetLoss = packetLoss[1];
|
|
28
|
-
}
|
|
29
|
-
// XXX: Assume number of keywords '/' more than 3
|
|
30
|
-
const count = (line.match(/[/]/g) || []).length;
|
|
31
|
-
if (count >= 3) {
|
|
32
|
-
const regExp = /([0-9.]+)/g;
|
|
33
|
-
// XXX: Assume min avg max stddev
|
|
34
|
-
let m1 = regExp.exec(line);
|
|
35
|
-
let m2 = regExp.exec(line);
|
|
36
|
-
let m3 = regExp.exec(line);
|
|
37
|
-
let m4 = regExp.exec(line);
|
|
38
|
-
m1 ? this.response.min = parseFloat(m1[1]) : null;
|
|
39
|
-
m2 ? this.response.avg = parseFloat(m2[1]) : null;
|
|
40
|
-
m3 ? this.response.max = parseFloat(m3[1]) : null;
|
|
41
|
-
m4 ? this.response.stddev = parseFloat(m4[1]) : null;
|
|
42
|
-
}
|
|
43
|
-
return this.response;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
exports.default = mac;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class mac {
|
|
4
|
+
constructor(response, options) {
|
|
5
|
+
this.config = options;
|
|
6
|
+
this.response = response;
|
|
7
|
+
this.response.times = [];
|
|
8
|
+
}
|
|
9
|
+
processHeader(line) {
|
|
10
|
+
// Get host and numeric_host
|
|
11
|
+
let tokens = line.split(' ');
|
|
12
|
+
this.response.host = tokens[1];
|
|
13
|
+
this.response.numericHost = tokens[2].slice(1, -2);
|
|
14
|
+
}
|
|
15
|
+
processBody(line) {
|
|
16
|
+
// XXX: Assume there is at least 3 '=' can be found
|
|
17
|
+
let count = (line.match(/=/g) || []).length;
|
|
18
|
+
if (count >= 3) {
|
|
19
|
+
let regExp = /([0-9.]+)[ ]*ms/;
|
|
20
|
+
let match = regExp.exec(line);
|
|
21
|
+
match ? this.response.times.push(parseFloat(match[1])) : null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
processFooter(line) {
|
|
25
|
+
let packetLoss = line.match(/ ([\d.]+)%/);
|
|
26
|
+
if (packetLoss) {
|
|
27
|
+
this.response.packetLoss = packetLoss[1];
|
|
28
|
+
}
|
|
29
|
+
// XXX: Assume number of keywords '/' more than 3
|
|
30
|
+
const count = (line.match(/[/]/g) || []).length;
|
|
31
|
+
if (count >= 3) {
|
|
32
|
+
const regExp = /([0-9.]+)/g;
|
|
33
|
+
// XXX: Assume min avg max stddev
|
|
34
|
+
let m1 = regExp.exec(line);
|
|
35
|
+
let m2 = regExp.exec(line);
|
|
36
|
+
let m3 = regExp.exec(line);
|
|
37
|
+
let m4 = regExp.exec(line);
|
|
38
|
+
m1 ? this.response.min = parseFloat(m1[1]) : null;
|
|
39
|
+
m2 ? this.response.avg = parseFloat(m2[1]) : null;
|
|
40
|
+
m3 ? this.response.max = parseFloat(m3[1]) : null;
|
|
41
|
+
m4 ? this.response.stddev = parseFloat(m4[1]) : null;
|
|
42
|
+
}
|
|
43
|
+
return this.response;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.default = mac;
|
|
47
|
+
//# sourceMappingURL=mac.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mac.js","sourceRoot":"","sources":["../../../src/parser/mac.ts"],"names":[],"mappings":";;AAGA,MAAM,GAAG;IAGL,YAAY,QAAsB,EAAE,OAA6B;QAC7D,IAAI,CAAC,MAAM,GAAG,OAAO,CAAA;QACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,QAAQ,CAAC,KAAK,GAAG,EAAE,CAAA;IAC5B,CAAC;IAED,aAAa,CAAC,IAAY;QACtB,4BAA4B;QAC5B,IAAI,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAE7B,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QAC/B,IAAI,CAAC,QAAQ,CAAC,WAAW,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACvD,CAAC;IAED,WAAW,CAAC,IAAY;QACpB,mDAAmD;QACnD,IAAI,KAAK,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;QAC5C,IAAI,KAAK,IAAI,CAAC,EAAE;YACZ,IAAI,MAAM,GAAG,iBAAiB,CAAC;YAC/B,IAAI,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC9B,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,KA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G,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;SACxD;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;CACJ;AAED,kBAAe,GAAG,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { extendedPingOptions, pingResponse } from "../types";
|
|
2
|
-
interface parser {
|
|
3
|
-
config?: extendedPingOptions;
|
|
4
|
-
processHeader(line: string): void;
|
|
5
|
-
processBody(line: string): void;
|
|
6
|
-
processFooter(line: string): pingResponse;
|
|
7
|
-
}
|
|
8
|
-
export default parser;
|
|
1
|
+
import { extendedPingOptions, pingResponse } from "../types";
|
|
2
|
+
interface parser {
|
|
3
|
+
config?: extendedPingOptions;
|
|
4
|
+
processHeader(line: string): void;
|
|
5
|
+
processBody(line: string): void;
|
|
6
|
+
processFooter(line: string): pingResponse;
|
|
7
|
+
}
|
|
8
|
+
export default parser;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
//# sourceMappingURL=parser.interface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.interface.js","sourceRoot":"","sources":["../../../src/parser/parser.interface.ts"],"names":[],"mappings":""}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { extendedPingOptions, pingResponse } from '../types';
|
|
2
|
-
declare function parserFactory(platform: string, output?: string[], options?: extendedPingOptions): pingResponse;
|
|
3
|
-
export default parserFactory;
|
|
1
|
+
import { extendedPingOptions, pingResponse } from '../types';
|
|
2
|
+
declare function parserFactory(platform: string, output?: string[], options?: extendedPingOptions): pingResponse;
|
|
3
|
+
export default parserFactory;
|
|
@@ -1,122 +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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
let
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
let
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
//
|
|
78
|
-
result.
|
|
79
|
-
//
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
result.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
//
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
+
//# sourceMappingURL=parserFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parserFactory.js","sourceRoot":"","sources":["../../../src/parser/parserFactory.ts"],"names":[],"mappings":";;;;;AAAA,sCAA+C;AAC/C,sCAA0C;AAC1C,wDAA+B;AAC/B,gDAAuB;AACvB,oDAA2B;AAE3B,0CAA4C;AAE5C,4EAAmD;AAEnD,qDAAqD;AACrD,SAAS,aAAa,CAAC,QAAgB,EAAE,MAAiB,EAAE,OAA6B;IACrF,IAAI,MAAc,CAAC;IACnB,IAAI,SAAS,GAAY,KAAK,CAAC;IAC/B,MAAM,WAAW,GAAG,IAAA,2BAAiB,EAAC,eAAe,CAAC,CAAA;IACtD,IAAI,CAAC,IAAA,4BAAmB,EAAC,QAAQ,CAAC,EAAE;QAChC,MAAM,IAAI,uBAAc,CAAC,yBAAc,CAAC,sBAAsB,CAAC,OAAO,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;KACjG;IACD,IAAI,QAAQ,KAAK,OAAO,EAAE;QACtB,MAAM,GAAG,IAAI,iBAAO,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QAC3C,SAAS,GAAG,IAAI,CAAC;KACpB;SAAM,IAAI,QAAQ,KAAK,QAAQ,EAAE;QAC9B,MAAM,GAAG,IAAI,aAAG,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;KAC1C;SAAM;QACH,MAAM,GAAG,IAAI,eAAK,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;KAC5C;IACD,IAAI,MAAM,GAAG,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IACpD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,6BAA6B;AAC7B,SAAS,WAAW,CAAC,MAAc,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AAG,MAAM,CAAC;KAC1B;IAED,mDAAmD;IACnD,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QAC1D,IAAI,CAAC,GAAI,MAAc,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE;YACtB,MAAc,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;SACvC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,yBAAyB;AACzB,MAAM,eAAe,GAAiB;IAClC,IAAI,EAAE,SAAS;IACf,WAAW,EAAE,SAAS;IACtB,KAAK,EAAE,KAAK;IACZ,MAAM,EAAE,SAAS;IACjB,IAAI,EAAE,SAAS;IACf,KAAK,EAAE,EAAE;IACT,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,MAAM,EAAE,SAAS;IACjB,UAAU,EAAE,SAAS;IACrB,UAAU,EAAE,SAAS;CACxB,CAAC;AAEF,yCAAyC;AACzC,MAAM,UAAU,GAAW,cAAc,CAAC;AAE1C,oCAAoC;AACpC,MAAM,MAAM,GAAG;IACX,MAAM,EAAE,CAAC;IACT,IAAI,EAAE,CAAC;IACP,MAAM,EAAE,CAAC;CACZ,CAAC;AAEF,kBAAe,aAAa,CAAC"}
|
|
@@ -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;
|