node-opcua-basic-types 2.97.0 → 2.98.1

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/node_id.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream";
2
- import { ExpandedNodeId, NodeId } from "node-opcua-nodeid";
3
- export declare function isValidNodeId(nodeId: NodeId): boolean;
4
- export declare function randomNodeId(): NodeId;
5
- export declare function encodeNodeId(nodeId: NodeId, stream: OutputBinaryStream): void;
6
- export declare function encodeExpandedNodeId(expandedNodeId: ExpandedNodeId, stream: OutputBinaryStream): void;
7
- export declare function decodeNodeId(stream: BinaryStream, _nodeId?: NodeId): NodeId;
8
- export declare function decodeExpandedNodeId(stream: BinaryStream, _nodeId?: ExpandedNodeId): ExpandedNodeId;
9
- export { coerceNodeId, coerceExpandedNodeId } from "node-opcua-nodeid";
1
+ import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream";
2
+ import { ExpandedNodeId, NodeId } from "node-opcua-nodeid";
3
+ export declare function isValidNodeId(nodeId: NodeId): boolean;
4
+ export declare function randomNodeId(): NodeId;
5
+ export declare function encodeNodeId(nodeId: NodeId, stream: OutputBinaryStream): void;
6
+ export declare function encodeExpandedNodeId(expandedNodeId: ExpandedNodeId, stream: OutputBinaryStream): void;
7
+ export declare function decodeNodeId(stream: BinaryStream, _nodeId?: NodeId): NodeId;
8
+ export declare function decodeExpandedNodeId(stream: BinaryStream, _nodeId?: ExpandedNodeId): ExpandedNodeId;
9
+ export { coerceNodeId, coerceExpandedNodeId } from "node-opcua-nodeid";
package/dist/node_id.js CHANGED
@@ -1,189 +1,189 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.coerceExpandedNodeId = exports.coerceNodeId = exports.decodeExpandedNodeId = exports.decodeNodeId = exports.encodeExpandedNodeId = exports.encodeNodeId = exports.randomNodeId = exports.isValidNodeId = void 0;
4
- /***
5
- * @module node-opcua-basic-types
6
- */
7
- const node_opcua_assert_1 = require("node-opcua-assert");
8
- const node_opcua_nodeid_1 = require("node-opcua-nodeid");
9
- const byte_string_1 = require("./byte_string");
10
- const guid_1 = require("./guid");
11
- const integers_1 = require("./integers");
12
- const string_1 = require("./string");
13
- const utils_1 = require("./utils");
14
- function isUInt8(value) {
15
- return value >= 0 && value <= 0xff;
16
- }
17
- function isUInt16(value) {
18
- return value >= 0 && value <= 0xffff;
19
- }
20
- function nodeID_encodingByte(nodeId) {
21
- let encodingByte = 0;
22
- if (nodeId.identifierType === node_opcua_nodeid_1.NodeIdType.NUMERIC) {
23
- if (isUInt8(nodeId.value) &&
24
- !nodeId.namespace &&
25
- !nodeId.namespaceUri &&
26
- !nodeId.serverIndex) {
27
- encodingByte = encodingByte | 0 /* EnumNodeIdEncoding.TwoBytes */;
28
- }
29
- else if (isUInt16(nodeId.value) &&
30
- isUInt8(nodeId.namespace) &&
31
- !nodeId.namespaceUri &&
32
- !nodeId.serverIndex) {
33
- encodingByte = encodingByte | 1 /* EnumNodeIdEncoding.FourBytes */;
34
- }
35
- else {
36
- encodingByte = encodingByte | 2 /* EnumNodeIdEncoding.Numeric */;
37
- }
38
- }
39
- else if (nodeId.identifierType === node_opcua_nodeid_1.NodeIdType.STRING) {
40
- encodingByte = encodingByte | 3 /* EnumNodeIdEncoding.String */;
41
- }
42
- else if (nodeId.identifierType === node_opcua_nodeid_1.NodeIdType.BYTESTRING) {
43
- encodingByte = encodingByte | 5 /* EnumNodeIdEncoding.ByteString */;
44
- }
45
- else if (nodeId.identifierType === node_opcua_nodeid_1.NodeIdType.GUID) {
46
- encodingByte = encodingByte | 4 /* EnumNodeIdEncoding.Guid */;
47
- }
48
- if (Object.prototype.hasOwnProperty.call(nodeId, "namespaceUri") && nodeId.namespaceUri) {
49
- encodingByte = encodingByte | 128 /* EnumNodeIdEncoding.NamespaceUriFlag */;
50
- }
51
- if (Object.prototype.hasOwnProperty.call(nodeId, "serverIndex") && nodeId.serverIndex) {
52
- encodingByte = encodingByte | 64 /* EnumNodeIdEncoding.ServerIndexFlag */;
53
- }
54
- return encodingByte;
55
- }
56
- function isValidNodeId(nodeId) {
57
- return nodeId instanceof node_opcua_nodeid_1.NodeId;
58
- }
59
- exports.isValidNodeId = isValidNodeId;
60
- function randomNodeId() {
61
- const value = (0, utils_1.getRandomInt)(0, 0xfffff);
62
- const namespace = (0, utils_1.getRandomInt)(0, 3);
63
- return (0, node_opcua_nodeid_1.makeNodeId)(value, namespace);
64
- }
65
- exports.randomNodeId = randomNodeId;
66
- function _encodeNodeId(encodingByte, nodeId, stream) {
67
- stream.writeUInt8(encodingByte); // encoding byte
68
- /*jslint bitwise: true */
69
- encodingByte &= 0x3f;
70
- switch (encodingByte) {
71
- case 0 /* EnumNodeIdEncoding.TwoBytes */:
72
- stream.writeUInt8(nodeId ? nodeId.value : 0);
73
- break;
74
- case 1 /* EnumNodeIdEncoding.FourBytes */:
75
- stream.writeUInt8(nodeId.namespace);
76
- stream.writeUInt16(nodeId.value);
77
- break;
78
- case 2 /* EnumNodeIdEncoding.Numeric */:
79
- stream.writeUInt16(nodeId.namespace);
80
- stream.writeUInt32(nodeId.value);
81
- break;
82
- case 3 /* EnumNodeIdEncoding.String */:
83
- stream.writeUInt16(nodeId.namespace);
84
- (0, string_1.encodeString)(nodeId.value, stream);
85
- break;
86
- case 5 /* EnumNodeIdEncoding.ByteString */:
87
- stream.writeUInt16(nodeId.namespace);
88
- (0, byte_string_1.encodeByteString)(nodeId.value, stream);
89
- break;
90
- default:
91
- (0, node_opcua_assert_1.assert)(encodingByte === 4 /* EnumNodeIdEncoding.Guid */);
92
- stream.writeUInt16(nodeId.namespace);
93
- (0, guid_1.encodeGuid)(nodeId.value, stream);
94
- break;
95
- }
96
- }
97
- function encodeNodeId(nodeId, stream) {
98
- let encodingByte = nodeID_encodingByte(nodeId);
99
- /*jslint bitwise: true */
100
- encodingByte &= 0x3f;
101
- _encodeNodeId(encodingByte, nodeId, stream);
102
- }
103
- exports.encodeNodeId = encodeNodeId;
104
- function encodeExpandedNodeId(expandedNodeId, stream) {
105
- (0, node_opcua_assert_1.assert)(expandedNodeId, "encodeExpandedNodeId: must provide a valid expandedNodeId");
106
- const encodingByte = nodeID_encodingByte(expandedNodeId);
107
- _encodeNodeId(encodingByte, expandedNodeId, stream);
108
- if (encodingByte & 128 /* EnumNodeIdEncoding.NamespaceUriFlag */) {
109
- (0, string_1.encodeString)(expandedNodeId.namespaceUri, stream);
110
- }
111
- if (encodingByte & 64 /* EnumNodeIdEncoding.ServerIndexFlag */) {
112
- (0, integers_1.encodeUInt32)(expandedNodeId.serverIndex, stream);
113
- }
114
- }
115
- exports.encodeExpandedNodeId = encodeExpandedNodeId;
116
- function _decodeNodeId(encodingByte, stream, _nodeId) {
117
- let value;
118
- let namespace;
119
- let identifierType;
120
- /*jslint bitwise: true */
121
- encodingByte &= 0x3f; // 1 to 5
122
- switch (encodingByte) {
123
- case 0 /* EnumNodeIdEncoding.TwoBytes */:
124
- value = stream.readUInt8();
125
- identifierType = node_opcua_nodeid_1.NodeIdType.NUMERIC;
126
- break;
127
- case 1 /* EnumNodeIdEncoding.FourBytes */:
128
- namespace = stream.readUInt8();
129
- value = stream.readUInt16();
130
- identifierType = node_opcua_nodeid_1.NodeIdType.NUMERIC;
131
- break;
132
- case 2 /* EnumNodeIdEncoding.Numeric */:
133
- namespace = stream.readUInt16();
134
- value = stream.readUInt32();
135
- identifierType = node_opcua_nodeid_1.NodeIdType.NUMERIC;
136
- break;
137
- case 3 /* EnumNodeIdEncoding.String */:
138
- namespace = stream.readUInt16();
139
- value = (0, string_1.decodeString)(stream) || "";
140
- identifierType = node_opcua_nodeid_1.NodeIdType.STRING;
141
- break;
142
- case 5 /* EnumNodeIdEncoding.ByteString */:
143
- namespace = stream.readUInt16();
144
- value = (0, byte_string_1.decodeByteString)(stream);
145
- identifierType = node_opcua_nodeid_1.NodeIdType.BYTESTRING;
146
- break;
147
- default:
148
- // istanbul ignore next
149
- if (encodingByte !== 4 /* EnumNodeIdEncoding.Guid */) {
150
- throw new Error("decodeNodeId: unknown encoding_byte = 0x" + encodingByte.toString(16));
151
- }
152
- namespace = stream.readUInt16();
153
- value = (0, guid_1.decodeGuid)(stream);
154
- identifierType = node_opcua_nodeid_1.NodeIdType.GUID;
155
- (0, node_opcua_assert_1.assert)((0, guid_1.isValidGuid)(value));
156
- break;
157
- }
158
- if (_nodeId === undefined) {
159
- return new node_opcua_nodeid_1.NodeId(identifierType, value, namespace);
160
- }
161
- _nodeId.value = value;
162
- _nodeId.identifierType = identifierType;
163
- _nodeId.namespace = namespace || 0;
164
- return _nodeId;
165
- }
166
- function decodeNodeId(stream, _nodeId) {
167
- const encodingByte = stream.readUInt8();
168
- return _decodeNodeId(encodingByte, stream, _nodeId);
169
- }
170
- exports.decodeNodeId = decodeNodeId;
171
- function decodeExpandedNodeId(stream, _nodeId) {
172
- const encodingByte = stream.readUInt8();
173
- const expandedNodeId = _decodeNodeId(encodingByte, stream, _nodeId);
174
- expandedNodeId.namespaceUri = null;
175
- expandedNodeId.serverIndex = 0;
176
- if (encodingByte & 128 /* EnumNodeIdEncoding.NamespaceUriFlag */) {
177
- expandedNodeId.namespaceUri = (0, string_1.decodeString)(stream);
178
- }
179
- if (encodingByte & 64 /* EnumNodeIdEncoding.ServerIndexFlag */) {
180
- expandedNodeId.serverIndex = (0, integers_1.decodeUInt32)(stream);
181
- }
182
- const e = expandedNodeId;
183
- return new node_opcua_nodeid_1.ExpandedNodeId(e.identifierType, e.value, e.namespace, e.namespaceUri, e.serverIndex);
184
- }
185
- exports.decodeExpandedNodeId = decodeExpandedNodeId;
186
- var node_opcua_nodeid_2 = require("node-opcua-nodeid");
187
- Object.defineProperty(exports, "coerceNodeId", { enumerable: true, get: function () { return node_opcua_nodeid_2.coerceNodeId; } });
188
- Object.defineProperty(exports, "coerceExpandedNodeId", { enumerable: true, get: function () { return node_opcua_nodeid_2.coerceExpandedNodeId; } });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.coerceExpandedNodeId = exports.coerceNodeId = exports.decodeExpandedNodeId = exports.decodeNodeId = exports.encodeExpandedNodeId = exports.encodeNodeId = exports.randomNodeId = exports.isValidNodeId = void 0;
4
+ /***
5
+ * @module node-opcua-basic-types
6
+ */
7
+ const node_opcua_assert_1 = require("node-opcua-assert");
8
+ const node_opcua_nodeid_1 = require("node-opcua-nodeid");
9
+ const byte_string_1 = require("./byte_string");
10
+ const guid_1 = require("./guid");
11
+ const integers_1 = require("./integers");
12
+ const string_1 = require("./string");
13
+ const utils_1 = require("./utils");
14
+ function isUInt8(value) {
15
+ return value >= 0 && value <= 0xff;
16
+ }
17
+ function isUInt16(value) {
18
+ return value >= 0 && value <= 0xffff;
19
+ }
20
+ function nodeID_encodingByte(nodeId) {
21
+ let encodingByte = 0;
22
+ if (nodeId.identifierType === node_opcua_nodeid_1.NodeIdType.NUMERIC) {
23
+ if (isUInt8(nodeId.value) &&
24
+ !nodeId.namespace &&
25
+ !nodeId.namespaceUri &&
26
+ !nodeId.serverIndex) {
27
+ encodingByte = encodingByte | 0 /* EnumNodeIdEncoding.TwoBytes */;
28
+ }
29
+ else if (isUInt16(nodeId.value) &&
30
+ isUInt8(nodeId.namespace) &&
31
+ !nodeId.namespaceUri &&
32
+ !nodeId.serverIndex) {
33
+ encodingByte = encodingByte | 1 /* EnumNodeIdEncoding.FourBytes */;
34
+ }
35
+ else {
36
+ encodingByte = encodingByte | 2 /* EnumNodeIdEncoding.Numeric */;
37
+ }
38
+ }
39
+ else if (nodeId.identifierType === node_opcua_nodeid_1.NodeIdType.STRING) {
40
+ encodingByte = encodingByte | 3 /* EnumNodeIdEncoding.String */;
41
+ }
42
+ else if (nodeId.identifierType === node_opcua_nodeid_1.NodeIdType.BYTESTRING) {
43
+ encodingByte = encodingByte | 5 /* EnumNodeIdEncoding.ByteString */;
44
+ }
45
+ else if (nodeId.identifierType === node_opcua_nodeid_1.NodeIdType.GUID) {
46
+ encodingByte = encodingByte | 4 /* EnumNodeIdEncoding.Guid */;
47
+ }
48
+ if (Object.prototype.hasOwnProperty.call(nodeId, "namespaceUri") && nodeId.namespaceUri) {
49
+ encodingByte = encodingByte | 128 /* EnumNodeIdEncoding.NamespaceUriFlag */;
50
+ }
51
+ if (Object.prototype.hasOwnProperty.call(nodeId, "serverIndex") && nodeId.serverIndex) {
52
+ encodingByte = encodingByte | 64 /* EnumNodeIdEncoding.ServerIndexFlag */;
53
+ }
54
+ return encodingByte;
55
+ }
56
+ function isValidNodeId(nodeId) {
57
+ return nodeId instanceof node_opcua_nodeid_1.NodeId;
58
+ }
59
+ exports.isValidNodeId = isValidNodeId;
60
+ function randomNodeId() {
61
+ const value = (0, utils_1.getRandomInt)(0, 0xfffff);
62
+ const namespace = (0, utils_1.getRandomInt)(0, 3);
63
+ return (0, node_opcua_nodeid_1.makeNodeId)(value, namespace);
64
+ }
65
+ exports.randomNodeId = randomNodeId;
66
+ function _encodeNodeId(encodingByte, nodeId, stream) {
67
+ stream.writeUInt8(encodingByte); // encoding byte
68
+ /*jslint bitwise: true */
69
+ encodingByte &= 0x3f;
70
+ switch (encodingByte) {
71
+ case 0 /* EnumNodeIdEncoding.TwoBytes */:
72
+ stream.writeUInt8(nodeId ? nodeId.value : 0);
73
+ break;
74
+ case 1 /* EnumNodeIdEncoding.FourBytes */:
75
+ stream.writeUInt8(nodeId.namespace);
76
+ stream.writeUInt16(nodeId.value);
77
+ break;
78
+ case 2 /* EnumNodeIdEncoding.Numeric */:
79
+ stream.writeUInt16(nodeId.namespace);
80
+ stream.writeUInt32(nodeId.value);
81
+ break;
82
+ case 3 /* EnumNodeIdEncoding.String */:
83
+ stream.writeUInt16(nodeId.namespace);
84
+ (0, string_1.encodeString)(nodeId.value, stream);
85
+ break;
86
+ case 5 /* EnumNodeIdEncoding.ByteString */:
87
+ stream.writeUInt16(nodeId.namespace);
88
+ (0, byte_string_1.encodeByteString)(nodeId.value, stream);
89
+ break;
90
+ default:
91
+ (0, node_opcua_assert_1.assert)(encodingByte === 4 /* EnumNodeIdEncoding.Guid */);
92
+ stream.writeUInt16(nodeId.namespace);
93
+ (0, guid_1.encodeGuid)(nodeId.value, stream);
94
+ break;
95
+ }
96
+ }
97
+ function encodeNodeId(nodeId, stream) {
98
+ let encodingByte = nodeID_encodingByte(nodeId);
99
+ /*jslint bitwise: true */
100
+ encodingByte &= 0x3f;
101
+ _encodeNodeId(encodingByte, nodeId, stream);
102
+ }
103
+ exports.encodeNodeId = encodeNodeId;
104
+ function encodeExpandedNodeId(expandedNodeId, stream) {
105
+ (0, node_opcua_assert_1.assert)(expandedNodeId, "encodeExpandedNodeId: must provide a valid expandedNodeId");
106
+ const encodingByte = nodeID_encodingByte(expandedNodeId);
107
+ _encodeNodeId(encodingByte, expandedNodeId, stream);
108
+ if (encodingByte & 128 /* EnumNodeIdEncoding.NamespaceUriFlag */) {
109
+ (0, string_1.encodeString)(expandedNodeId.namespaceUri, stream);
110
+ }
111
+ if (encodingByte & 64 /* EnumNodeIdEncoding.ServerIndexFlag */) {
112
+ (0, integers_1.encodeUInt32)(expandedNodeId.serverIndex, stream);
113
+ }
114
+ }
115
+ exports.encodeExpandedNodeId = encodeExpandedNodeId;
116
+ function _decodeNodeId(encodingByte, stream, _nodeId) {
117
+ let value;
118
+ let namespace;
119
+ let identifierType;
120
+ /*jslint bitwise: true */
121
+ encodingByte &= 0x3f; // 1 to 5
122
+ switch (encodingByte) {
123
+ case 0 /* EnumNodeIdEncoding.TwoBytes */:
124
+ value = stream.readUInt8();
125
+ identifierType = node_opcua_nodeid_1.NodeIdType.NUMERIC;
126
+ break;
127
+ case 1 /* EnumNodeIdEncoding.FourBytes */:
128
+ namespace = stream.readUInt8();
129
+ value = stream.readUInt16();
130
+ identifierType = node_opcua_nodeid_1.NodeIdType.NUMERIC;
131
+ break;
132
+ case 2 /* EnumNodeIdEncoding.Numeric */:
133
+ namespace = stream.readUInt16();
134
+ value = stream.readUInt32();
135
+ identifierType = node_opcua_nodeid_1.NodeIdType.NUMERIC;
136
+ break;
137
+ case 3 /* EnumNodeIdEncoding.String */:
138
+ namespace = stream.readUInt16();
139
+ value = (0, string_1.decodeString)(stream) || "";
140
+ identifierType = node_opcua_nodeid_1.NodeIdType.STRING;
141
+ break;
142
+ case 5 /* EnumNodeIdEncoding.ByteString */:
143
+ namespace = stream.readUInt16();
144
+ value = (0, byte_string_1.decodeByteString)(stream);
145
+ identifierType = node_opcua_nodeid_1.NodeIdType.BYTESTRING;
146
+ break;
147
+ default:
148
+ // istanbul ignore next
149
+ if (encodingByte !== 4 /* EnumNodeIdEncoding.Guid */) {
150
+ throw new Error("decodeNodeId: unknown encoding_byte = 0x" + encodingByte.toString(16));
151
+ }
152
+ namespace = stream.readUInt16();
153
+ value = (0, guid_1.decodeGuid)(stream);
154
+ identifierType = node_opcua_nodeid_1.NodeIdType.GUID;
155
+ (0, node_opcua_assert_1.assert)((0, guid_1.isValidGuid)(value));
156
+ break;
157
+ }
158
+ if (_nodeId === undefined) {
159
+ return new node_opcua_nodeid_1.NodeId(identifierType, value, namespace);
160
+ }
161
+ _nodeId.value = value;
162
+ _nodeId.identifierType = identifierType;
163
+ _nodeId.namespace = namespace || 0;
164
+ return _nodeId;
165
+ }
166
+ function decodeNodeId(stream, _nodeId) {
167
+ const encodingByte = stream.readUInt8();
168
+ return _decodeNodeId(encodingByte, stream, _nodeId);
169
+ }
170
+ exports.decodeNodeId = decodeNodeId;
171
+ function decodeExpandedNodeId(stream, _nodeId) {
172
+ const encodingByte = stream.readUInt8();
173
+ const expandedNodeId = _decodeNodeId(encodingByte, stream, _nodeId);
174
+ expandedNodeId.namespaceUri = null;
175
+ expandedNodeId.serverIndex = 0;
176
+ if (encodingByte & 128 /* EnumNodeIdEncoding.NamespaceUriFlag */) {
177
+ expandedNodeId.namespaceUri = (0, string_1.decodeString)(stream);
178
+ }
179
+ if (encodingByte & 64 /* EnumNodeIdEncoding.ServerIndexFlag */) {
180
+ expandedNodeId.serverIndex = (0, integers_1.decodeUInt32)(stream);
181
+ }
182
+ const e = expandedNodeId;
183
+ return new node_opcua_nodeid_1.ExpandedNodeId(e.identifierType, e.value, e.namespace, e.namespaceUri, e.serverIndex);
184
+ }
185
+ exports.decodeExpandedNodeId = decodeExpandedNodeId;
186
+ var node_opcua_nodeid_2 = require("node-opcua-nodeid");
187
+ Object.defineProperty(exports, "coerceNodeId", { enumerable: true, get: function () { return node_opcua_nodeid_2.coerceNodeId; } });
188
+ Object.defineProperty(exports, "coerceExpandedNodeId", { enumerable: true, get: function () { return node_opcua_nodeid_2.coerceExpandedNodeId; } });
189
189
  //# sourceMappingURL=node_id.js.map
@@ -1 +1 @@
1
- export declare function roundToFloat2(float: number): number;
1
+ export declare function roundToFloat2(float: number): number;
@@ -1,27 +1,27 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.roundToFloat2 = void 0;
4
- function roundToFloat2(float) {
5
- if (float === 0) {
6
- return float;
7
- }
8
- // this method artificially rounds a float to 7 significant digit in base 10
9
- // Note:
10
- // this is to overcome the that that Javascript doesn't provide single precision float values (32 bits)
11
- // but only double precision float values
12
- // wikipedia:(http://en.wikipedia.org/wiki/Floating_point)
13
- //
14
- // * Single precision, usually used to represent the "float" type in the C language family
15
- // (though this is not guaranteed). This is a binary format that occupies 32 bits (4 bytes) and its
16
- // significand has a precision of 24 bits (about 7 decimal digits).
17
- // * Double precision, usually used to represent the "double" type in the C language family
18
- // (though this is not guaranteed). This is a binary format that occupies 64 bits (8 bytes) and its
19
- // significand has a precision of 53 bits (about 16 decimal digits).
20
- //
21
- const nbDigits = Math.ceil(Math.log(Math.abs(float)) / Math.log(10));
22
- const scale = Math.pow(10, -nbDigits + 2);
23
- return Math.round(float * scale) / scale;
24
- // return (float > 0 && r < 0) || (float < 0 && r > 0) ? -r : r;
25
- }
26
- exports.roundToFloat2 = roundToFloat2;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.roundToFloat2 = void 0;
4
+ function roundToFloat2(float) {
5
+ if (float === 0) {
6
+ return float;
7
+ }
8
+ // this method artificially rounds a float to 7 significant digit in base 10
9
+ // Note:
10
+ // this is to overcome the that that Javascript doesn't provide single precision float values (32 bits)
11
+ // but only double precision float values
12
+ // wikipedia:(http://en.wikipedia.org/wiki/Floating_point)
13
+ //
14
+ // * Single precision, usually used to represent the "float" type in the C language family
15
+ // (though this is not guaranteed). This is a binary format that occupies 32 bits (4 bytes) and its
16
+ // significand has a precision of 24 bits (about 7 decimal digits).
17
+ // * Double precision, usually used to represent the "double" type in the C language family
18
+ // (though this is not guaranteed). This is a binary format that occupies 64 bits (8 bytes) and its
19
+ // significand has a precision of 53 bits (about 16 decimal digits).
20
+ //
21
+ const nbDigits = Math.ceil(Math.log(Math.abs(float)) / Math.log(10));
22
+ const scale = Math.pow(10, -nbDigits + 2);
23
+ return Math.round(float * scale) / scale;
24
+ // return (float > 0 && r < 0) || (float < 0 && r > 0) ? -r : r;
25
+ }
26
+ exports.roundToFloat2 = roundToFloat2;
27
27
  //# sourceMappingURL=round_to_float.js.map
@@ -1,4 +1,4 @@
1
- /***
2
- * @module node-opcua-basic-types
3
- */
4
- export * from "node-opcua-status-code";
1
+ /***
2
+ * @module node-opcua-basic-types
3
+ */
4
+ export * from "node-opcua-status-code";
@@ -1,21 +1,21 @@
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
- /***
18
- * @module node-opcua-basic-types
19
- */
20
- __exportStar(require("node-opcua-status-code"), exports);
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
+ /***
18
+ * @module node-opcua-basic-types
19
+ */
20
+ __exportStar(require("node-opcua-status-code"), exports);
21
21
  //# sourceMappingURL=status_code.js.map
package/dist/string.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- /***
2
- * @module node-opcua-basic-types
3
- */
4
- import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream";
5
- export declare function isValidString(value: unknown): boolean;
6
- export declare function randomString(): string;
7
- export declare function decodeString(stream: BinaryStream, value?: string | null): string | null;
8
- export declare function encodeString(value: null | string, stream: OutputBinaryStream): void;
9
- export type CharArray = string;
10
- export type UAString = string | null;
11
- export declare const decodeUAString: typeof decodeString;
12
- export declare const encodeUAString: typeof encodeString;
1
+ /***
2
+ * @module node-opcua-basic-types
3
+ */
4
+ import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream";
5
+ export declare function isValidString(value: unknown): boolean;
6
+ export declare function randomString(): string;
7
+ export declare function decodeString(stream: BinaryStream, value?: string | null): string | null;
8
+ export declare function encodeString(value: null | string, stream: OutputBinaryStream): void;
9
+ export type CharArray = string;
10
+ export type UAString = string | null;
11
+ export declare const decodeUAString: typeof decodeString;
12
+ export declare const encodeUAString: typeof encodeString;
package/dist/string.js CHANGED
@@ -1,31 +1,31 @@
1
- "use strict";
2
- /***
3
- * @module node-opcua-basic-types
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.encodeUAString = exports.decodeUAString = exports.encodeString = exports.decodeString = exports.randomString = exports.isValidString = void 0;
7
- const utils_1 = require("./utils");
8
- function isValidString(value) {
9
- return typeof value === "string";
10
- }
11
- exports.isValidString = isValidString;
12
- function randomString() {
13
- const nbCar = (0, utils_1.getRandomInt)(1, 20);
14
- const cars = [];
15
- for (let i = 0; i < nbCar; i++) {
16
- cars.push(String.fromCharCode(65 + (0, utils_1.getRandomInt)(0, 26)));
17
- }
18
- return cars.join("");
19
- }
20
- exports.randomString = randomString;
21
- function decodeString(stream, value) {
22
- return stream.readString();
23
- }
24
- exports.decodeString = decodeString;
25
- function encodeString(value, stream) {
26
- stream.writeString(value);
27
- }
28
- exports.encodeString = encodeString;
29
- exports.decodeUAString = decodeString;
30
- exports.encodeUAString = encodeString;
1
+ "use strict";
2
+ /***
3
+ * @module node-opcua-basic-types
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.encodeUAString = exports.decodeUAString = exports.encodeString = exports.decodeString = exports.randomString = exports.isValidString = void 0;
7
+ const utils_1 = require("./utils");
8
+ function isValidString(value) {
9
+ return typeof value === "string";
10
+ }
11
+ exports.isValidString = isValidString;
12
+ function randomString() {
13
+ const nbCar = (0, utils_1.getRandomInt)(1, 20);
14
+ const cars = [];
15
+ for (let i = 0; i < nbCar; i++) {
16
+ cars.push(String.fromCharCode(65 + (0, utils_1.getRandomInt)(0, 26)));
17
+ }
18
+ return cars.join("");
19
+ }
20
+ exports.randomString = randomString;
21
+ function decodeString(stream, value) {
22
+ return stream.readString();
23
+ }
24
+ exports.decodeString = decodeString;
25
+ function encodeString(value, stream) {
26
+ stream.writeString(value);
27
+ }
28
+ exports.encodeString = encodeString;
29
+ exports.decodeUAString = decodeString;
30
+ exports.encodeUAString = encodeString;
31
31
  //# sourceMappingURL=string.js.map
package/dist/utils.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- /***
2
- * @module node-opcua-basic-types
3
- */
4
- /**
5
- * return a random integer value in the range of min inclusive and max exclusive
6
- * @method getRandomInt
7
- * @param min
8
- * @param max
9
- * @return {*}
10
- * @private
11
- */
12
- export declare function getRandomInt(min: number, max: number): number;
1
+ /***
2
+ * @module node-opcua-basic-types
3
+ */
4
+ /**
5
+ * return a random integer value in the range of min inclusive and max exclusive
6
+ * @method getRandomInt
7
+ * @param min
8
+ * @param max
9
+ * @return {*}
10
+ * @private
11
+ */
12
+ export declare function getRandomInt(min: number, max: number): number;