New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@cedx/enum

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cedx/enum - npm Package Compare versions

Comparing version 3.2.0 to 3.3.0

LICENSE.md

6

CHANGELOG.md
# Changelog
This file contains highlights of what changes on each version of the [Enums for JS](https://github.com/cedx/enum.js) library.
## Version [3.3.0](https://github.com/cedx/enum.js/compare/v3.2.0...v3.3.0)
- Added a user guide based on [MkDocs](http://www.mkdocs.org).
- Updated the build system to [Gulp](https://gulpjs.com) version 4.
- Updated the package dependencies.
## Version [3.2.0](https://github.com/cedx/enum.js/compare/v3.1.0...v3.2.0)

@@ -5,0 +9,0 @@ - Added support for browser testing.

7

lib/enum.js

@@ -6,3 +6,3 @@ 'use strict';

*/
exports.Enum = class Enum {
class Enum {

@@ -117,2 +117,5 @@ /**

}
};
}
// Module exports.
exports.Enum = Enum;
'use strict';
const {Enum} = require('./enum');
const {Enum} = require('./enum.js');
module.exports = {Enum};

@@ -5,3 +5,3 @@ {

"description": "A simple implementation of enumerated types.",
"homepage": "https://github.com/cedx/enum.js",
"homepage": "https://cedx.github.io/enum.js",
"license": "MIT",

@@ -11,21 +11,21 @@ "main": "./lib/index.js",

"repository": "cedx/enum.js",
"version": "3.2.0",
"version": "3.3.0",
"devDependencies": {
"@cedx/coveralls": "^5.0.0",
"@cedx/coveralls": "^5.1.0",
"@cedx/gulp-david": "^11.0.0",
"browserify": "^14.4.0",
"browserify": "^15.2.0",
"chai": "^4.1.2",
"del": "^3.0.0",
"esdoc": "^1.0.3",
"esdoc-node": "^1.0.2",
"esdoc": "^1.0.4",
"esdoc-node": "^1.0.3",
"esdoc-standard-plugin": "^1.0.0",
"gulp": "^3.9.1",
"gulp-eslint": "^4.0.0",
"karma": "^1.7.1",
"karma-browserify": "^5.1.1",
"karma-firefox-launcher": "^1.0.1",
"gulp": "^4.0.0",
"gulp-eslint": "^4.0.2",
"karma": "^2.0.0",
"karma-browserify": "^5.1.3",
"karma-chrome-launcher": "^2.2.0",
"karma-mocha": "^1.3.0",
"mocha": "^4.0.1",
"nsp": "^3.0.0",
"nyc": "^11.3.0",
"mocha": "^5.0.0",
"nsp": "^3.1.0",
"nyc": "^11.4.1",
"watchify": "^3.9.0"

@@ -32,0 +32,0 @@ },

@@ -6,94 +6,9 @@ # Enums for JS

This implementation does not try to reproduce the semantics of traditional enumerations, like the ones found in C# or Java languages. It just gives a set of static methods to ease working with the values of an object literal representing an enumerated type.
## Resources
- [Documentation](https://cedx.github.io/enum.js)
- [API reference](https://cedx.github.io/enum.js/api)
- [npm package](https://www.npmjs.com/package/@cedx/enum)
- [GitHub repository](https://github.com/cedx/enum.js)
## Requirements
The latest [Node.js](https://nodejs.org) and [npm](https://www.npmjs.com) versions.
If you plan to play with the sources, you will also need the latest [Gulp](http://gulpjs.com) version.
## Installing via [npm](https://www.npmjs.com)
From a command prompt, run:
```shell
$ npm install --save @cedx/enum
```
## Usage
### Create the enumeration
Just use the `Enum.create()` method with an object literal containing scalar values (e.g. only booleans, numbers and strings):
```javascript
const {Enum} = require('@cedx/enum');
/**
* Specifies the day of the week.
* @type {object}
*/
const DayOfWeek = Enum.create({
sunday: 0,
monday: 1,
tuesday: 2,
wednesday: 3,
thursday: 4,
friday: 5,
saturday: 6
});
```
The [`Enum.create()`](https://github.com/cedx/enum.js/blob/master/lib/enum.js) method creates an anonymous class from the specified object. This class has the same values as the provided object, and some additional helper methods.
The created class has a constructor throwing a `TypeError`: it prohibits its instantiation. This class is also freezed to prevent any attempt at modifying its shape.
### Work with the enumeration
Check whether a value is defined among the enumerated type:
```javascript
DayOfWeek.isDefined(DayOfWeek.sunday); // true
DayOfWeek.isDefined('foo'); // false
```
Ensure that a value is defined among the enumerated type:
```javascript
DayOfWeek.assert(DayOfWeek.monday); // DayOfWeek.monday
DayOfWeek.assert('foo'); // (throws TypeError)
DayOfWeek.coerce(DayOfWeek.monday); // DayOfWeek.monday
DayOfWeek.coerce('bar'); // null
DayOfWeek.coerce('baz', DayOfWeek.tuesday); // DayOfWeek.tuesday
```
Get the zero-based position of a value in the enumerated type declaration:
```javascript
DayOfWeek.getIndex(DayOfWeek.wednesday); // 3
DayOfWeek.getIndex('foo'); // -1
```
Get the name associated to an enumerated value:
```javascript
DayOfWeek.getName(DayOfWeek.thursday); // "thursday"
DayOfWeek.getName('foo'); // "" (empty)
```
Get information about the enumerated type:
```javascript
DayOfWeek.getEntries();
// [["sunday", 0], ["monday", 1], ["tuesday", 2], ["wednesday", 3], ["thursday", 4], ["friday", 5], ["saturday", 6]]
DayOfWeek.getNames();
// ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"]
DayOfWeek.getValues();
// [0, 1, 2, 3, 4, 5, 6]
```
## See also
- [API reference](https://cedx.github.io/enum.js)
- [Code coverage](https://coveralls.io/github/cedx/enum.js)
- [Continuous integration](https://travis-ci.org/cedx/enum.js)
## License
[Enums for JS](https://github.com/cedx/enum.js) is distributed under the MIT License.
[Enums for JS](https://cedx.github.io/enum.js) is distributed under the MIT License.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc