diff options
| author | Andrej Mihajlov <and@codeispoetry.ru> | 2017-03-10 18:49:16 +0000 |
|---|---|---|
| committer | Andrej Mihajlov <and@codeispoetry.ru> | 2017-03-10 18:49:16 +0000 |
| commit | ab936cc298a81dbf0ef13e53bd03cff7f2324d13 (patch) | |
| tree | 9aea6453b22ffa3948a16c6fb6171ecaa321ba7f /app/lib/enum.js | |
| parent | 767148f976f942bb68d4bc6c4d09b076aa6e39e0 (diff) | |
| download | mullvadvpn-ab936cc298a81dbf0ef13e53bd03cff7f2324d13.tar.xz mullvadvpn-ab936cc298a81dbf0ef13e53bd03cff7f2324d13.zip | |
Update documentation
Diffstat (limited to 'app/lib/enum.js')
| -rw-r--r-- | app/lib/enum.js | 58 |
1 files changed, 38 insertions, 20 deletions
diff --git a/app/lib/enum.js b/app/lib/enum.js index 1815a551f7..a27bd37439 100644 --- a/app/lib/enum.js +++ b/app/lib/enum.js @@ -1,28 +1,46 @@ /** - * Creates enum object with keys provided as arguments - * - * @constructor - * @type Enum - * @property {bool} isValid({string}) whether key is valid - * @param {...string} ... Enum keys - * @export - * @returns Enum + * Enum + * @exports + * @class Enum */ -export default function Enum() { - let object = Object.create({}); - const keys = [...arguments]; +export default class Enum { - for(const key of keys) { - Object.defineProperty(object, key, { - enumerable: true, - value: key, + /** + * Creates an instance of EnumBase. + * + * @param {...string} ... - enum keys + * @memberOf Enum + */ + constructor() { + const keys = [...arguments]; + + for(const key of keys) { + Object.defineProperty(this, key, { + enumerable: true, + value: key, + writable: false + }); + } + + Object.defineProperty(this, 'allKeys', { + enumerable: false, + value: keys, writable: false }); + + Object.freeze(this); } - - Object.defineProperty(object, 'isValid', { - value: (e) => keys.includes(e) - }); - return Object.freeze(object); + /** + * Check if key is registered in this enum + * + * @param {string} key + * @returns {bool} + * + * @memberOf Enum + */ + isValid(key) { + return this.allKeys.includes(key); + } } + |
