node-opcua-enum 2.76.0 → 2.76.2
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 +78 -78
- package/dist/enum.js +243 -243
- package/dist/index.d.ts +5 -5
- package/dist/index.js +21 -21
- package/package.json +3 -3
package/dist/enum.d.ts
CHANGED
|
@@ -1,78 +1,78 @@
|
|
|
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
|
-
export interface _TypescriptEnum {
|
|
53
|
-
[key: string | number]: number | string;
|
|
54
|
-
}
|
|
55
|
-
export declare function adaptTypescriptEnum(map: _TypescriptEnum | string[]): _TypescriptEnum;
|
|
56
|
-
/**
|
|
57
|
-
* @class Enum
|
|
58
|
-
* @constructor
|
|
59
|
-
* Represents an Enum with enum items.
|
|
60
|
-
* @param {Array || Object} map This are the enum items.
|
|
61
|
-
*/
|
|
62
|
-
export declare class Enum {
|
|
63
|
-
private readonly enumItems;
|
|
64
|
-
private readonly _isFlaggable;
|
|
65
|
-
constructor(map: _TypescriptEnum | string[]);
|
|
66
|
-
get isFlaggable(): boolean;
|
|
67
|
-
/**
|
|
68
|
-
* Returns the appropriate EnumItem.
|
|
69
|
-
* @method get
|
|
70
|
-
* @param key The object to get with.
|
|
71
|
-
* @return the get result.
|
|
72
|
-
*/
|
|
73
|
-
get(key: EnumItem | string | number): EnumItem | null;
|
|
74
|
-
getDefaultValue(): EnumItem;
|
|
75
|
-
toString(): string;
|
|
76
|
-
private _getByString;
|
|
77
|
-
private _getByNum;
|
|
78
|
-
}
|
|
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
|
+
export interface _TypescriptEnum {
|
|
53
|
+
[key: string | number]: number | string;
|
|
54
|
+
}
|
|
55
|
+
export declare function adaptTypescriptEnum(map: _TypescriptEnum | string[]): _TypescriptEnum;
|
|
56
|
+
/**
|
|
57
|
+
* @class Enum
|
|
58
|
+
* @constructor
|
|
59
|
+
* Represents an Enum with enum items.
|
|
60
|
+
* @param {Array || Object} map This are the enum items.
|
|
61
|
+
*/
|
|
62
|
+
export declare class Enum {
|
|
63
|
+
private readonly enumItems;
|
|
64
|
+
private readonly _isFlaggable;
|
|
65
|
+
constructor(map: _TypescriptEnum | string[]);
|
|
66
|
+
get isFlaggable(): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Returns the appropriate EnumItem.
|
|
69
|
+
* @method get
|
|
70
|
+
* @param key The object to get with.
|
|
71
|
+
* @return the get result.
|
|
72
|
+
*/
|
|
73
|
+
get(key: EnumItem | string | number): EnumItem | null;
|
|
74
|
+
getDefaultValue(): EnumItem;
|
|
75
|
+
toString(): string;
|
|
76
|
+
private _getByString;
|
|
77
|
+
private _getByNum;
|
|
78
|
+
}
|
package/dist/enum.js
CHANGED
|
@@ -1,244 +1,244 @@
|
|
|
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.adaptTypescriptEnum = 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
|
-
function adaptTypescriptEnum(map) {
|
|
102
|
-
if (Array.isArray(map)) {
|
|
103
|
-
let mm = null;
|
|
104
|
-
// create map as flaggable enum
|
|
105
|
-
mm = {};
|
|
106
|
-
for (let i = 0; i < map.length; i++) {
|
|
107
|
-
mm[map[i]] = 1 << i;
|
|
108
|
-
}
|
|
109
|
-
return mm;
|
|
110
|
-
}
|
|
111
|
-
return map;
|
|
112
|
-
}
|
|
113
|
-
exports.adaptTypescriptEnum = adaptTypescriptEnum;
|
|
114
|
-
/**
|
|
115
|
-
* @class Enum
|
|
116
|
-
* @constructor
|
|
117
|
-
* Represents an Enum with enum items.
|
|
118
|
-
* @param {Array || Object} map This are the enum items.
|
|
119
|
-
*/
|
|
120
|
-
class Enum {
|
|
121
|
-
constructor(map) {
|
|
122
|
-
this.enumItems = [];
|
|
123
|
-
let mm = null;
|
|
124
|
-
let isFlaggable = null;
|
|
125
|
-
if (Array.isArray(map)) {
|
|
126
|
-
mm = adaptTypescriptEnum(map);
|
|
127
|
-
isFlaggable = true;
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
mm = map;
|
|
131
|
-
}
|
|
132
|
-
for (const key of Object.keys(mm)) {
|
|
133
|
-
if (typeof key !== "string") {
|
|
134
|
-
continue;
|
|
135
|
-
}
|
|
136
|
-
const val = mm[key];
|
|
137
|
-
if (undefined === val) {
|
|
138
|
-
continue;
|
|
139
|
-
}
|
|
140
|
-
const kv = new EnumItem(key, val);
|
|
141
|
-
const pThis = this;
|
|
142
|
-
pThis[key] = kv;
|
|
143
|
-
pThis[val] = kv;
|
|
144
|
-
this.enumItems.push(kv);
|
|
145
|
-
}
|
|
146
|
-
if (!isFlaggable) {
|
|
147
|
-
isFlaggable = checkIsFlaggable(this.enumItems);
|
|
148
|
-
}
|
|
149
|
-
this._isFlaggable = isFlaggable;
|
|
150
|
-
}
|
|
151
|
-
get isFlaggable() {
|
|
152
|
-
return this._isFlaggable;
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Returns the appropriate EnumItem.
|
|
156
|
-
* @method get
|
|
157
|
-
* @param key The object to get with.
|
|
158
|
-
* @return the get result.
|
|
159
|
-
*/
|
|
160
|
-
get(key) {
|
|
161
|
-
const pThis = this;
|
|
162
|
-
if (key instanceof EnumItem) {
|
|
163
|
-
if (!pThis[key.key]) {
|
|
164
|
-
throw new Error("Invalid key");
|
|
165
|
-
}
|
|
166
|
-
return key;
|
|
167
|
-
}
|
|
168
|
-
if (key === null || key === undefined) {
|
|
169
|
-
return null;
|
|
170
|
-
}
|
|
171
|
-
const prop = pThis[key];
|
|
172
|
-
if (prop) {
|
|
173
|
-
return prop;
|
|
174
|
-
}
|
|
175
|
-
else if (this._isFlaggable) {
|
|
176
|
-
if (typeof key === "string") {
|
|
177
|
-
return this._getByString(key);
|
|
178
|
-
}
|
|
179
|
-
else if (typeof key === "number") {
|
|
180
|
-
return this._getByNum(key);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
return null;
|
|
184
|
-
}
|
|
185
|
-
getDefaultValue() {
|
|
186
|
-
return this.enumItems[0];
|
|
187
|
-
}
|
|
188
|
-
toString() {
|
|
189
|
-
return this.enumItems.join(" , ");
|
|
190
|
-
}
|
|
191
|
-
_getByString(key) {
|
|
192
|
-
const pThis = this;
|
|
193
|
-
const parts = key.split(" | ");
|
|
194
|
-
let val = 0;
|
|
195
|
-
for (const part of parts) {
|
|
196
|
-
const item = pThis[part];
|
|
197
|
-
if (undefined === item) {
|
|
198
|
-
return null;
|
|
199
|
-
}
|
|
200
|
-
val |= item.value;
|
|
201
|
-
}
|
|
202
|
-
const kv = new EnumItem(key, val);
|
|
203
|
-
// add in cache for later
|
|
204
|
-
let prop = pThis[val];
|
|
205
|
-
if (prop === undefined) {
|
|
206
|
-
pThis[val] = kv;
|
|
207
|
-
}
|
|
208
|
-
prop = pThis[key];
|
|
209
|
-
if (prop === undefined) {
|
|
210
|
-
pThis[key] = kv;
|
|
211
|
-
}
|
|
212
|
-
return kv;
|
|
213
|
-
}
|
|
214
|
-
_getByNum(key) {
|
|
215
|
-
if (key === 0) {
|
|
216
|
-
return null;
|
|
217
|
-
}
|
|
218
|
-
const pThis = this;
|
|
219
|
-
let name;
|
|
220
|
-
let c = 1;
|
|
221
|
-
for (let i = 0; c < key; i++) {
|
|
222
|
-
if ((c & key) === c) {
|
|
223
|
-
const item = pThis[c];
|
|
224
|
-
if (undefined === item) {
|
|
225
|
-
return null;
|
|
226
|
-
}
|
|
227
|
-
if (name) {
|
|
228
|
-
name = name + " | " + item.key;
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
name = item.key;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
c *= 2;
|
|
235
|
-
}
|
|
236
|
-
const kv = new EnumItem(name, key);
|
|
237
|
-
// add in cache for later
|
|
238
|
-
pThis[name] = kv;
|
|
239
|
-
pThis[key] = kv;
|
|
240
|
-
return kv;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
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.adaptTypescriptEnum = 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
|
+
function adaptTypescriptEnum(map) {
|
|
102
|
+
if (Array.isArray(map)) {
|
|
103
|
+
let mm = null;
|
|
104
|
+
// create map as flaggable enum
|
|
105
|
+
mm = {};
|
|
106
|
+
for (let i = 0; i < map.length; i++) {
|
|
107
|
+
mm[map[i]] = 1 << i;
|
|
108
|
+
}
|
|
109
|
+
return mm;
|
|
110
|
+
}
|
|
111
|
+
return map;
|
|
112
|
+
}
|
|
113
|
+
exports.adaptTypescriptEnum = adaptTypescriptEnum;
|
|
114
|
+
/**
|
|
115
|
+
* @class Enum
|
|
116
|
+
* @constructor
|
|
117
|
+
* Represents an Enum with enum items.
|
|
118
|
+
* @param {Array || Object} map This are the enum items.
|
|
119
|
+
*/
|
|
120
|
+
class Enum {
|
|
121
|
+
constructor(map) {
|
|
122
|
+
this.enumItems = [];
|
|
123
|
+
let mm = null;
|
|
124
|
+
let isFlaggable = null;
|
|
125
|
+
if (Array.isArray(map)) {
|
|
126
|
+
mm = adaptTypescriptEnum(map);
|
|
127
|
+
isFlaggable = true;
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
mm = map;
|
|
131
|
+
}
|
|
132
|
+
for (const key of Object.keys(mm)) {
|
|
133
|
+
if (typeof key !== "string") {
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
const val = mm[key];
|
|
137
|
+
if (undefined === val) {
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
const kv = new EnumItem(key, val);
|
|
141
|
+
const pThis = this;
|
|
142
|
+
pThis[key] = kv;
|
|
143
|
+
pThis[val] = kv;
|
|
144
|
+
this.enumItems.push(kv);
|
|
145
|
+
}
|
|
146
|
+
if (!isFlaggable) {
|
|
147
|
+
isFlaggable = checkIsFlaggable(this.enumItems);
|
|
148
|
+
}
|
|
149
|
+
this._isFlaggable = isFlaggable;
|
|
150
|
+
}
|
|
151
|
+
get isFlaggable() {
|
|
152
|
+
return this._isFlaggable;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Returns the appropriate EnumItem.
|
|
156
|
+
* @method get
|
|
157
|
+
* @param key The object to get with.
|
|
158
|
+
* @return the get result.
|
|
159
|
+
*/
|
|
160
|
+
get(key) {
|
|
161
|
+
const pThis = this;
|
|
162
|
+
if (key instanceof EnumItem) {
|
|
163
|
+
if (!pThis[key.key]) {
|
|
164
|
+
throw new Error("Invalid key");
|
|
165
|
+
}
|
|
166
|
+
return key;
|
|
167
|
+
}
|
|
168
|
+
if (key === null || key === undefined) {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
const prop = pThis[key];
|
|
172
|
+
if (prop) {
|
|
173
|
+
return prop;
|
|
174
|
+
}
|
|
175
|
+
else if (this._isFlaggable) {
|
|
176
|
+
if (typeof key === "string") {
|
|
177
|
+
return this._getByString(key);
|
|
178
|
+
}
|
|
179
|
+
else if (typeof key === "number") {
|
|
180
|
+
return this._getByNum(key);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
getDefaultValue() {
|
|
186
|
+
return this.enumItems[0];
|
|
187
|
+
}
|
|
188
|
+
toString() {
|
|
189
|
+
return this.enumItems.join(" , ");
|
|
190
|
+
}
|
|
191
|
+
_getByString(key) {
|
|
192
|
+
const pThis = this;
|
|
193
|
+
const parts = key.split(" | ");
|
|
194
|
+
let val = 0;
|
|
195
|
+
for (const part of parts) {
|
|
196
|
+
const item = pThis[part];
|
|
197
|
+
if (undefined === item) {
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
val |= item.value;
|
|
201
|
+
}
|
|
202
|
+
const kv = new EnumItem(key, val);
|
|
203
|
+
// add in cache for later
|
|
204
|
+
let prop = pThis[val];
|
|
205
|
+
if (prop === undefined) {
|
|
206
|
+
pThis[val] = kv;
|
|
207
|
+
}
|
|
208
|
+
prop = pThis[key];
|
|
209
|
+
if (prop === undefined) {
|
|
210
|
+
pThis[key] = kv;
|
|
211
|
+
}
|
|
212
|
+
return kv;
|
|
213
|
+
}
|
|
214
|
+
_getByNum(key) {
|
|
215
|
+
if (key === 0) {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
const pThis = this;
|
|
219
|
+
let name;
|
|
220
|
+
let c = 1;
|
|
221
|
+
for (let i = 0; c < key; i++) {
|
|
222
|
+
if ((c & key) === c) {
|
|
223
|
+
const item = pThis[c];
|
|
224
|
+
if (undefined === item) {
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
if (name) {
|
|
228
|
+
name = name + " | " + item.key;
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
name = item.key;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
c *= 2;
|
|
235
|
+
}
|
|
236
|
+
const kv = new EnumItem(name, key);
|
|
237
|
+
// add in cache for later
|
|
238
|
+
pThis[name] = kv;
|
|
239
|
+
pThis[key] = kv;
|
|
240
|
+
return kv;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
exports.Enum = Enum;
|
|
244
244
|
//# 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,22 +1,22 @@
|
|
|
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-enum
|
|
19
|
-
*
|
|
20
|
-
*/
|
|
21
|
-
__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
|
+
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-enum
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
__exportStar(require("./enum"), exports);
|
|
22
22
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-opcua-enum",
|
|
3
|
-
"version": "2.76.
|
|
3
|
+
"version": "2.76.2",
|
|
4
4
|
"description": "pure nodejs OPCUA SDK - module -enum",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc -b",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"@types": "./dist/index.d.ts",
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"enum": "3.0.4",
|
|
15
|
-
"node-opcua-benchmarker": "2.76.
|
|
15
|
+
"node-opcua-benchmarker": "2.76.2",
|
|
16
16
|
"should": "^13.2.3"
|
|
17
17
|
},
|
|
18
18
|
"author": "Etienne Rossignon",
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"internet of things"
|
|
31
31
|
],
|
|
32
32
|
"homepage": "http://node-opcua.github.io/",
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "acb5ecaf1e1c71af3b63e80909d58447f3f298e7"
|
|
34
34
|
}
|