forked from adrai/enum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
enum-2.5.0.js
588 lines (474 loc) · 42.1 KB
/
enum-2.5.0.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.Enum=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
(function (global){
"use strict";
var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
var os = _interopRequire(_dereq_("os"));
var EnumItem = _interopRequire(_dereq_("./enumItem"));
var _isType = _dereq_("./isType");
var isString = _isType.isString;
var isNumber = _isType.isNumber;
var indexOf = _dereq_("./indexOf").indexOf;
var isBuffer = _interopRequire(_dereq_("is-buffer"));
var endianness = os.endianness();
/**
* Represents an Enum with enum items.
* @param {Array || Object} map This are the enum items.
* @param {String || Object} options This are options. [optional]
*/
var Enum = (function () {
function Enum(map, options) {
var _this = this;
_classCallCheck(this, Enum);
/* implement the "ref type interface", so that Enum types can
* be used in `node-ffi` function declarations and invokations.
* In C, these Enums act as `uint32_t` types.
*
* https://github.com/TooTallNate/ref#the-type-interface
*/
this.size = 4;
this.indirection = 1;
if (options && isString(options)) {
options = { name: options };
}
this._options = options || {};
this._options.separator = this._options.separator || " | ";
this._options.endianness = this._options.endianness || endianness;
this._options.ignoreCase = this._options.ignoreCase || false;
this._options.freez = this._options.freez || false;
this.enums = [];
if (map.length) {
this._enumLastIndex = map.length;
var array = map;
map = {};
for (var i = 0; i < array.length; i++) {
map[array[i]] = Math.pow(2, i);
}
}
for (var member in map) {
guardReservedKeys(this._options.name, member);
this[member] = new EnumItem(member, map[member], { ignoreCase: this._options.ignoreCase });
this.enums.push(this[member]);
}
this._enumMap = map;
if (this._options.ignoreCase) {
this.getLowerCaseEnums = function () {
var res = {};
for (var i = 0, len = this.enums.length; i < len; i++) {
res[this.enums[i].key.toLowerCase()] = this.enums[i];
}
return res;
};
}
if (this._options.name) {
this.name = this._options.name;
}
var isFlaggable = function () {
for (var i = 0, len = _this.enums.length; i < len; i++) {
var e = _this.enums[i];
if (!(e.value !== 0 && !(e.value & e.value - 1))) {
return false;
}
}
return true;
};
this.isFlaggable = isFlaggable();
if (this._options.freez) {
this.freezeEnums(); //this will make instances of Enum non-extensible
}
}
/**
* Returns the appropriate EnumItem key.
* @param {EnumItem || String || Number} key The object to get with.
* @return {String} The get result.
*/
Enum.prototype.getKey = function getKey(value) {
var item = this.get(value);
if (item) {
return item.key;
}
};
/**
* Returns the appropriate EnumItem value.
* @param {EnumItem || String || Number} key The object to get with.
* @return {Number} The get result.
*/
Enum.prototype.getValue = function getValue(key) {
var item = this.get(key);
if (item) {
return item.value;
}
};
/**
* Returns the appropriate EnumItem.
* @param {EnumItem || String || Number} key The object to get with.
* @return {EnumItem} The get result.
*/
Enum.prototype.get = function get(key, offset) {
if (key === null || key === undefined) {
return;
} // Buffer instance support, part of the ref Type interface
if (isBuffer(key)) {
key = key["readUInt32" + this._options.endianness](offset || 0);
}
if (EnumItem.isEnumItem(key)) {
var foundIndex = indexOf.call(this.enums, key);
if (foundIndex >= 0) {
return key;
}
if (!this.isFlaggable || this.isFlaggable && key.key.indexOf(this._options.separator) < 0) {
return;
}
return this.get(key.key);
} else if (isString(key)) {
var enums = this;
if (this._options.ignoreCase) {
enums = this.getLowerCaseEnums();
key = key.toLowerCase();
}
if (key.indexOf(this._options.separator) > 0) {
var parts = key.split(this._options.separator);
var value = 0;
for (var i = 0; i < parts.length; i++) {
var part = parts[i];
value |= enums[part].value;
}
return new EnumItem(key, value);
} else {
return enums[key];
}
} else {
for (var m in this) {
if (this.hasOwnProperty(m)) {
if (this[m].value === key) {
return this[m];
}
}
}
var result = null;
if (this.isFlaggable) {
for (var n in this) {
if (this.hasOwnProperty(n)) {
if ((key & this[n].value) !== 0) {
if (result) {
result += this._options.separator;
} else {
result = "";
}
result += n;
}
}
}
}
return this.get(result || null);
}
};
/**
* Sets the Enum "value" onto the give `buffer` at the specified `offset`.
* Part of the ref "Type interface".
*
* @param {Buffer} buffer The Buffer instance to write to.
* @param {Number} offset The offset in the buffer to write to. Default 0.
* @param {EnumItem || String || Number} value The EnumItem to write.
*/
Enum.prototype.set = function set(buffer, offset, value) {
var item = this.get(value);
if (item) {
return buffer["writeUInt32" + this._options.endianness](item.value, offset || 0);
}
};
/**
* Define freezeEnums() as a property of the prototype.
* make enumerable items nonconfigurable and deep freeze the properties. Throw Error on property setter.
*/
Enum.prototype.freezeEnums = function freezeEnums() {
function envSupportsFreezing() {
return Object.isFrozen && Object.isSealed && Object.getOwnPropertyNames && Object.getOwnPropertyDescriptor && Object.defineProperties && Object.__defineGetter__ && Object.__defineSetter__;
}
function freezer(o) {
var props = Object.getOwnPropertyNames(o);
props.forEach(function (p) {
if (!Object.getOwnPropertyDescriptor(o, p).configurable) {
return;
}
Object.defineProperties(o, p, { writable: false, configurable: false });
});
return o;
}
function getPropertyValue(value) {
return value;
}
function deepFreezeEnums(o) {
if (typeof o !== "object" || o === null || Object.isFrozen(o) || Object.isSealed(o)) {
return;
}
for (var key in o) {
if (o.hasOwnProperty(key)) {
o.__defineGetter__(key, getPropertyValue.bind(null, o[key]));
o.__defineSetter__(key, function throwPropertySetError(value) {
throw TypeError("Cannot redefine property; Enum Type is not extensible.");
});
deepFreezeEnums(o[key]);
}
}
if (Object.freeze) {
Object.freeze(o);
} else {
freezer(o);
}
}
if (envSupportsFreezing()) {
deepFreezeEnums(this);
}
return this;
};
/**
* Return true whether the enumItem parameter passed in is an EnumItem object and
* has been included as constant of this Enum
* @param {EnumItem} enumItem
*/
Enum.prototype.isDefined = function isDefined(enumItem) {
var condition = function (e) {
return e === enumItem;
};
if (isString(enumItem) || isNumber(enumItem)) {
condition = function (e) {
return e.is(enumItem);
};
}
return this.enums.some(condition);
};
/**
* Returns JSON object representation of this Enum.
* @return {String} JSON object representation of this Enum.
*/
Enum.prototype.toJSON = function toJSON() {
return this._enumMap;
};
/**
* Extends the existing Enum with a New Map.
* @param {Array} map Map to extend from
*/
Enum.prototype.extend = function extend(map) {
if (map.length) {
var array = map;
map = {};
for (var i = 0; i < array.length; i++) {
var exponent = this._enumLastIndex + i;
map[array[i]] = Math.pow(2, exponent);
}
for (var member in map) {
guardReservedKeys(this._options.name, member);
this[member] = new EnumItem(member, map[member], { ignoreCase: this._options.ignoreCase });
this.enums.push(this[member]);
}
for (var key in this._enumMap) {
map[key] = this._enumMap[key];
}
this._enumLastIndex += map.length;
this._enumMap = map;
if (this._options.freez) {
this.freezeEnums(); //this will make instances of new Enum non-extensible
}
}
};
/**
* Registers the Enum Type globally in node.js.
* @param {String} key Global variable. [optional]
*/
Enum.register = function register() {
var key = arguments[0] === undefined ? "Enum" : arguments[0];
if (!global[key]) {
global[key] = Enum;
}
};
Enum.prototype[Symbol.iterator] = function () {
var _this = this;
var index = 0;
return {
next: function () {
return index < _this.enums.length ? { done: false, value: _this.enums[index++] } : { done: true };
}
};
};
return Enum;
})();
module.exports = Enum;
// private
var reservedKeys = ["_options", "get", "getKey", "getValue", "enums", "isFlaggable", "_enumMap", "toJSON", "_enumLastIndex"];
function guardReservedKeys(customName, key) {
if (customName && key === "name" || indexOf.call(reservedKeys, key) >= 0) {
throw new Error("Enum key " + key + " is a reserved word!");
}
}
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"./enumItem":2,"./indexOf":3,"./isType":4,"is-buffer":6,"os":7}],2:[function(_dereq_,module,exports){
"use strict";
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
var _isType = _dereq_("./isType");
var isObject = _isType.isObject;
var isString = _isType.isString;
/**
* Represents an Item of an Enum.
* @param {String} key The Enum key.
* @param {Number} value The Enum value.
*/
var EnumItem = (function () {
/*constructor reference so that, this.constructor===EnumItem//=>true */
function EnumItem(key, value) {
var options = arguments[2] === undefined ? {} : arguments[2];
_classCallCheck(this, EnumItem);
this.key = key;
this.value = value;
this._options = options;
this._options.ignoreCase = this._options.ignoreCase || false;
}
/**
* Checks if the flagged EnumItem has the passing object.
* @param {EnumItem || String || Number} value The object to check with.
* @return {Boolean} The check result.
*/
EnumItem.prototype.has = function has(value) {
if (EnumItem.isEnumItem(value)) {
return (this.value & value.value) !== 0;
} else if (isString(value)) {
if (this._options.ignoreCase) {
return this.key.toLowerCase().indexOf(value.toLowerCase()) >= 0;
}
return this.key.indexOf(value) >= 0;
} else {
return (this.value & value) !== 0;
}
};
/**
* Checks if the EnumItem is the same as the passing object.
* @param {EnumItem || String || Number} key The object to check with.
* @return {Boolean} The check result.
*/
EnumItem.prototype.is = function is(key) {
if (EnumItem.isEnumItem(key)) {
return this.key === key.key;
} else if (isString(key)) {
if (this._options.ignoreCase) {
return this.key.toLowerCase() === key.toLowerCase();
}
return this.key === key;
} else {
return this.value === key;
}
};
/**
* Returns String representation of this EnumItem.
* @return {String} String representation of this EnumItem.
*/
EnumItem.prototype.toString = function toString() {
return this.key;
};
/**
* Returns JSON object representation of this EnumItem.
* @return {String} JSON object representation of this EnumItem.
*/
EnumItem.prototype.toJSON = function toJSON() {
return this.key;
};
/**
* Returns the value to compare with.
* @return {String} The value to compare with.
*/
EnumItem.prototype.valueOf = function valueOf() {
return this.value;
};
EnumItem.isEnumItem = function isEnumItem(value) {
return value instanceof EnumItem || isObject(value) && value.key !== undefined && value.value !== undefined;
};
return EnumItem;
})();
module.exports = EnumItem;
},{"./isType":4}],3:[function(_dereq_,module,exports){
"use strict";
exports.__esModule = true;
var indexOf = Array.prototype.indexOf || function (find, i /*opt*/) {
if (i === undefined) i = 0;
if (i < 0) i += this.length;
if (i < 0) i = 0;
for (var n = this.length; i < n; i++) if (i in this && this[i] === find) return i;
return -1;
};
exports.indexOf = indexOf;
},{}],4:[function(_dereq_,module,exports){
"use strict";
exports.__esModule = true;
var isType = function (type, value) {
return typeof value === type;
};
exports.isType = isType;
var isObject = function (value) {
return isType("object", value);
};
exports.isObject = isObject;
var isString = function (value) {
return isType("string", value);
};
exports.isString = isString;
var isNumber = function (value) {
return isType("number", value);
};
exports.isNumber = isNumber;
},{}],5:[function(_dereq_,module,exports){
module.exports = _dereq_('./dist/enum');
},{"./dist/enum":1}],6:[function(_dereq_,module,exports){
/*!
* Determine if an object is a Buffer
*
* @author Feross Aboukhadijeh <https://feross.org>
* @license MIT
*/
// The _isBuffer check is for Safari 5-7 support, because it's missing
// Object.prototype.constructor. Remove this eventually
module.exports = function (obj) {
return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer)
}
function isBuffer (obj) {
return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
}
// For Node v0.10 support. Remove this eventually.
function isSlowBuffer (obj) {
return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0))
}
},{}],7:[function(_dereq_,module,exports){
exports.endianness = function () { return 'LE' };
exports.hostname = function () {
if (typeof location !== 'undefined') {
return location.hostname
}
else return '';
};
exports.loadavg = function () { return [] };
exports.uptime = function () { return 0 };
exports.freemem = function () {
return Number.MAX_VALUE;
};
exports.totalmem = function () {
return Number.MAX_VALUE;
};
exports.cpus = function () { return [] };
exports.type = function () { return 'Browser' };
exports.release = function () {
if (typeof navigator !== 'undefined') {
return navigator.appVersion;
}
return '';
};
exports.networkInterfaces
= exports.getNetworkInterfaces
= function () { return {} };
exports.arch = function () { return 'javascript' };
exports.platform = function () { return 'browser' };
exports.tmpdir = exports.tmpDir = function () {
return '/tmp';
};
exports.EOL = '\n';
},{}]},{},[5])
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi9Vc2Vycy9hZHJhaS9Qcm9qZWN0cy9lbnVtL25vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCIvVXNlcnMvYWRyYWkvUHJvamVjdHMvZW51bS9kaXN0L2VudW0uanMiLCIvVXNlcnMvYWRyYWkvUHJvamVjdHMvZW51bS9kaXN0L2VudW1JdGVtLmpzIiwiL1VzZXJzL2FkcmFpL1Byb2plY3RzL2VudW0vZGlzdC9pbmRleE9mLmpzIiwiL1VzZXJzL2FkcmFpL1Byb2plY3RzL2VudW0vZGlzdC9pc1R5cGUuanMiLCIvVXNlcnMvYWRyYWkvUHJvamVjdHMvZW51bS9mYWtlXzlkZjBmMDgxLmpzIiwiL1VzZXJzL2FkcmFpL1Byb2plY3RzL2VudW0vbm9kZV9tb2R1bGVzL2lzLWJ1ZmZlci9pbmRleC5qcyIsIi9Vc2Vycy9hZHJhaS9Qcm9qZWN0cy9lbnVtL25vZGVfbW9kdWxlcy9vcy1icm93c2VyaWZ5L2Jyb3dzZXIuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7QUNBQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNB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gICAgICBpZiAoa2V5LmluZGV4T2YodGhpcy5fb3B0aW9ucy5zZXBhcmF0b3IpID4gMCkge1xuICAgICAgICB2YXIgcGFydHMgPSBrZXkuc3BsaXQodGhpcy5fb3B0aW9ucy5zZXBhcmF0b3IpO1xuXG4gICAgICAgIHZhciB2YWx1ZSA9IDA7XG4gICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgcGFydHMubGVuZ3RoOyBpKyspIHtcbiAgICAgICAgICB2YXIgcGFydCA9IHBhcnRzW2ldO1xuXG4gICAgICAgICAgdmFsdWUgfD0gZW51bXNbcGFydF0udmFsdWU7XG4gICAgICAgIH1cblxuICAgICAgICByZXR1cm4gbmV3IEVudW1JdGVtKGtleSwgdmFsdWUpO1xuICAgICAgfSBlbHNlIHtcbiAgICAgICAgcmV0dXJuIGVudW1zW2tleV07XG4gICAgICB9XG4gICAgfSBlbHNlIHtcbiAgICAgIGZvciAodmFyIG0gaW4gdGhpcykge1xuICAgICAgICBpZiAodGhpcy5oYXNPd25Qcm9wZXJ0eShtKSkge1xuICAgICAgICAgIGlmICh0aGlzW21dLnZhbHVlID09PSBrZXkpIHtcbiAgICAgICAgICAgIHJldHVybiB0aGlzW21dO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfVxuXG4gICAgICB2YXIgcmVzdWx0ID0gbnVsbDtcblxuICAgICAgaWYgKHRoaXMuaXNGbGFnZ2FibGUpIHtcbiAgICAgICAgZm9yICh2YXIgbiBpbiB0aGlzKSB7XG4gICAgICAgICAgaWYgKHRoaXMuaGFzT3duUHJvcGVydHkobikpIHtcbiAgICAgICAgICAgIGlmICgoa2V5ICYgdGhpc1tuXS52YWx1ZSkgIT09IDApIHtcbiAgICAgICAgICAgICAgaWYgKHJlc3VsdCkge1xuICAgICAgICAgICAgICAgIHJlc3VsdCArPSB0aGlzLl9vcHRpb25zLnNlcGFyYXRvcjtcbiAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICByZXN1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