@cedx/enum
Advanced tools
Comparing version 2.3.0 to 2.4.0
# Changelog | ||
This file contains highlights of what changes on each version of the [Enums for JS](https://github.com/cedx/enum.js) library. | ||
## Version 2.4.0 | ||
- Removed the dependency on [Babel](https://babeljs.io) compiler. | ||
- Updated the package dependencies. | ||
## Version 2.3.0 | ||
@@ -5,0 +9,0 @@ - Updated the package dependencies. |
134
lib/enum.js
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
/** | ||
* Provides helper methods for enumerations. | ||
*/ | ||
exports.Enum = class Enum { | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
/** | ||
* Creates an enumeration from the specified type definition. | ||
* @param {object} typeDef An object defining the shape of the enumerated type. | ||
* @return {object} The newly created enumeration. | ||
*/ | ||
static create(typeDef) { | ||
let enumType = class { | ||
/* eslint-disable require-jsdoc */ | ||
constructor() { throw new TypeError('This type is not instantiable.'); } | ||
static isDefined(value) { return Enum.isDefined(enumType, value); } | ||
static getName(value) { return Enum.getName(enumType, value); } | ||
static getNames() { return Enum.getNames(enumType); } | ||
static getValues() { return Enum.getValues(enumType); } | ||
/* eslint-enable require-jsdoc */ | ||
}; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
for (let prop in typeDef) { | ||
let type = typeof typeDef[prop]; | ||
if (type == 'boolean' || type == 'number' || type == 'string') enumType[prop] = typeDef[prop]; | ||
} | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
return Object.freeze(enumType); | ||
} | ||
var Enum = exports.Enum = function () { | ||
function Enum() { | ||
_classCallCheck(this, Enum); | ||
/** | ||
* Returns an indication whether a constant with a specified value exists in the specified enumeration. | ||
* @param {object} enumType An enumerated type. | ||
* @param {*} value The value of a constant in the specified enumeration. | ||
* @return {boolean} `true` if a constant in the specified enumeration has the specified value, otherwise `false`. | ||
*/ | ||
static isDefined(enumType, value) { | ||
return Enum.getValues(enumType).includes(value); | ||
} | ||
_createClass(Enum, null, [{ | ||
key: 'create', | ||
value: function create(typeDef) { | ||
var enumType = function () { | ||
function enumType() { | ||
_classCallCheck(this, enumType); | ||
/** | ||
* Retrieves the name of the constant in the specified enumeration that has the specified value. | ||
* @param {object} enumType An enumerated type. | ||
* @param {*} value The value of a constant in the specified enumeration. | ||
* @return {string} A string containing the name of the enumerated constant that has the specified value, or an empty string if no such constant is found. | ||
*/ | ||
static getName(enumType, value) { | ||
let index = Enum.getValues(enumType).indexOf(value); | ||
return index < 0 ? '' : Enum.getNames(enumType)[index]; | ||
} | ||
throw new TypeError('This type is not instantiable.'); | ||
} | ||
/** | ||
* Retrieves an array of the names of the constants in the specified enumeration. | ||
* @param {object} enumType An enumerated type. | ||
* @return {string[]} An array that contains the names of the constants in the specified enumeration. | ||
*/ | ||
static getNames(enumType) { | ||
return Object.keys(enumType); | ||
} | ||
_createClass(enumType, null, [{ | ||
key: 'isDefined', | ||
value: function isDefined(value) { | ||
return Enum.isDefined(enumType, value); | ||
} | ||
}, { | ||
key: 'getName', | ||
value: function getName(value) { | ||
return Enum.getName(enumType, value); | ||
} | ||
}, { | ||
key: 'getNames', | ||
value: function getNames() { | ||
return Enum.getNames(enumType); | ||
} | ||
}, { | ||
key: 'getValues', | ||
value: function getValues() { | ||
return Enum.getValues(enumType); | ||
} | ||
}]); | ||
return enumType; | ||
}(); | ||
for (var prop in typeDef) { | ||
var type = _typeof(typeDef[prop]); | ||
if (type == 'boolean' || type == 'number' || type == 'string') enumType[prop] = typeDef[prop]; | ||
} | ||
return Object.freeze(enumType); | ||
} | ||
}, { | ||
key: 'isDefined', | ||
value: function isDefined(enumType, value) { | ||
return Enum.getValues(enumType).includes(value); | ||
} | ||
}, { | ||
key: 'getName', | ||
value: function getName(enumType, value) { | ||
var index = Enum.getValues(enumType).indexOf(value); | ||
return index < 0 ? '' : Enum.getNames(enumType)[index]; | ||
} | ||
}, { | ||
key: 'getNames', | ||
value: function getNames(enumType) { | ||
return Object.keys(enumType); | ||
} | ||
}, { | ||
key: 'getValues', | ||
value: function getValues(enumType) { | ||
return Object.values(enumType); | ||
} | ||
}]); | ||
return Enum; | ||
}(); | ||
/** | ||
* Retrieves an array of the values of the constants in the specified enumeration. | ||
* @param {object} enumType An enumerated type. | ||
* @return {Array} An array that contains the values of the constants in the specified enumeration. | ||
*/ | ||
static getValues(enumType) { | ||
return Object.values(enumType); | ||
} | ||
}; |
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _enum = require('./enum'); | ||
Object.keys(_enum).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _enum[key]; | ||
} | ||
}); | ||
}); | ||
const {Enum} = require('./enum'); | ||
module.exports = {Enum}; |
@@ -8,21 +8,18 @@ { | ||
"main": "./lib/index", | ||
"module": "./src/index", | ||
"name": "@cedx/enum", | ||
"repository": "cedx/enum.js", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"devDependencies": { | ||
"@cedx/coveralls": "^2.0.0", | ||
"@cedx/gulp-david": "^7.0.1", | ||
"babel-preset-env": "^1.6.0", | ||
"babel-register": "^6.24.1", | ||
"chai": "^4.0.2", | ||
"@cedx/gulp-david": "^8.0.0", | ||
"chai": "^4.1.0", | ||
"del": "^3.0.0", | ||
"esdoc": "^0.5.2", | ||
"esdoc-node": "^1.0.2", | ||
"estraverse": "^4.2.0", | ||
"gulp": "^3.9.1", | ||
"gulp-babel": "^6.1.2", | ||
"gulp-eslint": "^4.0.0", | ||
"mocha": "^3.4.2", | ||
"nsp": "^2.6.3", | ||
"nyc": "^11.0.3" | ||
"nyc": "^11.1.0" | ||
}, | ||
@@ -41,5 +38,4 @@ "engines": { | ||
"coverage": "coveralls --file=var/lcov.info", | ||
"prepare": "gulp build", | ||
"test": "nyc --report-dir=var --reporter=lcovonly mocha --compilers=js:babel-register --recursive" | ||
"test": "nyc --report-dir=var --reporter=lcovonly mocha --recursive" | ||
} | ||
} |
@@ -25,3 +25,3 @@ # Enums for JS | ||
```javascript | ||
import {Enum} from '@cedx/enum'; | ||
const {Enum} = require('@cedx/enum'); | ||
@@ -28,0 +28,0 @@ /** |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12
19875
8
65
1