node-opcua-utils 2.98.0 → 2.104.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/dist/buffer_ellipsis.d.ts +5 -0
- package/dist/buffer_ellipsis.js +17 -0
- package/dist/buffer_ellipsis.js.map +1 -0
- package/dist/compare_buffers.d.ts +2 -0
- package/dist/compare_buffers.js +30 -0
- package/dist/compare_buffers.js.map +1 -0
- package/dist/function_variadic.d.ts +1 -0
- package/dist/function_variadic.js +3 -0
- package/dist/function_variadic.js.map +1 -0
- package/dist/get_clock_tick.d.ts +4 -0
- package/dist/get_clock_tick.js +17 -0
- package/dist/get_clock_tick.js.map +1 -0
- package/dist/get_function_parameters_name.d.ts +2 -0
- package/dist/get_function_parameters_name.js +18 -0
- package/dist/get_function_parameters_name.js.map +1 -0
- package/dist/hrtime.d.ts +2 -0
- package/dist/hrtime.js +32 -0
- package/dist/hrtime.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +75 -0
- package/dist/index.js.map +1 -0
- package/dist/line_file.d.ts +9 -0
- package/dist/line_file.js +24 -0
- package/dist/line_file.js.map +1 -0
- package/dist/match_uri.d.ts +11 -0
- package/dist/match_uri.js +24 -0
- package/dist/match_uri.js.map +1 -0
- package/dist/object_classname.d.ts +9 -0
- package/dist/object_classname.js +16 -0
- package/dist/object_classname.js.map +1 -0
- package/dist/replace_buffer_with_hex_dump.d.ts +6 -0
- package/dist/replace_buffer_with_hex_dump.js +21 -0
- package/dist/replace_buffer_with_hex_dump.js.map +1 -0
- package/dist/set_deprecated.d.ts +2 -0
- package/dist/set_deprecated.js +29 -0
- package/dist/set_deprecated.js.map +1 -0
- package/dist/string_utils.d.ts +66 -0
- package/dist/string_utils.js +128 -0
- package/dist/string_utils.js.map +1 -0
- package/dist/timestamp.d.ts +1 -0
- package/dist/timestamp.js +14 -0
- package/dist/timestamp.js.map +1 -0
- package/dist/watchdog.d.ts +57 -0
- package/dist/watchdog.js +143 -0
- package/dist/watchdog.js.map +1 -0
- package/package.json +9 -5
- package/source/compare_buffers.ts +1 -1
- package/source/set_deprecated.ts +1 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buffer_ellipsis = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @module node-opcua-utils
|
|
6
|
+
*/
|
|
7
|
+
function buffer_ellipsis(buffer, start, end) {
|
|
8
|
+
start = start || 0;
|
|
9
|
+
end = end || buffer.length;
|
|
10
|
+
if (end - start < 40) {
|
|
11
|
+
return buffer.subarray(start, end).toString("hex");
|
|
12
|
+
}
|
|
13
|
+
return buffer.subarray(start, start + 10).toString("hex") + " ... " + buffer.subarray(end - 10, end).toString("hex");
|
|
14
|
+
}
|
|
15
|
+
exports.buffer_ellipsis = buffer_ellipsis;
|
|
16
|
+
exports.buffer_ellipsis = buffer_ellipsis;
|
|
17
|
+
//# sourceMappingURL=buffer_ellipsis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffer_ellipsis.js","sourceRoot":"","sources":["../source/buffer_ellipsis.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,SAAgB,eAAe,CAAC,MAAc,EAAE,KAAc,EAAE,GAAY;IACxE,KAAK,GAAG,KAAK,IAAI,CAAC,CAAC;IACnB,GAAG,GAAG,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC;IAC3B,IAAI,GAAG,GAAG,KAAK,GAAG,EAAE,EAAE;QAClB,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;KACtD;IACD,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,GAAG,EAAE,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACzH,CAAC;AAPD,0CAOC;AAED,OAAO,CAAC,eAAe,GAAG,eAAe,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
exports.compare_buffers = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* @module node-opcua-utils
|
|
9
|
+
*/
|
|
10
|
+
// tslint:disable:no-console
|
|
11
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
12
|
+
const buffer_ellipsis_1 = require("./buffer_ellipsis");
|
|
13
|
+
function compare_buffers(buf1, buf2, max_length) {
|
|
14
|
+
max_length = max_length || buf2.length;
|
|
15
|
+
const block_length = 80;
|
|
16
|
+
let cursor = 0;
|
|
17
|
+
while (cursor < max_length) {
|
|
18
|
+
const slice1 = buf1.subarray(cursor, cursor + block_length);
|
|
19
|
+
const slice2 = buf2.subarray(cursor, cursor + block_length);
|
|
20
|
+
if (slice2.toString("hex") !== slice1.toString("hex")) {
|
|
21
|
+
console.log("pos = ", cursor);
|
|
22
|
+
console.log("slice1 :", chalk_1.default.yellow((0, buffer_ellipsis_1.buffer_ellipsis)(slice1)));
|
|
23
|
+
console.log("slice2 :", chalk_1.default.blue((0, buffer_ellipsis_1.buffer_ellipsis)(slice2)));
|
|
24
|
+
}
|
|
25
|
+
cursor += block_length;
|
|
26
|
+
}
|
|
27
|
+
// xx buf1.length.should.equal(max_length);
|
|
28
|
+
}
|
|
29
|
+
exports.compare_buffers = compare_buffers;
|
|
30
|
+
//# sourceMappingURL=compare_buffers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compare_buffers.js","sourceRoot":"","sources":["../source/compare_buffers.ts"],"names":[],"mappings":";;;;;;AAAA;;GAEG;AACH,4BAA4B;AAC5B,kDAA0B;AAC1B,uDAAoD;AAEpD,SAAgB,eAAe,CAAC,IAAY,EAAE,IAAY,EAAE,UAAmB;IAC3E,UAAU,GAAG,UAAU,IAAI,IAAI,CAAC,MAAM,CAAC;IACvC,MAAM,YAAY,GAAG,EAAE,CAAC;IACxB,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,OAAO,MAAM,GAAG,UAAU,EAAE;QACxB,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAAC,CAAC;QAC5D,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAAC,CAAC;QAC5D,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;YACnD,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;YAC9B,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,eAAK,CAAC,MAAM,CAAC,IAAA,iCAAe,EAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YAC/D,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,eAAK,CAAC,IAAI,CAAC,IAAA,iCAAe,EAAC,MAAM,CAAC,CAAC,CAAC,CAAC;SAChE;QACD,MAAM,IAAI,YAAY,CAAC;KAC1B;IACD,2CAA2C;AAC/C,CAAC;AAfD,0CAeC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type FunctionVariadic = (...args: any[]) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function_variadic.js","sourceRoot":"","sources":["../source/function_variadic.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.get_clock_tick = void 0;
|
|
4
|
+
if (typeof process === "object" && process.hrtime) {
|
|
5
|
+
const tickOrigin = process.hrtime();
|
|
6
|
+
// clock it as a double in millisecond
|
|
7
|
+
// so we can measure very tiny time intervals
|
|
8
|
+
exports.get_clock_tick = () => {
|
|
9
|
+
const hrt = process.hrtime(tickOrigin);
|
|
10
|
+
const r = (hrt[0]) * 1000.0 + Math.ceil((hrt[1] / 1e6) * 1000) / 1000;
|
|
11
|
+
return r;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
exports.get_clock_tick = () => Date.now();
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=get_clock_tick.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get_clock_tick.js","sourceRoot":"","sources":["../source/get_clock_tick.ts"],"names":[],"mappings":";;;AAMA,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,MAAM,EAAE;IAC/C,MAAM,UAAU,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IACpC,sCAAsC;IACtC,6CAA6C;IAC7C,sBAAc,GAAG,GAAG,EAAE;QAClB,MAAM,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACvC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;QACtE,OAAO,CAAC,CAAC;IACb,CAAC,CAAC;CACL;KAAM;IACH,sBAAc,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;CACrC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFunctionParameterNames = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @module node-opcua-utils
|
|
6
|
+
*/
|
|
7
|
+
const STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm;
|
|
8
|
+
const ARGUMENT_NAMES = /([^\s,]+)/g;
|
|
9
|
+
function getFunctionParameterNames(func) {
|
|
10
|
+
const fnStr = func.toString().replace(STRIP_COMMENTS, "");
|
|
11
|
+
const result = fnStr.slice(fnStr.indexOf("(") + 1, fnStr.indexOf(")")).match(ARGUMENT_NAMES);
|
|
12
|
+
if (!result) {
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
exports.getFunctionParameterNames = getFunctionParameterNames;
|
|
18
|
+
//# sourceMappingURL=get_function_parameters_name.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get_function_parameters_name.js","sourceRoot":"","sources":["../source/get_function_parameters_name.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,MAAM,cAAc,GAAG,kCAAkC,CAAC;AAC1D,MAAM,cAAc,GAAG,YAAY,CAAC;AAGpC,SAAgB,yBAAyB,CAAC,IAAsB;IAC5D,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;IAC1D,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAC7F,IAAI,CAAC,MAAM,EAAE;QACT,OAAO,EAAE,CAAC;KACb;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAPD,8DAOC"}
|
package/dist/hrtime.d.ts
ADDED
package/dist/hrtime.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hrtime = void 0;
|
|
4
|
+
// polyfil for window.performance.now
|
|
5
|
+
const performance = (typeof global === "object" && global.performance) || {};
|
|
6
|
+
const performanceNow = performance.now ||
|
|
7
|
+
performance.mozNow ||
|
|
8
|
+
performance.msNow ||
|
|
9
|
+
performance.oNow ||
|
|
10
|
+
performance.webkitNow ||
|
|
11
|
+
function () {
|
|
12
|
+
return new Date().getTime();
|
|
13
|
+
};
|
|
14
|
+
// generate timestamp or delta
|
|
15
|
+
// see http://nodejs.org/api/process.html#process_process_hrtime
|
|
16
|
+
function hrtime_for_browser(previousTimestamp) {
|
|
17
|
+
previousTimestamp = previousTimestamp || [0, 0];
|
|
18
|
+
const clocktime = performanceNow.call(performance) * 1e-3;
|
|
19
|
+
let seconds = Math.floor(clocktime);
|
|
20
|
+
let nanoseconds = Math.floor((clocktime % 1) * 1e9);
|
|
21
|
+
if (previousTimestamp) {
|
|
22
|
+
seconds = seconds - previousTimestamp[0];
|
|
23
|
+
nanoseconds = nanoseconds - previousTimestamp[1];
|
|
24
|
+
if (nanoseconds < 0) {
|
|
25
|
+
seconds--;
|
|
26
|
+
nanoseconds += 1e9;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return [seconds, nanoseconds];
|
|
30
|
+
}
|
|
31
|
+
exports.hrtime = typeof process === "object" ? (process.hrtime || hrtime_for_browser) : hrtime_for_browser;
|
|
32
|
+
//# sourceMappingURL=hrtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hrtime.js","sourceRoot":"","sources":["../source/hrtime.ts"],"names":[],"mappings":";;;AAAA,qCAAqC;AACrC,MAAM,WAAW,GAAQ,CAAC,OAAO,MAAM,KAAK,QAAQ,IAAK,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;AACnF,MAAM,cAAc,GAChB,WAAW,CAAC,GAAG;IACf,WAAW,CAAC,MAAM;IAClB,WAAW,CAAC,KAAK;IACjB,WAAW,CAAC,IAAI;IAChB,WAAW,CAAC,SAAS;IACrB;QACI,OAAO,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;IAChC,CAAC,CAAC;AAEN,8BAA8B;AAC9B,gEAAgE;AAChE,SAAS,kBAAkB,CAAC,iBAAoC;IAE5D,iBAAiB,GAAG,iBAAiB,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAEhD,MAAM,SAAS,GAAG,cAAc,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC;IAC1D,IAAI,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IACpC,IAAI,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;IACpD,IAAI,iBAAiB,EAAE;QACnB,OAAO,GAAG,OAAO,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC;QACzC,WAAW,GAAG,WAAW,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC;QACjD,IAAI,WAAW,GAAG,CAAC,EAAE;YACjB,OAAO,EAAE,CAAC;YACV,WAAW,IAAI,GAAG,CAAC;SACtB;KACJ;IACD,OAAO,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;AAClC,CAAC;AAEY,QAAA,MAAM,GAAe,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAoB,IAAI,kBAAkB,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* set a flag
|
|
3
|
+
* @method set_flag
|
|
4
|
+
*/
|
|
5
|
+
export declare function set_flag(value: number, mask: number | {
|
|
6
|
+
value: number;
|
|
7
|
+
}): number;
|
|
8
|
+
/**
|
|
9
|
+
* check if a set of bits are set in the values
|
|
10
|
+
* @method check_flag
|
|
11
|
+
*/
|
|
12
|
+
export declare function check_flag(value: number, mask: number | {
|
|
13
|
+
value: number;
|
|
14
|
+
}): boolean;
|
|
15
|
+
export declare function isNullOrUndefined(value: unknown | undefined): boolean;
|
|
16
|
+
export { buffer_ellipsis } from "./buffer_ellipsis";
|
|
17
|
+
export { capitalizeFirstLetter, lowerFirstLetter } from "./string_utils";
|
|
18
|
+
export { getObjectClassName } from "./object_classname";
|
|
19
|
+
export { get_clock_tick } from "./get_clock_tick";
|
|
20
|
+
export { compare_buffers } from "./compare_buffers";
|
|
21
|
+
export { getFunctionParameterNames } from "./get_function_parameters_name";
|
|
22
|
+
export * from "./watchdog";
|
|
23
|
+
export { setDeprecated } from "./set_deprecated";
|
|
24
|
+
export { replaceBufferWithHexDump } from "./replace_buffer_with_hex_dump";
|
|
25
|
+
export * from "./timestamp";
|
|
26
|
+
export * from "./line_file";
|
|
27
|
+
export * from "./match_uri";
|
|
28
|
+
export { hrtime } from "./hrtime";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.hrtime = exports.replaceBufferWithHexDump = exports.setDeprecated = exports.getFunctionParameterNames = exports.compare_buffers = exports.get_clock_tick = exports.getObjectClassName = exports.lowerFirstLetter = exports.capitalizeFirstLetter = exports.buffer_ellipsis = exports.isNullOrUndefined = exports.check_flag = exports.set_flag = void 0;
|
|
18
|
+
/**
|
|
19
|
+
* @module node-opcua-utils
|
|
20
|
+
*/
|
|
21
|
+
// tslint:disable:no-bitwise
|
|
22
|
+
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
23
|
+
/**
|
|
24
|
+
* set a flag
|
|
25
|
+
* @method set_flag
|
|
26
|
+
*/
|
|
27
|
+
function set_flag(value, mask) {
|
|
28
|
+
if (mask.value) {
|
|
29
|
+
mask = mask.value;
|
|
30
|
+
}
|
|
31
|
+
(0, node_opcua_assert_1.assert)(!Object.prototype.hasOwnProperty.call(mask, "value"));
|
|
32
|
+
(0, node_opcua_assert_1.assert)(mask !== undefined);
|
|
33
|
+
return value | mask;
|
|
34
|
+
}
|
|
35
|
+
exports.set_flag = set_flag;
|
|
36
|
+
/**
|
|
37
|
+
* check if a set of bits are set in the values
|
|
38
|
+
* @method check_flag
|
|
39
|
+
*/
|
|
40
|
+
function check_flag(value, mask) {
|
|
41
|
+
if (mask.value) {
|
|
42
|
+
mask = mask.value;
|
|
43
|
+
}
|
|
44
|
+
(0, node_opcua_assert_1.assert)(!Object.prototype.hasOwnProperty.call(mask, "value"));
|
|
45
|
+
return (value & mask) === mask;
|
|
46
|
+
}
|
|
47
|
+
exports.check_flag = check_flag;
|
|
48
|
+
function isNullOrUndefined(value) {
|
|
49
|
+
return value === undefined || value === null;
|
|
50
|
+
}
|
|
51
|
+
exports.isNullOrUndefined = isNullOrUndefined;
|
|
52
|
+
var buffer_ellipsis_1 = require("./buffer_ellipsis");
|
|
53
|
+
Object.defineProperty(exports, "buffer_ellipsis", { enumerable: true, get: function () { return buffer_ellipsis_1.buffer_ellipsis; } });
|
|
54
|
+
var string_utils_1 = require("./string_utils");
|
|
55
|
+
Object.defineProperty(exports, "capitalizeFirstLetter", { enumerable: true, get: function () { return string_utils_1.capitalizeFirstLetter; } });
|
|
56
|
+
Object.defineProperty(exports, "lowerFirstLetter", { enumerable: true, get: function () { return string_utils_1.lowerFirstLetter; } });
|
|
57
|
+
var object_classname_1 = require("./object_classname");
|
|
58
|
+
Object.defineProperty(exports, "getObjectClassName", { enumerable: true, get: function () { return object_classname_1.getObjectClassName; } });
|
|
59
|
+
var get_clock_tick_1 = require("./get_clock_tick");
|
|
60
|
+
Object.defineProperty(exports, "get_clock_tick", { enumerable: true, get: function () { return get_clock_tick_1.get_clock_tick; } });
|
|
61
|
+
var compare_buffers_1 = require("./compare_buffers");
|
|
62
|
+
Object.defineProperty(exports, "compare_buffers", { enumerable: true, get: function () { return compare_buffers_1.compare_buffers; } });
|
|
63
|
+
var get_function_parameters_name_1 = require("./get_function_parameters_name");
|
|
64
|
+
Object.defineProperty(exports, "getFunctionParameterNames", { enumerable: true, get: function () { return get_function_parameters_name_1.getFunctionParameterNames; } });
|
|
65
|
+
__exportStar(require("./watchdog"), exports);
|
|
66
|
+
var set_deprecated_1 = require("./set_deprecated");
|
|
67
|
+
Object.defineProperty(exports, "setDeprecated", { enumerable: true, get: function () { return set_deprecated_1.setDeprecated; } });
|
|
68
|
+
var replace_buffer_with_hex_dump_1 = require("./replace_buffer_with_hex_dump");
|
|
69
|
+
Object.defineProperty(exports, "replaceBufferWithHexDump", { enumerable: true, get: function () { return replace_buffer_with_hex_dump_1.replaceBufferWithHexDump; } });
|
|
70
|
+
__exportStar(require("./timestamp"), exports);
|
|
71
|
+
__exportStar(require("./line_file"), exports);
|
|
72
|
+
__exportStar(require("./match_uri"), exports);
|
|
73
|
+
var hrtime_1 = require("./hrtime");
|
|
74
|
+
Object.defineProperty(exports, "hrtime", { enumerable: true, get: function () { return hrtime_1.hrtime; } });
|
|
75
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
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yB,OAAA;AAClC,6CAA2B;AAC3B,mDAAiD;AAAxC,+GAAA,aAAa,OAAA;AACtB,+EAA0E;AAAjE,wIAAA,wBAAwB,OAAA;AACjC,8CAA4B;AAC5B,8CAA4B;AAC5B,8CAA4B;AAC5B,mCAAgC;AAAxB,gGAAA,MAAM,OAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module node-opcua-utils
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.LineFile = void 0;
|
|
7
|
+
class LineFile {
|
|
8
|
+
constructor() {
|
|
9
|
+
this._line = [];
|
|
10
|
+
}
|
|
11
|
+
write(...args) {
|
|
12
|
+
let str = "";
|
|
13
|
+
// tslint:disable:prefer-for-of
|
|
14
|
+
for (let i = 0; i < args.length; i++) {
|
|
15
|
+
str += args[i];
|
|
16
|
+
}
|
|
17
|
+
this._line.push(str);
|
|
18
|
+
}
|
|
19
|
+
toString(endOfLine = "\n") {
|
|
20
|
+
return this._line.join(endOfLine);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.LineFile = LineFile;
|
|
24
|
+
//# sourceMappingURL=line_file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"line_file.js","sourceRoot":"","sources":["../source/line_file.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,MAAa,QAAQ;IAGjB;QACI,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;IACpB,CAAC;IAEM,KAAK,CAAC,GAAG,IAAc;QAC1B,IAAI,GAAG,GAAG,EAAE,CAAC;QACb,+BAA+B;QAC/B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAClC,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC;SAClB;QACD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IAEM,QAAQ,CAAC,YAAyB,IAAI;QACzC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACtC,CAAC;CACJ;AAnBD,4BAmBC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module node-opcua-utils
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* returns true if two endpoint matches the same address:
|
|
6
|
+
*
|
|
7
|
+
* @see https://www.dnscheck.co/faq
|
|
8
|
+
* @see https://tools.ietf.org/html/rfc4343 : Domain Name System (DNS) Case Insensitivity Clarification
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
export declare function matchUri(endpointUri1: string | null, endpointUri2: string | null): boolean;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.matchUri = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @module node-opcua-utils
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* returns true if two endpoint matches the same address:
|
|
9
|
+
*
|
|
10
|
+
* @see https://www.dnscheck.co/faq
|
|
11
|
+
* @see https://tools.ietf.org/html/rfc4343 : Domain Name System (DNS) Case Insensitivity Clarification
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
function matchUri(endpointUri1, endpointUri2) {
|
|
15
|
+
if (endpointUri1 === null) {
|
|
16
|
+
return endpointUri2 === null;
|
|
17
|
+
}
|
|
18
|
+
if (endpointUri2 === null) {
|
|
19
|
+
return endpointUri1 === null;
|
|
20
|
+
}
|
|
21
|
+
return endpointUri1.toLowerCase() === endpointUri2.toLowerCase();
|
|
22
|
+
}
|
|
23
|
+
exports.matchUri = matchUri;
|
|
24
|
+
//# sourceMappingURL=match_uri.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match_uri.js","sourceRoot":"","sources":["../source/match_uri.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH;;;;;;GAMG;AACH,SAAgB,QAAQ,CAAC,YAA2B,EAAE,YAA2B;IAC7E,IAAI,YAAY,KAAK,IAAI,EAAE;QACvB,OAAO,YAAY,KAAK,IAAI,CAAC;KAChC;IACD,IAAI,YAAY,KAAK,IAAI,EAAE;QACvB,OAAO,YAAY,KAAK,IAAI,CAAC;KAChC;IACD,OAAO,YAAY,CAAC,WAAW,EAAE,KAAK,YAAY,CAAC,WAAW,EAAE,CAAC;AACrE,CAAC;AARD,4BAQC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getObjectClassName = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @module node-opcua-utils
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* @method getObjectClassName
|
|
9
|
+
* @param obj
|
|
10
|
+
* @return {string}
|
|
11
|
+
*/
|
|
12
|
+
function getObjectClassName(obj) {
|
|
13
|
+
return Object.prototype.toString.call(obj).slice(8, -1);
|
|
14
|
+
}
|
|
15
|
+
exports.getObjectClassName = getObjectClassName;
|
|
16
|
+
//# sourceMappingURL=object_classname.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object_classname.js","sourceRoot":"","sources":["../source/object_classname.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH;;;;GAIG;AACH,SAAgB,kBAAkB,CAAC,GAAY;IAC3C,OAAO,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAC5D,CAAC;AAFD,gDAEC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.replaceBufferWithHexDump = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @module node-opcua-utils
|
|
6
|
+
*/
|
|
7
|
+
function replaceBufferWithHexDump(obj) {
|
|
8
|
+
for (const p in obj) {
|
|
9
|
+
if (Object.prototype.hasOwnProperty.call(obj, p)) {
|
|
10
|
+
if (obj[p] instanceof Buffer) {
|
|
11
|
+
obj[p] = "<BUFFER>" + obj[p].toString("hex") + "</BUFFER>";
|
|
12
|
+
}
|
|
13
|
+
else if (typeof obj[p] === "object") {
|
|
14
|
+
replaceBufferWithHexDump(obj[p]);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return obj;
|
|
19
|
+
}
|
|
20
|
+
exports.replaceBufferWithHexDump = replaceBufferWithHexDump;
|
|
21
|
+
//# sourceMappingURL=replace_buffer_with_hex_dump.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replace_buffer_with_hex_dump.js","sourceRoot":"","sources":["../source/replace_buffer_with_hex_dump.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,SAAgB,wBAAwB,CAAC,GAAuD;IAC5F,KAAK,MAAM,CAAC,IAAI,GAAG,EAAE;QACjB,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE;YAC9C,IAAI,GAAG,CAAC,CAAC,CAAC,YAAY,MAAM,EAAE;gBAC1B,GAAG,CAAC,CAAC,CAAC,GAAG,UAAU,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,WAAW,CAAC;aAC9D;iBAAM,IAAI,OAAO,GAAG,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE;gBACnC,wBAAwB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;aACpC;SACJ;KACJ;IACD,OAAO,GAAG,CAAC;AACf,CAAC;AAXD,4DAWC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
exports.setDeprecated = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* @module node-opcua-utils
|
|
9
|
+
*/
|
|
10
|
+
// tslint:disable:ban-types
|
|
11
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
12
|
+
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
13
|
+
/* istanbul ignore next */
|
|
14
|
+
function setDeprecated(constructor, methodName, helpString) {
|
|
15
|
+
const oldMethod = constructor.prototype[methodName];
|
|
16
|
+
(0, node_opcua_assert_1.assert)(oldMethod instanceof Function, "expecting a valid " + methodName + "method on class " + constructor.constructor.name);
|
|
17
|
+
let counter = 0;
|
|
18
|
+
constructor.prototype[methodName] = function (...args) {
|
|
19
|
+
if (counter % 1000 === 0) {
|
|
20
|
+
// tslint:disable:no-console
|
|
21
|
+
console.log(chalk_1.default.green("Warning !"), chalk_1.default.green(chalk_1.default.bold(constructor.name + "#" + methodName), " is now deprecated"));
|
|
22
|
+
console.log(" ", helpString);
|
|
23
|
+
}
|
|
24
|
+
counter++;
|
|
25
|
+
return oldMethod.call(this, ...args);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
exports.setDeprecated = setDeprecated;
|
|
29
|
+
//# sourceMappingURL=set_deprecated.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set_deprecated.js","sourceRoot":"","sources":["../source/set_deprecated.ts"],"names":[],"mappings":";;;;;;AAAA;;GAEG;AACH,2BAA2B;AAC3B,kDAA0B;AAC1B,yDAA2C;AAI3C,0BAA0B;AAC1B,SAAgB,aAAa,CAAC,WAA6B,EAAE,UAAkB,EAAE,UAAkB;IAC/F,MAAM,SAAS,GAAG,WAAW,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;IAEpD,IAAA,0BAAM,EAAC,SAAS,YAAY,QAAQ,EAAE,oBAAoB,GAAG,UAAU,GAAG,kBAAkB,GAAG,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAE7H,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,WAAW,CAAC,SAAS,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,IAAW;QACxD,IAAI,OAAO,GAAG,IAAI,KAAK,CAAC,EAAE;YACtB,4BAA4B;YAC5B,OAAO,CAAC,GAAG,CACP,eAAK,CAAC,KAAK,CAAC,WAAW,CAAC,EACxB,eAAK,CAAC,KAAK,CAAC,eAAK,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,GAAG,GAAG,GAAG,UAAU,CAAC,EAAE,oBAAoB,CAAC,CACrF,CAAC;YACF,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;SACxC;QACD,OAAO,EAAE,CAAC;QACV,OAAO,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;IACzC,CAAC,CAAC;AACN,CAAC;AAlBD,sCAkBC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module node-opcua-utils
|
|
3
|
+
*/
|
|
4
|
+
export declare function capitalizeFirstLetter(str: string): string;
|
|
5
|
+
export declare function isUpperCaseChar(c: string): boolean;
|
|
6
|
+
export declare function isAlpha(c: string): boolean;
|
|
7
|
+
export declare function countUpperCaseSlow(str: string): number;
|
|
8
|
+
export declare function countAlphaSlow(str: string): number;
|
|
9
|
+
export declare function countUpperCase(str: string): number;
|
|
10
|
+
export declare function countAlpha(str: string): number;
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* lowerFirstLetter convert a OPCUA Identifier to a javascript Identifier
|
|
14
|
+
*
|
|
15
|
+
* @summary
|
|
16
|
+
*
|
|
17
|
+
* OPCUA and Javascript use two different rules to build identifiers.
|
|
18
|
+
*
|
|
19
|
+
* OPCUA Identifier usually starts with a upper case letter and word are join together, this is known as
|
|
20
|
+
* the Pascal case, or CapitalizedWords convention. (for instance HelloWorld)
|
|
21
|
+
* But sometime, OPCUA identifiers do not follow this convention strictly and we can find various
|
|
22
|
+
* other convention being applied such as underscore between word, or addition of ACRONYMIC prefixes.
|
|
23
|
+
* On it's own, this causes great confusion and inconsistency in programming style.
|
|
24
|
+
*
|
|
25
|
+
* Javascript uses a slightly different convention called camelCase where word are joined together
|
|
26
|
+
* and inner words starts with a capital letter whereas first word starts with a lower case letter.
|
|
27
|
+
* (for instance helloWorld)
|
|
28
|
+
*
|
|
29
|
+
* In node-opcua we have taken the opinionated decision to consistently use camelCase convention for
|
|
30
|
+
* object properties so that all the code look nice and consistent.
|
|
31
|
+
* the lowerFirstLetter method can be used to easily convert from the OPCUA naming convention
|
|
32
|
+
* to javascript naming convention by applying the following rules.
|
|
33
|
+
*
|
|
34
|
+
* * each ascii sequence in a identifier will be converted to lower camel case.
|
|
35
|
+
* * when an identifier only contains upper case letter then it will be untouched. ( i.e CQDF => CQFD)
|
|
36
|
+
* (this rules helps to preserve acronyms)
|
|
37
|
+
* * when a identifier starts with more than one UpperCase letter but still contain lowercase letter
|
|
38
|
+
* then the first Uppercase letter excluding the last one will be converted to lower case
|
|
39
|
+
* ( ie: EURange = > euRange)
|
|
40
|
+
* * when a identifier contains several sequences delimited with underscores (_) the above rules
|
|
41
|
+
* will be applied to each of the element of the sequence
|
|
42
|
+
* ( ie: ALM_FlowOutOfTolerance => ALM_flowOutOfTolerance ( ALM=>ALM , FlowOutOfTolerance=>flowOutOfTolerance)
|
|
43
|
+
*
|
|
44
|
+
* @reference
|
|
45
|
+
* * https://en.wikipedia.org/wiki/Camel_case
|
|
46
|
+
* * https://en.wikipedia.org/wiki/Hungarian_notation
|
|
47
|
+
* * http://wiki.c2.com/?UnderscoreVersusCapitalAndLowerCaseVariableNaming
|
|
48
|
+
*
|
|
49
|
+
*
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* HelloWorld => helloWorld
|
|
53
|
+
* XAxis => xAxis
|
|
54
|
+
* EURange => euRange
|
|
55
|
+
* DATE => DATE
|
|
56
|
+
* XYZ => XYZ
|
|
57
|
+
* AB => AB
|
|
58
|
+
* Ab => ab
|
|
59
|
+
* A => a
|
|
60
|
+
* T1ABC8 => T1ABC8
|
|
61
|
+
* F_ABC_D => F_ABC_D
|
|
62
|
+
* ALM_Timeout => ALM_timeout
|
|
63
|
+
* SV_GasOn => SV_gasOn
|
|
64
|
+
* DI_VAL_FlowImp => DI_VAL_flowImp
|
|
65
|
+
*/
|
|
66
|
+
export declare function lowerFirstLetter(str: string): string;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lowerFirstLetter = exports.countAlpha = exports.countUpperCase = exports.countAlphaSlow = exports.countUpperCaseSlow = exports.isAlpha = exports.isUpperCaseChar = exports.capitalizeFirstLetter = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @module node-opcua-utils
|
|
6
|
+
*/
|
|
7
|
+
// tslint:disable:variable-name
|
|
8
|
+
function capitalizeFirstLetter(str) {
|
|
9
|
+
if (str == null) {
|
|
10
|
+
return str;
|
|
11
|
+
}
|
|
12
|
+
return str.substring(0, 1).toUpperCase() + str.substring(1);
|
|
13
|
+
}
|
|
14
|
+
exports.capitalizeFirstLetter = capitalizeFirstLetter;
|
|
15
|
+
const ACode = "A".charCodeAt(0);
|
|
16
|
+
const ZCode = "Z".charCodeAt(0);
|
|
17
|
+
function isUpperCaseChar(c) {
|
|
18
|
+
const code = c.charCodeAt(0);
|
|
19
|
+
return code >= ACode && code <= ZCode;
|
|
20
|
+
}
|
|
21
|
+
exports.isUpperCaseChar = isUpperCaseChar;
|
|
22
|
+
const aCode = "a".charCodeAt(0);
|
|
23
|
+
const zCode = "z".charCodeAt(0);
|
|
24
|
+
function isAlpha(c) {
|
|
25
|
+
const code = c.charCodeAt(0);
|
|
26
|
+
return (code >= ACode && code <= ZCode) || (code >= aCode && code <= zCode);
|
|
27
|
+
}
|
|
28
|
+
exports.isAlpha = isAlpha;
|
|
29
|
+
function countUpperCaseSlow(str) {
|
|
30
|
+
return str.split("").reduce((p, c) => p + (isUpperCaseChar(c) ? 1 : 0), 0);
|
|
31
|
+
}
|
|
32
|
+
exports.countUpperCaseSlow = countUpperCaseSlow;
|
|
33
|
+
function countAlphaSlow(str) {
|
|
34
|
+
return str.split("").reduce((p, c) => p + (isAlpha(c) ? 1 : 0), 0);
|
|
35
|
+
}
|
|
36
|
+
exports.countAlphaSlow = countAlphaSlow;
|
|
37
|
+
function countUpperCase(str) {
|
|
38
|
+
let count = 0;
|
|
39
|
+
const n = str.length;
|
|
40
|
+
for (let i = 0; i < n; i++) {
|
|
41
|
+
count += isUpperCaseChar(str[i]) ? 1 : 0;
|
|
42
|
+
}
|
|
43
|
+
return count;
|
|
44
|
+
}
|
|
45
|
+
exports.countUpperCase = countUpperCase;
|
|
46
|
+
function countAlpha(str) {
|
|
47
|
+
let count = 0;
|
|
48
|
+
const n = str.length;
|
|
49
|
+
for (let i = 0; i < n; i++) {
|
|
50
|
+
count += isAlpha(str[i]) ? 1 : 0;
|
|
51
|
+
}
|
|
52
|
+
return count;
|
|
53
|
+
}
|
|
54
|
+
exports.countAlpha = countAlpha;
|
|
55
|
+
/**
|
|
56
|
+
*
|
|
57
|
+
* lowerFirstLetter convert a OPCUA Identifier to a javascript Identifier
|
|
58
|
+
*
|
|
59
|
+
* @summary
|
|
60
|
+
*
|
|
61
|
+
* OPCUA and Javascript use two different rules to build identifiers.
|
|
62
|
+
*
|
|
63
|
+
* OPCUA Identifier usually starts with a upper case letter and word are join together, this is known as
|
|
64
|
+
* the Pascal case, or CapitalizedWords convention. (for instance HelloWorld)
|
|
65
|
+
* But sometime, OPCUA identifiers do not follow this convention strictly and we can find various
|
|
66
|
+
* other convention being applied such as underscore between word, or addition of ACRONYMIC prefixes.
|
|
67
|
+
* On it's own, this causes great confusion and inconsistency in programming style.
|
|
68
|
+
*
|
|
69
|
+
* Javascript uses a slightly different convention called camelCase where word are joined together
|
|
70
|
+
* and inner words starts with a capital letter whereas first word starts with a lower case letter.
|
|
71
|
+
* (for instance helloWorld)
|
|
72
|
+
*
|
|
73
|
+
* In node-opcua we have taken the opinionated decision to consistently use camelCase convention for
|
|
74
|
+
* object properties so that all the code look nice and consistent.
|
|
75
|
+
* the lowerFirstLetter method can be used to easily convert from the OPCUA naming convention
|
|
76
|
+
* to javascript naming convention by applying the following rules.
|
|
77
|
+
*
|
|
78
|
+
* * each ascii sequence in a identifier will be converted to lower camel case.
|
|
79
|
+
* * when an identifier only contains upper case letter then it will be untouched. ( i.e CQDF => CQFD)
|
|
80
|
+
* (this rules helps to preserve acronyms)
|
|
81
|
+
* * when a identifier starts with more than one UpperCase letter but still contain lowercase letter
|
|
82
|
+
* then the first Uppercase letter excluding the last one will be converted to lower case
|
|
83
|
+
* ( ie: EURange = > euRange)
|
|
84
|
+
* * when a identifier contains several sequences delimited with underscores (_) the above rules
|
|
85
|
+
* will be applied to each of the element of the sequence
|
|
86
|
+
* ( ie: ALM_FlowOutOfTolerance => ALM_flowOutOfTolerance ( ALM=>ALM , FlowOutOfTolerance=>flowOutOfTolerance)
|
|
87
|
+
*
|
|
88
|
+
* @reference
|
|
89
|
+
* * https://en.wikipedia.org/wiki/Camel_case
|
|
90
|
+
* * https://en.wikipedia.org/wiki/Hungarian_notation
|
|
91
|
+
* * http://wiki.c2.com/?UnderscoreVersusCapitalAndLowerCaseVariableNaming
|
|
92
|
+
*
|
|
93
|
+
*
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* HelloWorld => helloWorld
|
|
97
|
+
* XAxis => xAxis
|
|
98
|
+
* EURange => euRange
|
|
99
|
+
* DATE => DATE
|
|
100
|
+
* XYZ => XYZ
|
|
101
|
+
* AB => AB
|
|
102
|
+
* Ab => ab
|
|
103
|
+
* A => a
|
|
104
|
+
* T1ABC8 => T1ABC8
|
|
105
|
+
* F_ABC_D => F_ABC_D
|
|
106
|
+
* ALM_Timeout => ALM_timeout
|
|
107
|
+
* SV_GasOn => SV_gasOn
|
|
108
|
+
* DI_VAL_FlowImp => DI_VAL_flowImp
|
|
109
|
+
*/
|
|
110
|
+
function lowerFirstLetter(str) {
|
|
111
|
+
if (str == null) {
|
|
112
|
+
return str;
|
|
113
|
+
}
|
|
114
|
+
// at least, 2 all upper
|
|
115
|
+
if (str.length >= 2 && countUpperCase(str) === countAlpha(str)) {
|
|
116
|
+
return str;
|
|
117
|
+
}
|
|
118
|
+
if (str.match(/_/)) {
|
|
119
|
+
return str.split("_").map(lowerFirstLetter).join("_");
|
|
120
|
+
}
|
|
121
|
+
let result = str.substring(0, 1).toLowerCase() + str.substring(1);
|
|
122
|
+
if (result.length > 3 && isUpperCaseChar(str[1]) && isUpperCaseChar(str[2])) {
|
|
123
|
+
result = str.substring(0, 2).toLowerCase() + str.substring(2);
|
|
124
|
+
}
|
|
125
|
+
return result;
|
|
126
|
+
}
|
|
127
|
+
exports.lowerFirstLetter = lowerFirstLetter;
|
|
128
|
+
//# sourceMappingURL=string_utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string_utils.js","sourceRoot":"","sources":["../source/string_utils.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,+BAA+B;AAC/B,SAAgB,qBAAqB,CAAC,GAAW;IAC7C,IAAI,GAAG,IAAI,IAAI,EAAE;QACb,OAAO,GAAG,CAAC;KACd;IACD,OAAO,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AAChE,CAAC;AALD,sDAKC;AAED,MAAM,KAAK,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AAChC,MAAM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AAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAClE,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE;QACzE,MAAM,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;KACjE;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAjBD,4CAiBC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function timestamp(): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.timestamp = void 0;
|
|
4
|
+
function w(s, length) {
|
|
5
|
+
return ("" + s).padStart(length, "0");
|
|
6
|
+
}
|
|
7
|
+
function t(d) {
|
|
8
|
+
return w(d.getUTCHours(), 2) + ":" + w(d.getUTCMinutes(), 2) + ":" + w(d.getUTCSeconds(), 2) + ":" + w(d.getMilliseconds(), 3);
|
|
9
|
+
}
|
|
10
|
+
function timestamp() {
|
|
11
|
+
return t(new Date());
|
|
12
|
+
}
|
|
13
|
+
exports.timestamp = timestamp;
|
|
14
|
+
//# sourceMappingURL=timestamp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timestamp.js","sourceRoot":"","sources":["../source/timestamp.ts"],"names":[],"mappings":";;;AAAA,SAAS,CAAC,CAAC,CAAkB,EAAE,MAAc;IACzC,OAAO,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAC1C,CAAC;AAED,SAAS,CAAC,CAAC,CAAO;IACd,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC,CAAC;AACnI,CAAC;AAED,SAAgB,SAAS;IACrB,OAAO,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;AACzB,CAAC;AAFD,8BAEC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* @module node-opcua-utils
|
|
4
|
+
*/
|
|
5
|
+
import { EventEmitter } from "events";
|
|
6
|
+
type ArbitraryClockTick = number;
|
|
7
|
+
type DurationInMillisecond = number;
|
|
8
|
+
export interface IWatchdogData2 {
|
|
9
|
+
key: number;
|
|
10
|
+
subscriber: ISubscriber;
|
|
11
|
+
timeout: DurationInMillisecond;
|
|
12
|
+
lastSeen: ArbitraryClockTick;
|
|
13
|
+
visitCount: number;
|
|
14
|
+
}
|
|
15
|
+
export interface ISubscriber {
|
|
16
|
+
_watchDog?: WatchDog;
|
|
17
|
+
_watchDogData?: IWatchdogData2;
|
|
18
|
+
watchdogReset: () => void;
|
|
19
|
+
keepAlive?: () => void;
|
|
20
|
+
onClientSeen?: () => void;
|
|
21
|
+
}
|
|
22
|
+
export declare class WatchDog extends EventEmitter {
|
|
23
|
+
static lastSeenToDuration(lastSeen: number): number;
|
|
24
|
+
static emptyKeepAlive: () => void;
|
|
25
|
+
/**
|
|
26
|
+
* returns the number of subscribers using the WatchDog object.
|
|
27
|
+
*/
|
|
28
|
+
get subscriberCount(): number;
|
|
29
|
+
private readonly _watchdogDataMap;
|
|
30
|
+
private _counter;
|
|
31
|
+
private _currentTime;
|
|
32
|
+
private _timer;
|
|
33
|
+
private readonly _visitSubscriberB;
|
|
34
|
+
constructor();
|
|
35
|
+
/**
|
|
36
|
+
* add a subscriber to the WatchDog.
|
|
37
|
+
* @method addSubscriber
|
|
38
|
+
*
|
|
39
|
+
* add a subscriber to the WatchDog.
|
|
40
|
+
*
|
|
41
|
+
* This method modifies the subscriber be adding a
|
|
42
|
+
* new method to it called 'keepAlive'
|
|
43
|
+
* The subscriber must also provide a "watchdogReset". watchdogReset will be called
|
|
44
|
+
* if the subscriber failed to call keepAlive withing the timeout period.
|
|
45
|
+
* @param subscriber
|
|
46
|
+
* @param timeout
|
|
47
|
+
* @return the numerical key associated with this subscriber
|
|
48
|
+
*/
|
|
49
|
+
addSubscriber(subscriber: ISubscriber, timeout: number): number;
|
|
50
|
+
removeSubscriber(subscriber: ISubscriber): void;
|
|
51
|
+
shutdown(): void;
|
|
52
|
+
getCurrentSystemTick(): ArbitraryClockTick;
|
|
53
|
+
private _visit_subscriber;
|
|
54
|
+
private _start_timer;
|
|
55
|
+
private _stop_timer;
|
|
56
|
+
}
|
|
57
|
+
export {};
|
package/dist/watchdog.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WatchDog = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @module node-opcua-utils
|
|
6
|
+
*/
|
|
7
|
+
const events_1 = require("events");
|
|
8
|
+
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
9
|
+
const get_clock_tick_1 = require("./get_clock_tick");
|
|
10
|
+
function hasExpired(watchDogData, currentTime) {
|
|
11
|
+
const elapsedTime = currentTime - watchDogData.lastSeen;
|
|
12
|
+
return elapsedTime > watchDogData.timeout;
|
|
13
|
+
}
|
|
14
|
+
function keepAliveFunc() {
|
|
15
|
+
(0, node_opcua_assert_1.assert)(this._watchDog instanceof WatchDog);
|
|
16
|
+
// istanbul ignore next
|
|
17
|
+
if (!this._watchDogData || !this._watchDog) {
|
|
18
|
+
throw new Error("Internal error");
|
|
19
|
+
}
|
|
20
|
+
(0, node_opcua_assert_1.assert)(typeof this._watchDogData.key === "number");
|
|
21
|
+
this._watchDogData.lastSeen = this._watchDog.getCurrentSystemTick();
|
|
22
|
+
if (this.onClientSeen) {
|
|
23
|
+
this.onClientSeen();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
class WatchDog extends events_1.EventEmitter {
|
|
27
|
+
static lastSeenToDuration(lastSeen) {
|
|
28
|
+
return (0, get_clock_tick_1.get_clock_tick)() - lastSeen;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* returns the number of subscribers using the WatchDog object.
|
|
32
|
+
*/
|
|
33
|
+
get subscriberCount() {
|
|
34
|
+
return Object.keys(this._watchdogDataMap).length;
|
|
35
|
+
}
|
|
36
|
+
constructor() {
|
|
37
|
+
super();
|
|
38
|
+
this._watchdogDataMap = {};
|
|
39
|
+
this._counter = 0;
|
|
40
|
+
this._currentTime = this.getCurrentSystemTick();
|
|
41
|
+
this._visitSubscriberB = this._visit_subscriber.bind(this);
|
|
42
|
+
this._timer = null; // as NodeJS.Timer;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* add a subscriber to the WatchDog.
|
|
46
|
+
* @method addSubscriber
|
|
47
|
+
*
|
|
48
|
+
* add a subscriber to the WatchDog.
|
|
49
|
+
*
|
|
50
|
+
* This method modifies the subscriber be adding a
|
|
51
|
+
* new method to it called 'keepAlive'
|
|
52
|
+
* The subscriber must also provide a "watchdogReset". watchdogReset will be called
|
|
53
|
+
* if the subscriber failed to call keepAlive withing the timeout period.
|
|
54
|
+
* @param subscriber
|
|
55
|
+
* @param timeout
|
|
56
|
+
* @return the numerical key associated with this subscriber
|
|
57
|
+
*/
|
|
58
|
+
addSubscriber(subscriber, timeout) {
|
|
59
|
+
this._currentTime = this.getCurrentSystemTick();
|
|
60
|
+
timeout = timeout || 1000;
|
|
61
|
+
(0, node_opcua_assert_1.assert)(typeof timeout === "number", " invalid timeout ");
|
|
62
|
+
(0, node_opcua_assert_1.assert)(typeof subscriber.watchdogReset === "function", " the subscriber must provide a watchdogReset method ");
|
|
63
|
+
(0, node_opcua_assert_1.assert)(typeof subscriber.keepAlive !== "function" || subscriber.keepAlive === WatchDog.emptyKeepAlive);
|
|
64
|
+
this._counter += 1;
|
|
65
|
+
const key = this._counter;
|
|
66
|
+
subscriber._watchDog = this;
|
|
67
|
+
subscriber._watchDogData = {
|
|
68
|
+
key,
|
|
69
|
+
lastSeen: this._currentTime,
|
|
70
|
+
subscriber,
|
|
71
|
+
timeout,
|
|
72
|
+
visitCount: 0
|
|
73
|
+
};
|
|
74
|
+
this._watchdogDataMap[key] = subscriber._watchDogData;
|
|
75
|
+
if (subscriber.onClientSeen) {
|
|
76
|
+
subscriber.onClientSeen();
|
|
77
|
+
}
|
|
78
|
+
subscriber.keepAlive = keepAliveFunc.bind(subscriber);
|
|
79
|
+
// start timer when the first subscriber comes in
|
|
80
|
+
if (this.subscriberCount === 1) {
|
|
81
|
+
(0, node_opcua_assert_1.assert)(this._timer === null);
|
|
82
|
+
this._start_timer();
|
|
83
|
+
}
|
|
84
|
+
(0, node_opcua_assert_1.assert)(this._timer !== null);
|
|
85
|
+
return key;
|
|
86
|
+
}
|
|
87
|
+
removeSubscriber(subscriber) {
|
|
88
|
+
if (!subscriber._watchDog) {
|
|
89
|
+
return; // already removed !!!
|
|
90
|
+
}
|
|
91
|
+
if (!subscriber._watchDogData) {
|
|
92
|
+
throw new Error("Internal error");
|
|
93
|
+
}
|
|
94
|
+
(0, node_opcua_assert_1.assert)(subscriber._watchDog instanceof WatchDog);
|
|
95
|
+
(0, node_opcua_assert_1.assert)(typeof subscriber._watchDogData.key === "number");
|
|
96
|
+
(0, node_opcua_assert_1.assert)(typeof subscriber.keepAlive === "function");
|
|
97
|
+
(0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(this._watchdogDataMap, subscriber._watchDogData.key));
|
|
98
|
+
delete this._watchdogDataMap[subscriber._watchDogData.key];
|
|
99
|
+
delete subscriber._watchDog;
|
|
100
|
+
// leave it as it might be usefull, delete subscriber._watchDogData;
|
|
101
|
+
subscriber.keepAlive = WatchDog.emptyKeepAlive;
|
|
102
|
+
// delete timer when the last subscriber comes out
|
|
103
|
+
if (this.subscriberCount === 0) {
|
|
104
|
+
this._stop_timer();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
shutdown() {
|
|
108
|
+
(0, node_opcua_assert_1.assert)(this._timer === null && Object.keys(this._watchdogDataMap).length === 0, " leaking subscriber in watchdog");
|
|
109
|
+
}
|
|
110
|
+
getCurrentSystemTick() {
|
|
111
|
+
return (0, get_clock_tick_1.get_clock_tick)();
|
|
112
|
+
}
|
|
113
|
+
_visit_subscriber() {
|
|
114
|
+
this._currentTime = this.getCurrentSystemTick();
|
|
115
|
+
const expiredSubscribers = Object.values(this._watchdogDataMap).filter((watchDogData) => {
|
|
116
|
+
watchDogData.visitCount += 1;
|
|
117
|
+
return hasExpired(watchDogData, this._currentTime);
|
|
118
|
+
});
|
|
119
|
+
if (expiredSubscribers.length) {
|
|
120
|
+
this.emit("timeout", expiredSubscribers);
|
|
121
|
+
}
|
|
122
|
+
expiredSubscribers.forEach((watchDogData) => {
|
|
123
|
+
this.removeSubscriber(watchDogData.subscriber);
|
|
124
|
+
watchDogData.subscriber.watchdogReset();
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
_start_timer() {
|
|
128
|
+
(0, node_opcua_assert_1.assert)(this._timer === null, " setInterval already called ?");
|
|
129
|
+
this._timer = setInterval(this._visitSubscriberB, 1000);
|
|
130
|
+
}
|
|
131
|
+
_stop_timer() {
|
|
132
|
+
(0, node_opcua_assert_1.assert)(this._timer !== null, "_stop_timer already called ?");
|
|
133
|
+
if (this._timer !== null) {
|
|
134
|
+
clearInterval(this._timer);
|
|
135
|
+
this._timer = null;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
exports.WatchDog = WatchDog;
|
|
140
|
+
WatchDog.emptyKeepAlive = () => {
|
|
141
|
+
/* */
|
|
142
|
+
};
|
|
143
|
+
//# sourceMappingURL=watchdog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watchdog.js","sourceRoot":"","sources":["../source/watchdog.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,mCAAsC;AACtC,yDAA2C;AAC3C,qDAAkD;AAuBlD,SAAS,UAAU,CAAC,YAA4B,EAAE,WAA+B;IAC7E,MAAM,WAAW,GAAG,WAAW,GAAG,YAAY,CAAC,QAAQ,CAAC;IACxD,OAAO,WAAW,GAAG,YAAY,CAAC,OAAO,CAAC;AAC9C,CAAC;AAED,SAAS,aAAa;IAClB,IAAA,0BAAM,EAAC,IAAI,CAAC,SAAS,YAAY,QAAQ,CAAC,CAAC;IAC3C,uBAAuB;IACvB,IAAI,CAAC,IAAI,CAAC,aAAa,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;QACxC,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;KACrC;IACD,IAAA,0BAAM,EAAC,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,KAAK,QAAQ,CAAC,CAAC;IACnD,IAAI,CAAC,aAAa,CAAC,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,oBAAoB,EAAE,CAAC;IACpE,IAAI,IAAI,CAAC,YAAY,EAAE;QACnB,IAAI,CAAC,YAAY,EAAE,CAAC;KACvB;AACL,CAAC;AAED,MAAa,QAAS,SAAQ,qBAAY;IACtC,MAAM,CAAC,kBAAkB,CAAC,QAAgB;QACtC,OAAO,IAAA,+BAAc,GAAE,GAAG,QAAQ,CAAC;IACvC,CAAC;IAKD;;OAEG;IACH,IAAI,eAAe;QACf,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,MAAM,CAAC;IACrD,CAAC;IAQD;QACI,KAAK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IAAI,CAAC,MAAM,CAAC,CAAC;YAC3B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;SACtB;IACL,CAAC;;AA7IL,4BA8IC;AAzIU,uBAAc,GAAG,GAAS,EAAE;IAC/B,KAAK;AACT,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-opcua-utils",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "pure nodejs OPCUA SDK - module
|
|
3
|
+
"version": "2.104.0",
|
|
4
|
+
"description": "pure nodejs OPCUA SDK - module utils",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
@@ -13,11 +13,11 @@
|
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"chalk": "4.1.2",
|
|
16
|
-
"node-opcua-assert": "2.
|
|
16
|
+
"node-opcua-assert": "2.104.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"should": "^13.2.3",
|
|
20
|
-
"sinon": "^15.0
|
|
20
|
+
"sinon": "^15.1.0"
|
|
21
21
|
},
|
|
22
22
|
"author": "Etienne Rossignon",
|
|
23
23
|
"license": "MIT",
|
|
@@ -34,5 +34,9 @@
|
|
|
34
34
|
"internet of things"
|
|
35
35
|
],
|
|
36
36
|
"homepage": "http://node-opcua.github.io/",
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "3cd6d355e8b3c66822d08a3ca682659ea5d1a55d",
|
|
38
|
+
"files": [
|
|
39
|
+
"dist",
|
|
40
|
+
"source"
|
|
41
|
+
]
|
|
38
42
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @module node-opcua-utils
|
|
3
3
|
*/
|
|
4
4
|
// tslint:disable:no-console
|
|
5
|
-
import
|
|
5
|
+
import chalk from "chalk";
|
|
6
6
|
import { buffer_ellipsis } from "./buffer_ellipsis";
|
|
7
7
|
|
|
8
8
|
export function compare_buffers(buf1: Buffer, buf2: Buffer, max_length?: number): void {
|
package/source/set_deprecated.ts
CHANGED