node-opcua-utils 2.54.0 → 2.60.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/.mocharc.yml +10 -10
  2. package/LICENSE +20 -20
  3. package/dist/function_variadic.d.ts +1 -0
  4. package/dist/function_variadic.js +3 -0
  5. package/dist/function_variadic.js.map +1 -0
  6. package/dist/get_function_parameters_name.d.ts +2 -1
  7. package/dist/get_function_parameters_name.js +0 -1
  8. package/dist/get_function_parameters_name.js.map +1 -1
  9. package/dist/index.d.ts +1 -1
  10. package/dist/index.js +2 -2
  11. package/dist/index.js.map +1 -1
  12. package/dist/line_file.d.ts +1 -1
  13. package/dist/line_file.js +3 -3
  14. package/dist/line_file.js.map +1 -1
  15. package/dist/object_classname.d.ts +1 -1
  16. package/dist/object_classname.js.map +1 -1
  17. package/dist/replace_buffer_with_hex_dump.d.ts +3 -1
  18. package/dist/replace_buffer_with_hex_dump.js +1 -1
  19. package/dist/replace_buffer_with_hex_dump.js.map +1 -1
  20. package/dist/set_deprecated.d.ts +2 -1
  21. package/dist/set_deprecated.js +2 -2
  22. package/dist/set_deprecated.js.map +1 -1
  23. package/dist/string_utils.d.ts +4 -4
  24. package/dist/string_utils.js +5 -5
  25. package/dist/string_utils.js.map +1 -1
  26. package/dist/timestamp.js +1 -4
  27. package/dist/timestamp.js.map +1 -1
  28. package/dist/watchdog.d.ts +1 -0
  29. package/dist/watchdog.js +5 -2
  30. package/dist/watchdog.js.map +1 -1
  31. package/package.json +7 -5
  32. package/source/buffer_ellipsis.ts +13 -13
  33. package/source/compare_buffers.ts +23 -23
  34. package/source/function_variadic.ts +1 -0
  35. package/source/get_clock_tick.ts +18 -18
  36. package/source/get_function_parameters_name.ts +15 -13
  37. package/source/index.ts +46 -46
  38. package/source/line_file.ts +24 -24
  39. package/source/match_uri.ts +19 -19
  40. package/source/object_classname.ts +11 -11
  41. package/source/replace_buffer_with_hex_dump.ts +15 -15
  42. package/source/set_deprecated.ts +29 -28
  43. package/source/string_utils.ts +12 -12
  44. package/source/timestamp.ts +11 -15
  45. package/source/watchdog.ts +205 -200
  46. package/dist/construct_filename.d.ts +0 -4
  47. package/dist/construct_filename.js +0 -14
  48. package/dist/construct_filename.js.map +0 -1
  49. package/dist/linefile.d.ts +0 -8
  50. package/dist/linefile.js +0 -37
  51. package/dist/linefile.js.map +0 -1
  52. package/dist/nodejs-only/index.d.ts +0 -2
  53. package/dist/nodejs-only/index.js +0 -15
  54. package/dist/nodejs-only/index.js.map +0 -1
  55. package/dist/nodejs-only/linefile.d.ts +0 -8
  56. package/dist/nodejs-only/linefile.js +0 -37
  57. package/dist/nodejs-only/linefile.js.map +0 -1
  58. package/dist/nodejs-only/normalize_require_file.d.ts +0 -10
  59. package/dist/nodejs-only/normalize_require_file.js +0 -26
  60. package/dist/nodejs-only/normalize_require_file.js.map +0 -1
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(!Object.prototype.hasOwnProperty.call(mask, "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(!Object.prototype.hasOwnProperty.call(mask, "value"));
28
+ return (value & (mask as number)) === (mask as number);
29
+ }
30
+
31
+ export function isNullOrUndefined(value: unknown | undefined): 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,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(...args: string[]): void {
13
+ let str = "";
14
+ // tslint:disable:prefer-for-of
15
+ for (let i = 0; i < args.length; i++) {
16
+ str += args[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,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): boolean {
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: unknown): 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: Record<string, { toString(format: string): void }>): any {
5
+ for (const p in obj) {
6
+ if (Object.prototype.hasOwnProperty.call(obj, 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,28 +1,29 @@
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
+ import { FunctionVariadic } from "./function_variadic";
9
+
10
+ /* istanbul ignore next */
11
+ export function setDeprecated(constructor: FunctionVariadic, methodName: string, helpString: string): void {
12
+ const oldMethod = constructor.prototype[methodName];
13
+
14
+ assert(oldMethod instanceof Function, "expecting a valid " + methodName + "method on class " + constructor.constructor.name);
15
+
16
+ let counter = 0;
17
+ constructor.prototype[methodName] = function (...args: any[]) {
18
+ if (counter % 1000 === 0) {
19
+ // tslint:disable:no-console
20
+ console.log(
21
+ chalk.green("Warning !"),
22
+ chalk.green(chalk.bold(constructor.name + "#" + methodName), " is now deprecated")
23
+ );
24
+ console.log(" ", helpString);
25
+ }
26
+ counter++;
27
+ return oldMethod.call(this, ...args);
28
+ };
29
+ }
@@ -31,16 +31,16 @@ export function countAlphaSlow(str: string): number {
31
31
 
32
32
  export function countUpperCase(str: string): number {
33
33
  let count = 0;
34
- const n = str.length
35
- for (let i=0; i < n ; i++) {
34
+ const n = str.length;
35
+ for (let i = 0; i < n; i++) {
36
36
  count += isUpperCaseChar(str[i]) ? 1 : 0;
37
37
  }
38
38
  return count;
39
39
  }
40
40
  export function countAlpha(str: string): number {
41
41
  let count = 0;
42
- const n = str.length
43
- for (let i=0; i < n ; i++) {
42
+ const n = str.length;
43
+ for (let i = 0; i < n; i++) {
44
44
  count += isAlpha(str[i]) ? 1 : 0;
45
45
  }
46
46
  return count;
@@ -54,19 +54,19 @@ export function countAlpha(str: string): number {
54
54
  *
55
55
  * OPCUA and Javascript use two different rules to build identifiers.
56
56
  *
57
- * OPCUA Identifier usually starts with a upper case letter and word are join together, this is known as
57
+ * OPCUA Identifier usually starts with a upper case letter and word are join together, this is known as
58
58
  * the Pascal case, or CapitalizedWords convention. (for instance HelloWorld)
59
- * But sometime, OPCUA indentifiers do not follow this convention strictly and we can find various
60
- * other convention being applied such as underscore between word, or addintion of ACRONYMED prefixes.
61
- * On it's own, this causes great confusion and inconsistancy in programming style.
59
+ * But sometime, OPCUA identifiers do not follow this convention strictly and we can find various
60
+ * other convention being applied such as underscore between word, or addition of ACRONYMIC prefixes.
61
+ * On it's own, this causes great confusion and inconsistency in programming style.
62
62
  *
63
- * Javascritpt uses a slightly different convention called camelCase where word are joined together
64
- * and inner words starts with a capital letter whereas first word starts with a lower case letter.
63
+ * Javascript uses a slightly different convention called camelCase where word are joined together
64
+ * and inner words starts with a capital letter whereas first word starts with a lower case letter.
65
65
  * (for instance helloWorld)
66
66
  *
67
67
  * In node-opcua we have taken the opinionated decision to consistently use camelCase convention for
68
68
  * object properties so that all the code look nice and consistent.
69
- * the lowerFirstLetter method can be used to easily convert from the OPCUA naming convention
69
+ * the lowerFirstLetter method can be used to easily convert from the OPCUA naming convention
70
70
  * to javascript naming convention by applying the following rules.
71
71
  *
72
72
  * * each ascii sequence in a identifier will be converted to lower camel case.
@@ -110,7 +110,7 @@ export function lowerFirstLetter(str: string): string {
110
110
  return str;
111
111
  }
112
112
 
113
- if (str.match(/\_/)) {
113
+ if (str.match(/_/)) {
114
114
  return str.split("_").map(lowerFirstLetter).join("_");
115
115
  }
116
116
  let result = str.substr(0, 1).toLowerCase() + str.substr(1);
@@ -1,15 +1,11 @@
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) + ":" + w(d.getUTCMinutes(), 2) + ":" + w(d.getUTCSeconds(), 2) + ":" + w(d.getMilliseconds(), 3);
7
+ }
8
+
9
+ export function timestamp(): string {
10
+ return t(new Date());
11
+ }