node-opcua-enum 2.64.0 → 2.64.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/enum.d.ts CHANGED
@@ -1,74 +1,74 @@
1
- /**
2
- * @module node-opcua-enum
3
- *
4
- */
5
- /**
6
- * Represents an Item of an Enum.
7
- *
8
- * @class Enum
9
- */
10
- export declare class EnumItem {
11
- key: string;
12
- value: number;
13
- /**
14
- *
15
- * @param key the enum key
16
- * @param value the enum value
17
- */
18
- constructor(key: string, value: number);
19
- /**
20
- * Checks if the EnumItem is the same as the passing object.
21
- * @method is
22
- * @param {EnumItem | String | Number} item The object to check with.
23
- * @return {Boolean} The check result.
24
- */
25
- is(item: EnumItem | string | number): boolean;
26
- /**
27
- * Checks if the flagged EnumItem has the passing object.
28
- * @method has
29
- * @param {EnumItem | String |Number} value The object to check with.
30
- * @return {Boolean} The check result.
31
- */
32
- has(value: string | number | EnumItem): boolean;
33
- /**
34
- * Returns String representation of this EnumItem.
35
- * @method toString
36
- * @return {String} String representation of this EnumItem.
37
- */
38
- toString(): string;
39
- /**
40
- * Returns JSON object representation of this EnumItem.
41
- * @method toJSON
42
- * @return {String} JSON object representation of this EnumItem.
43
- */
44
- toJSON(): any;
45
- /**
46
- * Returns the value to compare with.
47
- * @method valueOf
48
- * @return {String} The value to compare with.
49
- */
50
- valueOf(): number;
51
- }
52
- /**
53
- * @class Enum
54
- * @constructor
55
- * Represents an Enum with enum items.
56
- * @param {Array || Object} map This are the enum items.
57
- */
58
- export declare class Enum {
59
- private readonly enumItems;
60
- private readonly _isFlaggable;
61
- constructor(map: any);
62
- get isFlaggable(): boolean;
63
- /**
64
- * Returns the appropriate EnumItem.
65
- * @method get
66
- * @param key The object to get with.
67
- * @return the get result.
68
- */
69
- get(key: EnumItem | string | number): (EnumItem | null);
70
- getDefaultValue(): EnumItem;
71
- toString(): string;
72
- private _getByString;
73
- private _getByNum;
74
- }
1
+ /**
2
+ * @module node-opcua-enum
3
+ *
4
+ */
5
+ /**
6
+ * Represents an Item of an Enum.
7
+ *
8
+ * @class Enum
9
+ */
10
+ export declare class EnumItem {
11
+ key: string;
12
+ value: number;
13
+ /**
14
+ *
15
+ * @param key the enum key
16
+ * @param value the enum value
17
+ */
18
+ constructor(key: string, value: number);
19
+ /**
20
+ * Checks if the EnumItem is the same as the passing object.
21
+ * @method is
22
+ * @param {EnumItem | String | Number} item The object to check with.
23
+ * @return {Boolean} The check result.
24
+ */
25
+ is(item: EnumItem | string | number): boolean;
26
+ /**
27
+ * Checks if the flagged EnumItem has the passing object.
28
+ * @method has
29
+ * @param {EnumItem | String |Number} value The object to check with.
30
+ * @return {Boolean} The check result.
31
+ */
32
+ has(value: string | number | EnumItem): boolean;
33
+ /**
34
+ * Returns String representation of this EnumItem.
35
+ * @method toString
36
+ * @return {String} String representation of this EnumItem.
37
+ */
38
+ toString(): string;
39
+ /**
40
+ * Returns JSON object representation of this EnumItem.
41
+ * @method toJSON
42
+ * @return {String} JSON object representation of this EnumItem.
43
+ */
44
+ toJSON(): any;
45
+ /**
46
+ * Returns the value to compare with.
47
+ * @method valueOf
48
+ * @return {String} The value to compare with.
49
+ */
50
+ valueOf(): number;
51
+ }
52
+ /**
53
+ * @class Enum
54
+ * @constructor
55
+ * Represents an Enum with enum items.
56
+ * @param {Array || Object} map This are the enum items.
57
+ */
58
+ export declare class Enum {
59
+ private readonly enumItems;
60
+ private readonly _isFlaggable;
61
+ constructor(map: any);
62
+ get isFlaggable(): boolean;
63
+ /**
64
+ * Returns the appropriate EnumItem.
65
+ * @method get
66
+ * @param key The object to get with.
67
+ * @return the get result.
68
+ */
69
+ get(key: EnumItem | string | number): (EnumItem | null);
70
+ getDefaultValue(): EnumItem;
71
+ toString(): string;
72
+ private _getByString;
73
+ private _getByNum;
74
+ }
package/dist/enum.js CHANGED
@@ -1,232 +1,232 @@
1
- "use strict";
2
- /**
3
- * @module node-opcua-enum
4
- *
5
- */
6
- // tslint:disable:no-bitwise
7
- // tslint:disable:max-classes-per-file
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.Enum = exports.EnumItem = void 0;
10
- /**
11
- * Represents an Item of an Enum.
12
- *
13
- * @class Enum
14
- */
15
- class EnumItem {
16
- /**
17
- *
18
- * @param key the enum key
19
- * @param value the enum value
20
- */
21
- constructor(key, value) {
22
- this.key = key;
23
- this.value = value;
24
- }
25
- /**
26
- * Checks if the EnumItem is the same as the passing object.
27
- * @method is
28
- * @param {EnumItem | String | Number} item The object to check with.
29
- * @return {Boolean} The check result.
30
- */
31
- is(item) {
32
- if (item instanceof EnumItem) {
33
- return this.value === item.value;
34
- }
35
- else if (typeof item === "string") {
36
- return this.key === item;
37
- }
38
- else {
39
- return this.value === item;
40
- }
41
- }
42
- /**
43
- * Checks if the flagged EnumItem has the passing object.
44
- * @method has
45
- * @param {EnumItem | String |Number} value The object to check with.
46
- * @return {Boolean} The check result.
47
- */
48
- has(value) {
49
- if (value instanceof EnumItem) {
50
- return (value.value & this.value) !== 0;
51
- }
52
- else if (typeof value === "string") {
53
- return this.key.indexOf(value) >= 0;
54
- }
55
- else {
56
- return (value & this.value) !== 0;
57
- }
58
- }
59
- /**
60
- * Returns String representation of this EnumItem.
61
- * @method toString
62
- * @return {String} String representation of this EnumItem.
63
- */
64
- toString() {
65
- return this.key;
66
- }
67
- /**
68
- * Returns JSON object representation of this EnumItem.
69
- * @method toJSON
70
- * @return {String} JSON object representation of this EnumItem.
71
- */
72
- toJSON() {
73
- return this.key;
74
- }
75
- /**
76
- * Returns the value to compare with.
77
- * @method valueOf
78
- * @return {String} The value to compare with.
79
- */
80
- valueOf() {
81
- return this.value;
82
- }
83
- }
84
- exports.EnumItem = EnumItem;
85
- function powerOfTwo(n) {
86
- return n && (!(n & (n - 1))) ? true : false;
87
- }
88
- // check if enum is flaggable
89
- function checkIsFlaggable(enums) {
90
- for (const e of enums) {
91
- const value = +e.value;
92
- if (isNaN(value)) {
93
- continue; // skipping none number value
94
- }
95
- if ((value !== 0 && value !== 1) && !powerOfTwo(value)) {
96
- return false;
97
- }
98
- }
99
- return true;
100
- }
101
- /**
102
- * @class Enum
103
- * @constructor
104
- * Represents an Enum with enum items.
105
- * @param {Array || Object} map This are the enum items.
106
- */
107
- class Enum {
108
- constructor(map) {
109
- this.enumItems = [];
110
- let mm = null;
111
- let isFlaggable = null;
112
- if (Array.isArray(map)) {
113
- // create map as flaggable enum
114
- mm = {};
115
- for (let i = 0; i < map.length; i++) {
116
- mm[map[i]] = 1 << i;
117
- }
118
- isFlaggable = true;
119
- }
120
- else {
121
- mm = map;
122
- }
123
- for (const key of Object.keys(mm)) {
124
- const val = mm[key];
125
- if (undefined === val) {
126
- continue;
127
- }
128
- const kv = new EnumItem(key, val);
129
- const pThis = this;
130
- pThis[key] = kv;
131
- pThis[val] = kv;
132
- this.enumItems.push(kv);
133
- }
134
- if (!isFlaggable) {
135
- isFlaggable = checkIsFlaggable(this.enumItems);
136
- }
137
- this._isFlaggable = isFlaggable;
138
- }
139
- get isFlaggable() {
140
- return this._isFlaggable;
141
- }
142
- /**
143
- * Returns the appropriate EnumItem.
144
- * @method get
145
- * @param key The object to get with.
146
- * @return the get result.
147
- */
148
- get(key) {
149
- const pThis = this;
150
- if (key instanceof EnumItem) {
151
- if (!pThis[key.key]) {
152
- throw new Error("Invalid key");
153
- }
154
- return key;
155
- }
156
- if (key === null || key === undefined) {
157
- return null;
158
- }
159
- const prop = pThis[key];
160
- if (prop) {
161
- return prop;
162
- }
163
- else if (this._isFlaggable) {
164
- if (typeof key === "string") {
165
- return this._getByString(key);
166
- }
167
- else if (typeof key === "number") {
168
- return this._getByNum(key);
169
- }
170
- }
171
- return null;
172
- }
173
- getDefaultValue() {
174
- return this.enumItems[0];
175
- }
176
- toString() {
177
- return this.enumItems.join(" , ");
178
- }
179
- _getByString(key) {
180
- const pThis = this;
181
- const parts = key.split(" | ");
182
- let val = 0;
183
- for (const part of parts) {
184
- const item = pThis[part];
185
- if (undefined === item) {
186
- return null;
187
- }
188
- val |= item.value;
189
- }
190
- const kv = new EnumItem(key, val);
191
- // add in cache for later
192
- let prop = pThis[val];
193
- if (prop === undefined) {
194
- pThis[val] = kv;
195
- }
196
- prop = pThis[key];
197
- if (prop === undefined) {
198
- pThis[key] = kv;
199
- }
200
- return kv;
201
- }
202
- _getByNum(key) {
203
- if (key === 0) {
204
- return null;
205
- }
206
- const pThis = this;
207
- let name;
208
- let c = 1;
209
- for (let i = 0; c < key; i++) {
210
- if ((c & key) === c) {
211
- const item = pThis[c];
212
- if (undefined === item) {
213
- return null;
214
- }
215
- if (name) {
216
- name = name + " | " + item.key;
217
- }
218
- else {
219
- name = item.key;
220
- }
221
- }
222
- c *= 2;
223
- }
224
- const kv = new EnumItem(name, key);
225
- // add in cache for later
226
- pThis[name] = kv;
227
- pThis[key] = kv;
228
- return kv;
229
- }
230
- }
231
- exports.Enum = Enum;
1
+ "use strict";
2
+ /**
3
+ * @module node-opcua-enum
4
+ *
5
+ */
6
+ // tslint:disable:no-bitwise
7
+ // tslint:disable:max-classes-per-file
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.Enum = exports.EnumItem = void 0;
10
+ /**
11
+ * Represents an Item of an Enum.
12
+ *
13
+ * @class Enum
14
+ */
15
+ class EnumItem {
16
+ /**
17
+ *
18
+ * @param key the enum key
19
+ * @param value the enum value
20
+ */
21
+ constructor(key, value) {
22
+ this.key = key;
23
+ this.value = value;
24
+ }
25
+ /**
26
+ * Checks if the EnumItem is the same as the passing object.
27
+ * @method is
28
+ * @param {EnumItem | String | Number} item The object to check with.
29
+ * @return {Boolean} The check result.
30
+ */
31
+ is(item) {
32
+ if (item instanceof EnumItem) {
33
+ return this.value === item.value;
34
+ }
35
+ else if (typeof item === "string") {
36
+ return this.key === item;
37
+ }
38
+ else {
39
+ return this.value === item;
40
+ }
41
+ }
42
+ /**
43
+ * Checks if the flagged EnumItem has the passing object.
44
+ * @method has
45
+ * @param {EnumItem | String |Number} value The object to check with.
46
+ * @return {Boolean} The check result.
47
+ */
48
+ has(value) {
49
+ if (value instanceof EnumItem) {
50
+ return (value.value & this.value) !== 0;
51
+ }
52
+ else if (typeof value === "string") {
53
+ return this.key.indexOf(value) >= 0;
54
+ }
55
+ else {
56
+ return (value & this.value) !== 0;
57
+ }
58
+ }
59
+ /**
60
+ * Returns String representation of this EnumItem.
61
+ * @method toString
62
+ * @return {String} String representation of this EnumItem.
63
+ */
64
+ toString() {
65
+ return this.key;
66
+ }
67
+ /**
68
+ * Returns JSON object representation of this EnumItem.
69
+ * @method toJSON
70
+ * @return {String} JSON object representation of this EnumItem.
71
+ */
72
+ toJSON() {
73
+ return this.key;
74
+ }
75
+ /**
76
+ * Returns the value to compare with.
77
+ * @method valueOf
78
+ * @return {String} The value to compare with.
79
+ */
80
+ valueOf() {
81
+ return this.value;
82
+ }
83
+ }
84
+ exports.EnumItem = EnumItem;
85
+ function powerOfTwo(n) {
86
+ return n && (!(n & (n - 1))) ? true : false;
87
+ }
88
+ // check if enum is flaggable
89
+ function checkIsFlaggable(enums) {
90
+ for (const e of enums) {
91
+ const value = +e.value;
92
+ if (isNaN(value)) {
93
+ continue; // skipping none number value
94
+ }
95
+ if ((value !== 0 && value !== 1) && !powerOfTwo(value)) {
96
+ return false;
97
+ }
98
+ }
99
+ return true;
100
+ }
101
+ /**
102
+ * @class Enum
103
+ * @constructor
104
+ * Represents an Enum with enum items.
105
+ * @param {Array || Object} map This are the enum items.
106
+ */
107
+ class Enum {
108
+ constructor(map) {
109
+ this.enumItems = [];
110
+ let mm = null;
111
+ let isFlaggable = null;
112
+ if (Array.isArray(map)) {
113
+ // create map as flaggable enum
114
+ mm = {};
115
+ for (let i = 0; i < map.length; i++) {
116
+ mm[map[i]] = 1 << i;
117
+ }
118
+ isFlaggable = true;
119
+ }
120
+ else {
121
+ mm = map;
122
+ }
123
+ for (const key of Object.keys(mm)) {
124
+ const val = mm[key];
125
+ if (undefined === val) {
126
+ continue;
127
+ }
128
+ const kv = new EnumItem(key, val);
129
+ const pThis = this;
130
+ pThis[key] = kv;
131
+ pThis[val] = kv;
132
+ this.enumItems.push(kv);
133
+ }
134
+ if (!isFlaggable) {
135
+ isFlaggable = checkIsFlaggable(this.enumItems);
136
+ }
137
+ this._isFlaggable = isFlaggable;
138
+ }
139
+ get isFlaggable() {
140
+ return this._isFlaggable;
141
+ }
142
+ /**
143
+ * Returns the appropriate EnumItem.
144
+ * @method get
145
+ * @param key The object to get with.
146
+ * @return the get result.
147
+ */
148
+ get(key) {
149
+ const pThis = this;
150
+ if (key instanceof EnumItem) {
151
+ if (!pThis[key.key]) {
152
+ throw new Error("Invalid key");
153
+ }
154
+ return key;
155
+ }
156
+ if (key === null || key === undefined) {
157
+ return null;
158
+ }
159
+ const prop = pThis[key];
160
+ if (prop) {
161
+ return prop;
162
+ }
163
+ else if (this._isFlaggable) {
164
+ if (typeof key === "string") {
165
+ return this._getByString(key);
166
+ }
167
+ else if (typeof key === "number") {
168
+ return this._getByNum(key);
169
+ }
170
+ }
171
+ return null;
172
+ }
173
+ getDefaultValue() {
174
+ return this.enumItems[0];
175
+ }
176
+ toString() {
177
+ return this.enumItems.join(" , ");
178
+ }
179
+ _getByString(key) {
180
+ const pThis = this;
181
+ const parts = key.split(" | ");
182
+ let val = 0;
183
+ for (const part of parts) {
184
+ const item = pThis[part];
185
+ if (undefined === item) {
186
+ return null;
187
+ }
188
+ val |= item.value;
189
+ }
190
+ const kv = new EnumItem(key, val);
191
+ // add in cache for later
192
+ let prop = pThis[val];
193
+ if (prop === undefined) {
194
+ pThis[val] = kv;
195
+ }
196
+ prop = pThis[key];
197
+ if (prop === undefined) {
198
+ pThis[key] = kv;
199
+ }
200
+ return kv;
201
+ }
202
+ _getByNum(key) {
203
+ if (key === 0) {
204
+ return null;
205
+ }
206
+ const pThis = this;
207
+ let name;
208
+ let c = 1;
209
+ for (let i = 0; c < key; i++) {
210
+ if ((c & key) === c) {
211
+ const item = pThis[c];
212
+ if (undefined === item) {
213
+ return null;
214
+ }
215
+ if (name) {
216
+ name = name + " | " + item.key;
217
+ }
218
+ else {
219
+ name = item.key;
220
+ }
221
+ }
222
+ c *= 2;
223
+ }
224
+ const kv = new EnumItem(name, key);
225
+ // add in cache for later
226
+ pThis[name] = kv;
227
+ pThis[key] = kv;
228
+ return kv;
229
+ }
230
+ }
231
+ exports.Enum = Enum;
232
232
  //# sourceMappingURL=enum.js.map
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- /**
2
- * @module node-opcua-enum
3
- *
4
- */
5
- export * from "./enum";
1
+ /**
2
+ * @module node-opcua-enum
3
+ *
4
+ */
5
+ export * from "./enum";
package/dist/index.js CHANGED
@@ -1,18 +1,18 @@
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" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- /**
14
- * @module node-opcua-enum
15
- *
16
- */
17
- __exportStar(require("./enum"), exports);
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" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ /**
14
+ * @module node-opcua-enum
15
+ *
16
+ */
17
+ __exportStar(require("./enum"), exports);
18
18
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,37 +1,37 @@
1
1
  {
2
- "name": "node-opcua-enum",
3
- "version": "2.64.0",
4
- "description": "pure nodejs OPCUA SDK - module -enum",
5
- "main": "./dist/index.js",
6
- "@types": "./dist/index.d.ts",
7
- "dependencies": {
8
- "node-opcua-assert": "2.64.0"
9
- },
10
- "devDependencies": {
11
- "enum": "3.0.4",
12
- "node-opcua-benchmarker": "2.64.0",
13
- "should": "^13.2.3"
14
- },
15
- "author": "Etienne Rossignon",
16
- "license": "MIT",
17
- "repository": {
18
- "type": "git",
19
- "url": "git://github.com/node-opcua/node-opcua.git"
20
- },
21
- "keywords": [
22
- "OPCUA",
23
- "opcua",
24
- "m2m",
25
- "iot",
26
- "opc ua",
27
- "internet of things"
28
- ],
29
- "homepage": "http://node-opcua.github.io/",
30
- "gitHead": "e4d73afdfcccb3491423149d9b9785888f4ebb3c",
31
- "scripts": {
32
- "build": "tsc -b",
33
- "lint": "eslint source/**/*.ts",
34
- "clean": "node -e \"require('rimraf').sync('dist');\"",
35
- "test": "mocha"
36
- }
37
- }
2
+ "name": "node-opcua-enum",
3
+ "version": "2.64.1",
4
+ "description": "pure nodejs OPCUA SDK - module -enum",
5
+ "scripts": {
6
+ "build": "tsc -b",
7
+ "lint": "eslint source/**/*.ts",
8
+ "clean": "node -e \"require('rimraf').sync('dist');\"",
9
+ "test": "mocha"
10
+ },
11
+ "main": "./dist/index.js",
12
+ "@types": "./dist/index.d.ts",
13
+ "dependencies": {
14
+ "node-opcua-assert": "2.64.1"
15
+ },
16
+ "devDependencies": {
17
+ "enum": "3.0.4",
18
+ "node-opcua-benchmarker": "2.64.1",
19
+ "should": "^13.2.3"
20
+ },
21
+ "author": "Etienne Rossignon",
22
+ "license": "MIT",
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git://github.com/node-opcua/node-opcua.git"
26
+ },
27
+ "keywords": [
28
+ "OPCUA",
29
+ "opcua",
30
+ "m2m",
31
+ "iot",
32
+ "opc ua",
33
+ "internet of things"
34
+ ],
35
+ "homepage": "http://node-opcua.github.io/",
36
+ "gitHead": "b65b8738603cd475d7d99a2b20b0ae9d32b4110c"
37
+ }