Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

enum

Package Overview
Dependencies
Maintainers
2
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

enum - npm Package Compare versions

Comparing version 2.5.0 to 3.0.0

cjs/enum.js

71

package.json
{
"author": "adrai",
"name": "enum",
"version": "2.5.0",
"version": "3.0.0",
"private": false,
"main": "index.js",
"type": "module",
"main": "./cjs/enum.js",
"exports": {
".": {
"require": "./cjs/enum.js",
"default": "./lib/enum.js"
}
},
"module": "./lib/enum.js",
"engines": {
"node": ">=0.6.0"
},
"directories": {
"lib": "./lib"
},
"dependencies": {
"is-buffer": "^1.1.0"
},
"dependencies": {},
"devDependencies": {
"expect.js": ">= 0.1.2",
"gulp": "^3.8.11",
"gulp-babel": "^4.0.0",
"gulp-bench": "^1.1.0",
"gulp-browserify": "^0.5.1",
"gulp-mocha": "^2.0.0",
"gulp-rename": "^1.2.0",
"gulp-rimraf": "^0.1.1",
"gulp-shell": "^0.4.0",
"gulp-uglify": "^1.1.0",
"mocha": ">= 1.0.1",
"zuul": ">= 1.0.1"
"@babel/cli": "7.8.4",
"@babel/core": "7.9.0",
"@babel/preset-env": "7.9.5",
"babel-plugin-add-module-exports": "1.0.2",
"browserify": "16.5.1",
"eslint": "6.8.0",
"eslint-config-standard": "14.1.1",
"eslint-plugin-import": "2.20.1",
"eslint-plugin-node": "11.0.0",
"eslint-plugin-promise": "4.2.1",
"eslint-plugin-require-path-exists": "1.1.9",
"eslint-plugin-standard": "4.0.1",
"expect.js": "0.3.1",
"mocha": "7.1.1",
"uglify-js": "3.8.1"
},

@@ -49,23 +55,8 @@ "description": "Enum is a javascript module that introduces the Enum Type. It works for node.js and in the browser.",

"scripts": {
"test": "gulp test-ci",
"build": "gulp build",
"prepublish": "gulp"
},
"testling": {
"browsers": [
"ie/6..latest",
"firefox/17..latest",
"firefox/nightly",
"chrome/22..latest",
"chrome/canary",
"opera/12..latest",
"opera/next",
"safari/5.1..latest",
"ipad/6.0..latest",
"iphone/6.0..latest",
"android-browser/4.2..latest"
],
"harness": "mocha",
"files": "test/*.js"
"lint": "eslint .",
"compile": "rm -rf cjs && mkdir cjs && babel lib -d cjs --presets=@babel/preset-env --plugins=add-module-exports && echo '{\"type\":\"commonjs\"}' > cjs/package.json",
"browser": "rm -rf dist && mkdir dist && browserify --standalone Enum cjs/enum.js -o dist/enum-$npm_package_version.js && uglifyjs dist/enum-$npm_package_version.js --compress --mangle -o dist/enum-$npm_package_version.min.js",
"build": "npm run compile && npm run browser",
"test": "npm run lint && npm run build && mocha test -R spec --globals Enum"
}
}
# Introduction
[![travis](https://img.shields.io/travis/adrai/enum.svg)](https://travis-ci.org/adrai/enum) [![npm](https://img.shields.io/npm/v/enum.svg)](https://npmjs.org/package/enum) [![Sauce Test Status](https://saucelabs.com/buildstatus/adrirai)](https://saucelabs.com/u/adrirai)
[![travis](https://img.shields.io/travis/adrai/enum.svg)](https://travis-ci.org/adrai/enum) [![npm](https://img.shields.io/npm/v/enum.svg)](https://npmjs.org/package/enum)
[![Sauce Test Status](https://saucelabs.com/browser-matrix/adrirai.svg)](https://saucelabs.com/u/adrirai)
<!---
[![browser support](https://ci.testling.com/adrai/enum.png)](https://ci.testling.com/adrai/enum)
-->
Enum is a javascript module that introduces the Enum Type. It works for node.js and in the browser.

@@ -21,4 +14,4 @@

|:------------|:----------------|:---------|
| `enum-2.4.0.js` | *uncompressed, with comments* | [Download](https://raw.github.com/adrai/enum/master/enum-2.4.0.js) |
| `enum-2.4.0.min.js` | *compressed, without comments* | [Download](https://raw.github.com/adrai/enum/master/enum-2.4.0.min.js) |
| `enum-3.0.0.js` | *uncompressed, with comments* | [Download](https://raw.github.com/adrai/enum/master/dist/enum-3.0.0.js) |
| `enum-3.0.0.min.js` | *compressed, without comments* | [Download](https://raw.github.com/adrai/enum/dist/master/enum-3.0.0.min.js) |

@@ -37,17 +30,20 @@ # Installation (node.js)

// use it as module
var Enum = require('enum');
const Enum = require('enum')
// or extend node.js with this new type
require('enum').register();
require('enum').register()
// or with import
import Enum from 'enum'
// define a simple enum (automatically flaggable -> A: 0x01, B: 0x02, C: 0x04)
//Uses bitwise 'OR' operation in between the values and creates enumerated constants. For example, if 'Read':1, 'Write':2, then ReadWrite= Read | Write = 1 | 2 = 3;
var myEnum = new Enum(['A', 'B', 'C']);
//Uses bitwise 'OR' operation in between the values and creates enumerated constants. For example, if 'Read':1, 'Write':2, then ReadWrite= Read | Write = 1 | 2 = 3
const myEnum = new Enum(['A', 'B', 'C'])
//define a flagged enum object to create a multicolor option; just pass an array
var myEnum = new Enum(['Black', 'Red', 'Green', 'Blue']);
myEnum; //=> Enum {_options: Object, enums: Array[4], Black: EnumItem, Red: EnumItem, Green: EnumItem….....}
myEnum.isFlaggable; //=> true
//define a flagged enum object to create a multicolor option just pass an array
const myEnum = new Enum(['Black', 'Red', 'Green', 'Blue'])
myEnum //=> Enum {_options: Object, enums: Array[4], Black: EnumItem, Red: EnumItem, Green: EnumItem….....}
myEnum.isFlaggable //=> true
for(var i=1; i<8; i++){ console.log(myEnum.get(i).value + '=> '+ myEnum.get(i).key)}
for (const i=1 i<8 i++){ console.log(myEnum.get(i).value + '=> '+ myEnum.get(i).key)}
1=> Black

@@ -62,37 +58,37 @@ 2=> Red

// define an enum with own values
var myEnum = new Enum({'A': 1, 'B': 2, 'C': 4});
const myEnum = new Enum({'A': 1, 'B': 2, 'C': 4})
// if defining a flaggable enum, you can define your own separator (default is ' | ')
var myEnum = new Enum(['A', 'B', 'C'], { separator: ' | ' });
const myEnum = new Enum(['A', 'B', 'C'], { separator: ' | ' })
// if you want your enum to have a name define it in the options
var myEnum = new Enum(['A', 'B', 'C'], { name: 'MyEnum' });
const myEnum = new Enum(['A', 'B', 'C'], { name: 'MyEnum' })
// or
var myEnum = new Enum(['A', 'B', 'C'], 'MyEnum');
const myEnum = new Enum(['A', 'B', 'C'], 'MyEnum')
// if you want your enum to have an explicit "endianness", define it in the options
// (defaults to `os.endianness()`)
var myEnum = new Enum(['A', 'B', 'C'], { endianness: 'BE' });
const myEnum = new Enum(['A', 'B', 'C'], { endianness: 'BE' })
// if you want your enum to be not case sensitive
// (defaults to `false`)
var myEnum = new Enum(['One', 'tWo', 'ThrEE'], { ignoreCase: true });
myEnum.get('one'); // => myEnum.One
myEnum.get('TWO'); // => myEnum.tWo
myEnum.ThrEE.is('three'); // => true
const myEnum = new Enum(['One', 'tWo', 'ThrEE'], { ignoreCase: true })
myEnum.get('one') // => myEnum.One
myEnum.get('TWO') // => myEnum.tWo
myEnum.ThrEE.is('three') // => true
// this option will make instances of Enum non-extensible
// (defaults to `false`)
var myEnum = new Enum(['ONE', 'TWO', 'THREE'], { freez: true });
const myEnum = new Enum(['ONE', 'TWO', 'THREE'], { freez: true })
//define enum type without flag
var myEnum = new Enum({'None': 0, 'Black':1, 'Red': 2, 'Red2': 3, 'Green': 4, 'Blue': 5});
myEnum; //=> Enum {_options: Object, enums: Array[6], None: EnumItem, Black: EnumItem, Red: EnumItem…........}
myEnum.isFlaggable; //=> false
const myEnum = new Enum({'None': 0, 'Black':1, 'Red': 2, 'Red2': 3, 'Green': 4, 'Blue': 5})
myEnum //=> Enum {_options: Object, enums: Array[6], None: EnumItem, Black: EnumItem, Red: EnumItem…........}
myEnum.isFlaggable //=> false
myEnum.toJSON(); // returns {'None': 0, 'Black':1, 'Red': 2, 'Red2': 3, 'Green': 4, 'Blue': 5}
JSON.stringify(myEnum); // returns '{"None":0,"Black":1,"Red":2,"Red2":3,"Green":4,"Blue":5}'
myEnum.toJSON() // returns {'None': 0, 'Black':1, 'Red': 2, 'Red2': 3, 'Green': 4, 'Blue': 5}
JSON.stringify(myEnum) // returns '{"None":0,"Black":1,"Red":2,"Red2":3,"Green":4,"Blue":5}'
for(var i=0; i<=5; i++){ console.log(myEnum.get(i).value + '=> '+ myEnum.get(i).key)}
for(const i=0 i<=5 i++){ console.log(myEnum.get(i).value + '=> '+ myEnum.get(i).key)}
0=> None

@@ -107,4 +103,4 @@ 1=> Black

myEnum.enums.forEach(function(enumItem) {
console.log(enumItem.key);
});
console.log(enumItem.key)
})
// => None

@@ -165,3 +161,3 @@ // => Black

// check flag
var myItem = myEnum.get(3); // or [myEnum.get('A | B')]
const myItem = myEnum.get(3) // or [myEnum.get('A | B')]
myItem.has(myEnum.A)

@@ -186,9 +182,9 @@

//Each EnumItem has a beack-reference to a constructor and they are implicitly final.
Object.getOwnPropertyDescriptor(myEnum, 'Red'); //=> Object {value: EnumItem, writable: false, enumerable: true, configurable: false}
Object.isExtensible(myEnum); //=> false
myEnum instanceof Enum; //=> true
Object.getOwnPropertyDescriptor(myEnum, 'Red') //=> Object {value: EnumItem, writable: false, enumerable: true, configurable: false}
Object.isExtensible(myEnum) //=> false
myEnum instanceof Enum //=> true
//Instances of Enum created with 'new' from similar objects are not equal
myEnum1=new Enum({'A':1, 'B':2, 'C':4});
myEnum2=new Enum({'A':1, 'B':2, 'C':4});
myEnum1=new Enum({'A':1, 'B':2, 'C':4})
myEnum2=new Enum({'A':1, 'B':2, 'C':4})
myEnum1 == myEnum2 //=> false

@@ -199,34 +195,11 @@ myEnum1.A == myEnum2.A //=> false

//This enum object has no properties other than those defined during its creation. Existing Data is 'Persistent' and preserves the original version
myEnum.B.value; //=> 2
myEnum.B = 5; //=> Throws TypeError
delete myEnum.B; //=> false
myEnum.D = 6; //=> doesn't add to the enum object, silently ignores
myEnum.D; // undefined
myEnum.B.value //=> 2
myEnum.B = 5 //=> Throws TypeError
delete myEnum.B //=> false
myEnum.D = 6 //=> doesn't add to the enum object, silently ignores
myEnum.D // undefined
//Try to define new property throws TypeError
Object.defineProperty(myEnum, D, {value:6, writable:false, enumerable:true});
Object.defineProperty(myEnum, D, { value:6, writable:false, enumerable:true })
//=>TypeError: Cannot define property:D, object is not extensible.
````
# License
Copyright (c) 2016 Adriano Raiano, Christoph Hermann
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
````

Sorry, the diff of this file is not supported yet

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