node-opcua-utils 2.52.0 → 2.54.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/.mocharc.yml +10 -10
- package/LICENSE +20 -20
- package/dist/construct_filename.d.ts +4 -0
- package/dist/construct_filename.js +14 -0
- package/dist/construct_filename.js.map +1 -0
- package/dist/linefile.d.ts +8 -0
- package/dist/linefile.js +37 -0
- package/dist/linefile.js.map +1 -0
- package/dist/nodejs-only/index.d.ts +2 -0
- package/dist/nodejs-only/index.js +15 -0
- package/dist/nodejs-only/index.js.map +1 -0
- package/dist/nodejs-only/linefile.d.ts +8 -0
- package/dist/nodejs-only/linefile.js +37 -0
- package/dist/nodejs-only/linefile.js.map +1 -0
- package/dist/nodejs-only/normalize_require_file.d.ts +10 -0
- package/dist/nodejs-only/normalize_require_file.js +26 -0
- package/dist/nodejs-only/normalize_require_file.js.map +1 -0
- package/package.json +3 -3
- package/source/buffer_ellipsis.ts +13 -13
- package/source/compare_buffers.ts +23 -23
- package/source/get_function_parameters_name.ts +13 -13
- package/source/index.ts +46 -46
- package/source/line_file.ts +24 -24
- package/source/match_uri.ts +19 -19
- package/source/object_classname.ts +11 -11
- package/source/replace_buffer_with_hex_dump.ts +15 -15
- package/source/set_deprecated.ts +28 -28
- package/source/timestamp.ts +15 -15
package/.mocharc.yml
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
recursive: true
|
|
2
|
-
require:
|
|
3
|
-
- ../../node_modules/source-map-support/register
|
|
4
|
-
- ../../node_modules/ts-node/register
|
|
5
|
-
- ../../node_modules/should
|
|
6
|
-
timeout: 20000
|
|
7
|
-
files:
|
|
8
|
-
- test/**/*.ts
|
|
9
|
-
- test/**/*.js
|
|
10
|
-
|
|
1
|
+
recursive: true
|
|
2
|
+
require:
|
|
3
|
+
- ../../node_modules/source-map-support/register
|
|
4
|
+
- ../../node_modules/ts-node/register
|
|
5
|
+
- ../../node_modules/should
|
|
6
|
+
timeout: 20000
|
|
7
|
+
files:
|
|
8
|
+
- test/**/*.ts
|
|
9
|
+
- test/**/*.js
|
|
10
|
+
|
package/LICENSE
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2014-2021 Etienne Rossignon
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
-
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
-
the Software without restriction, including without limitation the rights to
|
|
8
|
-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
-
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
-
subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
-
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2014-2021 Etienne Rossignon
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.constructFilename = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @module node-opcua-utils
|
|
6
|
+
*/
|
|
7
|
+
function constructFilename(filename) {
|
|
8
|
+
throw new Error("constructFilename has been deprecated ! use node-opcua-nodesets.constructFilename or ....");
|
|
9
|
+
// xx var dirname = $_$.dirname;
|
|
10
|
+
// xx var file = path.join(dirname, filename);
|
|
11
|
+
// xx return file;
|
|
12
|
+
}
|
|
13
|
+
exports.constructFilename = constructFilename;
|
|
14
|
+
//# sourceMappingURL=construct_filename.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"construct_filename.js","sourceRoot":"","sources":["../source/construct_filename.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,SAAgB,iBAAiB,CAAC,QAAgB;IAC9C,MAAM,IAAI,KAAK,CAAC,2FAA2F,CAAC,CAAC;IAC7G,mCAAmC;IACnC,iDAAiD;IACjD,qBAAqB;AACzB,CAAC;AALD,8CAKC"}
|
package/dist/linefile.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LineFile = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @module node-opcua-utils
|
|
6
|
+
*/
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const os = require("os");
|
|
9
|
+
class LineFile {
|
|
10
|
+
constructor() {
|
|
11
|
+
this._line = [];
|
|
12
|
+
this.write("// --------- This code has been automatically generated !!! " + new Date().toISOString());
|
|
13
|
+
this.write("/**");
|
|
14
|
+
this.write(" * @module node-opcua-types");
|
|
15
|
+
this.write(" */");
|
|
16
|
+
}
|
|
17
|
+
write(...arg) {
|
|
18
|
+
let str = "";
|
|
19
|
+
// tslint:disable:prefer-for-of
|
|
20
|
+
for (let i = 0; i < arguments.length; i++) {
|
|
21
|
+
str += arguments[i];
|
|
22
|
+
}
|
|
23
|
+
this._line.push(str);
|
|
24
|
+
}
|
|
25
|
+
toString() {
|
|
26
|
+
return this._line.join(os.EOL);
|
|
27
|
+
}
|
|
28
|
+
save(filename) {
|
|
29
|
+
fs_1.writeFileSync(filename, this.toString(), "ascii");
|
|
30
|
+
}
|
|
31
|
+
saveFormat(filename, formatter) {
|
|
32
|
+
const code = formatter(this.toString());
|
|
33
|
+
fs_1.writeFileSync(filename, code, "ascii");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.LineFile = LineFile;
|
|
37
|
+
//# sourceMappingURL=linefile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"linefile.js","sourceRoot":"","sources":["../source/linefile.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,2BAAmC;AACnC,yBAAyB;AAEzB,MAAa,QAAQ;IAIjB;QACI,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,KAAK,CAAC,8DAA8D,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;QACtG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAClB,IAAI,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC;QAC1C,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;IAEM,KAAK,CAAC,GAAG,GAAa;QACzB,IAAI,GAAG,GAAG,EAAE,CAAC;QAEb,+BAA+B;QAC/B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACvC,GAAG,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC;SACvB;QACD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IAEM,QAAQ;QACX,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC;IAEM,IAAI,CAAC,QAAgB;QACxB,kBAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,EAAE,OAAO,CAAC,CAAC;IACtD,CAAC;IAEM,UAAU,CAAC,QAAgB,EAAE,SAAmC;QACnE,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QACxC,kBAAa,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAC3C,CAAC;CACJ;AAlCD,4BAkCC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./linefile"), exports);
|
|
14
|
+
__exportStar(require("./normalize_require_file"), exports);
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/nodejs-only/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAA2B;AAC3B,2DAAyC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LineFile = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @module node-opcua-utils
|
|
6
|
+
*/
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const os = require("os");
|
|
9
|
+
class LineFile {
|
|
10
|
+
constructor() {
|
|
11
|
+
this._line = [];
|
|
12
|
+
this.write("// --------- This code has been automatically generated !!! " + new Date().toISOString());
|
|
13
|
+
this.write("/**");
|
|
14
|
+
this.write(" * @module node-opcua-types");
|
|
15
|
+
this.write(" */");
|
|
16
|
+
}
|
|
17
|
+
write(...arg) {
|
|
18
|
+
let str = "";
|
|
19
|
+
// tslint:disable:prefer-for-of
|
|
20
|
+
for (let i = 0; i < arguments.length; i++) {
|
|
21
|
+
str += arguments[i];
|
|
22
|
+
}
|
|
23
|
+
this._line.push(str);
|
|
24
|
+
}
|
|
25
|
+
toString() {
|
|
26
|
+
return this._line.join(os.EOL);
|
|
27
|
+
}
|
|
28
|
+
save(filename) {
|
|
29
|
+
fs_1.writeFileSync(filename, this.toString(), "ascii");
|
|
30
|
+
}
|
|
31
|
+
saveFormat(filename, formatter) {
|
|
32
|
+
const code = formatter(this.toString());
|
|
33
|
+
fs_1.writeFileSync(filename, code, "ascii");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.LineFile = LineFile;
|
|
37
|
+
//# sourceMappingURL=linefile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"linefile.js","sourceRoot":"","sources":["../../source/nodejs-only/linefile.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,2BAAmC;AACnC,yBAAyB;AAEzB,MAAa,QAAQ;IAIjB;QACI,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,KAAK,CAAC,8DAA8D,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;QACtG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAClB,IAAI,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC;QAC1C,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;IAEM,KAAK,CAAC,GAAG,GAAa;QACzB,IAAI,GAAG,GAAG,EAAE,CAAC;QAEb,+BAA+B;QAC/B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACvC,GAAG,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC;SACvB;QACD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IAEM,QAAQ;QACX,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC;IAEM,IAAI,CAAC,QAAgB;QACxB,kBAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,EAAE,OAAO,CAAC,CAAC;IACtD,CAAC;IAEM,UAAU,CAAC,QAAgB,EAAE,SAAmC;QACnE,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QACxC,kBAAa,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAC3C,CAAC;CACJ;AAlCD,4BAkCC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @method normalize_require_file
|
|
3
|
+
* @param baseFolder
|
|
4
|
+
* @param fullPathToFile
|
|
5
|
+
*
|
|
6
|
+
*
|
|
7
|
+
* @example:
|
|
8
|
+
* normalize_require_file("/home/bob/folder1/","/home/bob/folder1/folder2/toto.js").should.eql("./folder2/toto");
|
|
9
|
+
*/
|
|
10
|
+
export declare function normalize_require_file(baseFolder: string, fullPathToFile: string): string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalize_require_file = void 0;
|
|
4
|
+
const path = require("path");
|
|
5
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
6
|
+
/**
|
|
7
|
+
* @method normalize_require_file
|
|
8
|
+
* @param baseFolder
|
|
9
|
+
* @param fullPathToFile
|
|
10
|
+
*
|
|
11
|
+
*
|
|
12
|
+
* @example:
|
|
13
|
+
* normalize_require_file("/home/bob/folder1/","/home/bob/folder1/folder2/toto.js").should.eql("./folder2/toto");
|
|
14
|
+
*/
|
|
15
|
+
function normalize_require_file(baseFolder, fullPathToFile) {
|
|
16
|
+
let localFile = path.relative(baseFolder, fullPathToFile).replace(/\\/g, "/");
|
|
17
|
+
// append ./ if necessary
|
|
18
|
+
if (localFile.substr(0, 1) !== ".") {
|
|
19
|
+
localFile = "./" + localFile;
|
|
20
|
+
}
|
|
21
|
+
// remove extension
|
|
22
|
+
localFile = localFile.substr(0, localFile.length - path.extname(localFile).length);
|
|
23
|
+
return localFile;
|
|
24
|
+
}
|
|
25
|
+
exports.normalize_require_file = normalize_require_file;
|
|
26
|
+
//# sourceMappingURL=normalize_require_file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize_require_file.js","sourceRoot":"","sources":["../../source/nodejs-only/normalize_require_file.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAC7B,wHAAwH;AACxH;;;;;;;;GAQG;AACH,SAAgB,sBAAsB,CAAC,UAAkB,EAAE,cAAsB;IAC7E,IAAI,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC9E,yBAAyB;IACzB,IAAI,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,GAAG,EAAE;QAChC,SAAS,GAAG,IAAI,GAAG,SAAS,CAAC;KAChC;IACD,mBAAmB;IACnB,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;IACnF,OAAO,SAAS,CAAC;AACrB,CAAC;AATD,wDASC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-opcua-utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.54.0",
|
|
4
4
|
"description": "pure nodejs OPCUA SDK - module -utils",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"node-opcua-assert": "2.52.0"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@types/node": "16.
|
|
18
|
+
"@types/node": "16.10.1",
|
|
19
19
|
"should": "^13.2.3",
|
|
20
20
|
"sinon": "^11.1.2"
|
|
21
21
|
},
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"internet of things"
|
|
35
35
|
],
|
|
36
36
|
"homepage": "http://node-opcua.github.io/",
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "d3093f76a2c8f574444fd59e98e7d53f34b83d8b"
|
|
38
38
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module node-opcua-utils
|
|
3
|
-
*/
|
|
4
|
-
export function buffer_ellipsis(buffer: Buffer, start?: number, end?: number): string {
|
|
5
|
-
start = start || 0;
|
|
6
|
-
end = end || buffer.length;
|
|
7
|
-
if (end - start < 40) {
|
|
8
|
-
return buffer.slice(start, end).toString("hex");
|
|
9
|
-
}
|
|
10
|
-
return buffer.slice(start, start + 10).toString("hex") + " ... " + buffer.slice(end - 10, end).toString("hex");
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
exports.buffer_ellipsis = buffer_ellipsis;
|
|
1
|
+
/**
|
|
2
|
+
* @module node-opcua-utils
|
|
3
|
+
*/
|
|
4
|
+
export function buffer_ellipsis(buffer: Buffer, start?: number, end?: number): string {
|
|
5
|
+
start = start || 0;
|
|
6
|
+
end = end || buffer.length;
|
|
7
|
+
if (end - start < 40) {
|
|
8
|
+
return buffer.slice(start, end).toString("hex");
|
|
9
|
+
}
|
|
10
|
+
return buffer.slice(start, start + 10).toString("hex") + " ... " + buffer.slice(end - 10, end).toString("hex");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
exports.buffer_ellipsis = buffer_ellipsis;
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module node-opcua-utils
|
|
3
|
-
*/
|
|
4
|
-
// tslint:disable:no-console
|
|
5
|
-
import * as chalk from "chalk";
|
|
6
|
-
import { buffer_ellipsis } from "./buffer_ellipsis";
|
|
7
|
-
|
|
8
|
-
export function compare_buffers(buf1: Buffer, buf2: Buffer, max_length?: number): void {
|
|
9
|
-
max_length = max_length || buf2.length;
|
|
10
|
-
const block_length = 80;
|
|
11
|
-
let cursor = 0;
|
|
12
|
-
while (cursor < max_length) {
|
|
13
|
-
const slice1 = buf1.slice(cursor, cursor + block_length);
|
|
14
|
-
const slice2 = buf2.slice(cursor, cursor + block_length);
|
|
15
|
-
if (slice2.toString("hex") !== slice1.toString("hex")) {
|
|
16
|
-
console.log("pos = ", cursor);
|
|
17
|
-
console.log("slice1 :", chalk.yellow(buffer_ellipsis(slice1)));
|
|
18
|
-
console.log("slice2 :", chalk.blue(buffer_ellipsis(slice2)));
|
|
19
|
-
}
|
|
20
|
-
cursor += block_length;
|
|
21
|
-
}
|
|
22
|
-
// xx buf1.length.should.equal(max_length);
|
|
23
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @module node-opcua-utils
|
|
3
|
+
*/
|
|
4
|
+
// tslint:disable:no-console
|
|
5
|
+
import * as chalk from "chalk";
|
|
6
|
+
import { buffer_ellipsis } from "./buffer_ellipsis";
|
|
7
|
+
|
|
8
|
+
export function compare_buffers(buf1: Buffer, buf2: Buffer, max_length?: number): void {
|
|
9
|
+
max_length = max_length || buf2.length;
|
|
10
|
+
const block_length = 80;
|
|
11
|
+
let cursor = 0;
|
|
12
|
+
while (cursor < max_length) {
|
|
13
|
+
const slice1 = buf1.slice(cursor, cursor + block_length);
|
|
14
|
+
const slice2 = buf2.slice(cursor, cursor + block_length);
|
|
15
|
+
if (slice2.toString("hex") !== slice1.toString("hex")) {
|
|
16
|
+
console.log("pos = ", cursor);
|
|
17
|
+
console.log("slice1 :", chalk.yellow(buffer_ellipsis(slice1)));
|
|
18
|
+
console.log("slice2 :", chalk.blue(buffer_ellipsis(slice2)));
|
|
19
|
+
}
|
|
20
|
+
cursor += block_length;
|
|
21
|
+
}
|
|
22
|
+
// xx buf1.length.should.equal(max_length);
|
|
23
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module node-opcua-utils
|
|
3
|
-
*/
|
|
4
|
-
const STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm;
|
|
5
|
-
const ARGUMENT_NAMES = /([^\s,]+)/g;
|
|
6
|
-
|
|
7
|
-
// tslint:disable-next-line:ban-types
|
|
8
|
-
export function getFunctionParameterNames(func: Function) {
|
|
9
|
-
const fnStr = func.toString().replace(STRIP_COMMENTS, "");
|
|
10
|
-
let result = fnStr.slice(fnStr.indexOf("(") + 1, fnStr.indexOf(")")).match(ARGUMENT_NAMES);
|
|
11
|
-
if (result === null) { result = []; }
|
|
12
|
-
return result;
|
|
13
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @module node-opcua-utils
|
|
3
|
+
*/
|
|
4
|
+
const STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm;
|
|
5
|
+
const ARGUMENT_NAMES = /([^\s,]+)/g;
|
|
6
|
+
|
|
7
|
+
// tslint:disable-next-line:ban-types
|
|
8
|
+
export function getFunctionParameterNames(func: Function) {
|
|
9
|
+
const fnStr = func.toString().replace(STRIP_COMMENTS, "");
|
|
10
|
+
let result = fnStr.slice(fnStr.indexOf("(") + 1, fnStr.indexOf(")")).match(ARGUMENT_NAMES);
|
|
11
|
+
if (result === null) { result = []; }
|
|
12
|
+
return result;
|
|
13
|
+
}
|
package/source/index.ts
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module node-opcua-utils
|
|
3
|
-
*/
|
|
4
|
-
// tslint:disable:no-bitwise
|
|
5
|
-
import { assert } from "node-opcua-assert";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* set a flag
|
|
9
|
-
* @method set_flag
|
|
10
|
-
*/
|
|
11
|
-
export function set_flag(value: number, mask: number | { value: number }): number {
|
|
12
|
-
if ((mask as any).value) {
|
|
13
|
-
mask = (mask as any).value;
|
|
14
|
-
}
|
|
15
|
-
assert(!mask.hasOwnProperty("value"));
|
|
16
|
-
assert(mask !== undefined);
|
|
17
|
-
return value | (mask as number);
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* check if a set of bits are set in the values
|
|
21
|
-
* @method check_flag
|
|
22
|
-
*/
|
|
23
|
-
export function check_flag(value: number, mask: number | { value: number }): boolean {
|
|
24
|
-
if ((mask as any).value) {
|
|
25
|
-
mask = (mask as any).value;
|
|
26
|
-
}
|
|
27
|
-
assert(!mask.hasOwnProperty("value"));
|
|
28
|
-
return (value & (mask as number)) === (mask as number);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function isNullOrUndefined(value: any): boolean {
|
|
32
|
-
return value === undefined || value === null;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export { buffer_ellipsis } from "./buffer_ellipsis";
|
|
36
|
-
export { capitalizeFirstLetter, lowerFirstLetter } from "./string_utils";
|
|
37
|
-
export { getObjectClassName } from "./object_classname";
|
|
38
|
-
export { get_clock_tick } from "./get_clock_tick";
|
|
39
|
-
export { compare_buffers } from "./compare_buffers";
|
|
40
|
-
export { getFunctionParameterNames } from "./get_function_parameters_name";
|
|
41
|
-
export * from "./watchdog";
|
|
42
|
-
export { setDeprecated } from "./set_deprecated";
|
|
43
|
-
export { replaceBufferWithHexDump } from "./replace_buffer_with_hex_dump";
|
|
44
|
-
export * from "./timestamp";
|
|
45
|
-
export * from "./line_file";
|
|
46
|
-
export * from "./match_uri";
|
|
1
|
+
/**
|
|
2
|
+
* @module node-opcua-utils
|
|
3
|
+
*/
|
|
4
|
+
// tslint:disable:no-bitwise
|
|
5
|
+
import { assert } from "node-opcua-assert";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* set a flag
|
|
9
|
+
* @method set_flag
|
|
10
|
+
*/
|
|
11
|
+
export function set_flag(value: number, mask: number | { value: number }): number {
|
|
12
|
+
if ((mask as any).value) {
|
|
13
|
+
mask = (mask as any).value;
|
|
14
|
+
}
|
|
15
|
+
assert(!mask.hasOwnProperty("value"));
|
|
16
|
+
assert(mask !== undefined);
|
|
17
|
+
return value | (mask as number);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* check if a set of bits are set in the values
|
|
21
|
+
* @method check_flag
|
|
22
|
+
*/
|
|
23
|
+
export function check_flag(value: number, mask: number | { value: number }): boolean {
|
|
24
|
+
if ((mask as any).value) {
|
|
25
|
+
mask = (mask as any).value;
|
|
26
|
+
}
|
|
27
|
+
assert(!mask.hasOwnProperty("value"));
|
|
28
|
+
return (value & (mask as number)) === (mask as number);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function isNullOrUndefined(value: any): boolean {
|
|
32
|
+
return value === undefined || value === null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { buffer_ellipsis } from "./buffer_ellipsis";
|
|
36
|
+
export { capitalizeFirstLetter, lowerFirstLetter } from "./string_utils";
|
|
37
|
+
export { getObjectClassName } from "./object_classname";
|
|
38
|
+
export { get_clock_tick } from "./get_clock_tick";
|
|
39
|
+
export { compare_buffers } from "./compare_buffers";
|
|
40
|
+
export { getFunctionParameterNames } from "./get_function_parameters_name";
|
|
41
|
+
export * from "./watchdog";
|
|
42
|
+
export { setDeprecated } from "./set_deprecated";
|
|
43
|
+
export { replaceBufferWithHexDump } from "./replace_buffer_with_hex_dump";
|
|
44
|
+
export * from "./timestamp";
|
|
45
|
+
export * from "./line_file";
|
|
46
|
+
export * from "./match_uri";
|
package/source/line_file.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module node-opcua-utils
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export class LineFile {
|
|
6
|
-
private _line: string[];
|
|
7
|
-
|
|
8
|
-
constructor() {
|
|
9
|
-
this._line = [];
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
public write(...arg: string[]): void {
|
|
13
|
-
let str = "";
|
|
14
|
-
// tslint:disable:prefer-for-of
|
|
15
|
-
for (let i = 0; i < arguments.length; i++) {
|
|
16
|
-
str += arguments[i];
|
|
17
|
-
}
|
|
18
|
-
this._line.push(str);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public toString(endOfLine: "\n" | "\r" = "\n"): string {
|
|
22
|
-
return this._line.join(endOfLine);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @module node-opcua-utils
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export class LineFile {
|
|
6
|
+
private _line: string[];
|
|
7
|
+
|
|
8
|
+
constructor() {
|
|
9
|
+
this._line = [];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public write(...arg: string[]): void {
|
|
13
|
+
let str = "";
|
|
14
|
+
// tslint:disable:prefer-for-of
|
|
15
|
+
for (let i = 0; i < arguments.length; i++) {
|
|
16
|
+
str += arguments[i];
|
|
17
|
+
}
|
|
18
|
+
this._line.push(str);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public toString(endOfLine: "\n" | "\r" = "\n"): string {
|
|
22
|
+
return this._line.join(endOfLine);
|
|
23
|
+
}
|
|
24
|
+
}
|
package/source/match_uri.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
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 function matchUri(endpointUri1: string | null, endpointUri2: string | null) {
|
|
12
|
-
if (endpointUri1 === null) {
|
|
13
|
-
return endpointUri2 === null;
|
|
14
|
-
}
|
|
15
|
-
if (endpointUri2 === null) {
|
|
16
|
-
return endpointUri1 === null;
|
|
17
|
-
}
|
|
18
|
-
return endpointUri1.toLowerCase() === endpointUri2.toLowerCase();
|
|
19
|
-
}
|
|
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 function matchUri(endpointUri1: string | null, endpointUri2: string | null) {
|
|
12
|
+
if (endpointUri1 === null) {
|
|
13
|
+
return endpointUri2 === null;
|
|
14
|
+
}
|
|
15
|
+
if (endpointUri2 === null) {
|
|
16
|
+
return endpointUri1 === null;
|
|
17
|
+
}
|
|
18
|
+
return endpointUri1.toLowerCase() === endpointUri2.toLowerCase();
|
|
19
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module node-opcua-utils
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* @method getObjectClassName
|
|
6
|
-
* @param obj
|
|
7
|
-
* @return {string}
|
|
8
|
-
*/
|
|
9
|
-
export function getObjectClassName(obj: object): string {
|
|
10
|
-
return Object.prototype.toString.call(obj).slice(8, -1);
|
|
11
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @module node-opcua-utils
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* @method getObjectClassName
|
|
6
|
+
* @param obj
|
|
7
|
+
* @return {string}
|
|
8
|
+
*/
|
|
9
|
+
export function getObjectClassName(obj: object): string {
|
|
10
|
+
return Object.prototype.toString.call(obj).slice(8, -1);
|
|
11
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module node-opcua-utils
|
|
3
|
-
*/
|
|
4
|
-
export function replaceBufferWithHexDump(obj: any): any {
|
|
5
|
-
for (const p in obj) {
|
|
6
|
-
if (obj.hasOwnProperty(p)) {
|
|
7
|
-
if (obj[p] instanceof Buffer) {
|
|
8
|
-
obj[p] = "<BUFFER>" + obj[p].toString("hex") + "</BUFFER>";
|
|
9
|
-
} else if (typeof obj[p] === "object") {
|
|
10
|
-
replaceBufferWithHexDump(obj[p]);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return obj;
|
|
15
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @module node-opcua-utils
|
|
3
|
+
*/
|
|
4
|
+
export function replaceBufferWithHexDump(obj: any): any {
|
|
5
|
+
for (const p in obj) {
|
|
6
|
+
if (obj.hasOwnProperty(p)) {
|
|
7
|
+
if (obj[p] instanceof Buffer) {
|
|
8
|
+
obj[p] = "<BUFFER>" + obj[p].toString("hex") + "</BUFFER>";
|
|
9
|
+
} else if (typeof obj[p] === "object") {
|
|
10
|
+
replaceBufferWithHexDump(obj[p]);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return obj;
|
|
15
|
+
}
|
package/source/set_deprecated.ts
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module node-opcua-utils
|
|
3
|
-
*/
|
|
4
|
-
// tslint:disable:ban-types
|
|
5
|
-
import * as chalk from "chalk";
|
|
6
|
-
import { assert } from "node-opcua-assert";
|
|
7
|
-
|
|
8
|
-
/* istanbul ignore next */
|
|
9
|
-
export function setDeprecated(constructor: Function, methodName: string, helpString: string): void {
|
|
10
|
-
|
|
11
|
-
const oldMethod = constructor.prototype[methodName];
|
|
12
|
-
|
|
13
|
-
assert(oldMethod instanceof Function,
|
|
14
|
-
"expecting a valid " + methodName + "method on class " + constructor.constructor.name);
|
|
15
|
-
|
|
16
|
-
let counter = 0;
|
|
17
|
-
constructor.prototype[methodName] = function() {
|
|
18
|
-
if (counter % 1000 === 0) {
|
|
19
|
-
// tslint:disable:no-console
|
|
20
|
-
console.log(chalk.green("Warning !"),
|
|
21
|
-
chalk.green(chalk.bold(constructor.name + "#" + methodName), " is now deprecated"));
|
|
22
|
-
console.log(" ", helpString);
|
|
23
|
-
}
|
|
24
|
-
counter++;
|
|
25
|
-
return oldMethod.apply(this, arguments);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @module node-opcua-utils
|
|
3
|
+
*/
|
|
4
|
+
// tslint:disable:ban-types
|
|
5
|
+
import * as chalk from "chalk";
|
|
6
|
+
import { assert } from "node-opcua-assert";
|
|
7
|
+
|
|
8
|
+
/* istanbul ignore next */
|
|
9
|
+
export function setDeprecated(constructor: Function, methodName: string, helpString: string): void {
|
|
10
|
+
|
|
11
|
+
const oldMethod = constructor.prototype[methodName];
|
|
12
|
+
|
|
13
|
+
assert(oldMethod instanceof Function,
|
|
14
|
+
"expecting a valid " + methodName + "method on class " + constructor.constructor.name);
|
|
15
|
+
|
|
16
|
+
let counter = 0;
|
|
17
|
+
constructor.prototype[methodName] = function() {
|
|
18
|
+
if (counter % 1000 === 0) {
|
|
19
|
+
// tslint:disable:no-console
|
|
20
|
+
console.log(chalk.green("Warning !"),
|
|
21
|
+
chalk.green(chalk.bold(constructor.name + "#" + methodName), " is now deprecated"));
|
|
22
|
+
console.log(" ", helpString);
|
|
23
|
+
}
|
|
24
|
+
counter++;
|
|
25
|
+
return oldMethod.apply(this, arguments);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
}
|
package/source/timestamp.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
function w(s: string | number, length: number): string {
|
|
2
|
-
return ("000" + s).substr(-length);
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
function t(d: Date): string {
|
|
6
|
-
return w(d.getUTCHours(), 2) + ":"
|
|
7
|
-
+ w(d.getUTCMinutes(), 2) + ":"
|
|
8
|
-
+ w(d.getUTCSeconds(), 2) + ":"
|
|
9
|
-
+ w(d.getMilliseconds(), 3);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function timestamp() {
|
|
13
|
-
return t(new Date());
|
|
14
|
-
}
|
|
15
|
-
|
|
1
|
+
function w(s: string | number, length: number): string {
|
|
2
|
+
return ("000" + s).substr(-length);
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
function t(d: Date): string {
|
|
6
|
+
return w(d.getUTCHours(), 2) + ":"
|
|
7
|
+
+ w(d.getUTCMinutes(), 2) + ":"
|
|
8
|
+
+ w(d.getUTCSeconds(), 2) + ":"
|
|
9
|
+
+ w(d.getMilliseconds(), 3);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function timestamp() {
|
|
13
|
+
return t(new Date());
|
|
14
|
+
}
|
|
15
|
+
|