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

@cedx/enum

Package Overview
Dependencies
Maintainers
1
Versions
37
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 5.3.0 to 5.4.0

build/enum.min.js

45

build/enum.js

@@ -1,1 +0,44 @@

window.Enum=function(a){function b(d){if(c[d])return c[d].exports;var e=c[d]={i:d,l:!1,exports:{}};return a[d].call(e.exports,e,e.exports,b),e.l=!0,e.exports}var c={};return b.m=a,b.c=c,b.d=function(a,c,d){b.o(a,c)||Object.defineProperty(a,c,{enumerable:!0,get:d})},b.r=function(a){'undefined'!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(a,Symbol.toStringTag,{value:'Module'}),Object.defineProperty(a,'__esModule',{value:!0})},b.t=function(a,c){if(1&c&&(a=b(a)),8&c)return a;if(4&c&&'object'==typeof a&&a&&a.__esModule)return a;var d=Object.create(null);if(b.r(d),Object.defineProperty(d,'default',{enumerable:!0,value:a}),2&c&&'string'!=typeof a)for(var e in a)b.d(d,e,function(b){return a[b]}.bind(null,e));return d},b.n=function(a){var c=a&&a.__esModule?function(){return a['default']}:function(){return a};return b.d(c,'a',c),c},b.o=function(a,b){return Object.prototype.hasOwnProperty.call(a,b)},b.p='',b(b.s=0)}([function(a,b,c){'use strict';Object.defineProperty(b,'__esModule',{value:!0}),function(a){for(var c in a)b.hasOwnProperty(c)||(b[c]=a[c])}(c(1))},function(a,b){'use strict';Object.defineProperty(b,'__esModule',{value:!0});b.Enum=class{static create(a){const b=new class extends this{};for(const[c,d]of Object.entries(a))a.hasOwnProperty(c)&&['boolean','number','string'].includes(typeof d)&&(b[c]=d);return Object.freeze(b)}assert(a){if(this.isDefined(a))return a;throw new TypeError(`Invalid enumerated value: ${a}`)}coerce(a,b){return this.isDefined(a)?a:b}entries(){return Object.entries(this)}isDefined(a){return this.values().includes(a)}getIndex(a){return this.values().indexOf(a)}getName(a){const b=this.getIndex(a);return 0<=b?this.names()[b]:''}names(){return Object.keys(this)}values(){return Object.values(this)}}}]).Enum;
(function (exports) {
'use strict';
class Enum {
static create(typeDef) {
const enumType = new class extends Enum {
};
for (const [key, value] of Object.entries(typeDef))
if (typeDef.hasOwnProperty(key) && ['boolean', 'number', 'string'].includes(typeof value))
enumType[key] = value;
return Object.freeze(enumType);
}
assert(value) {
if (this.isDefined(value))
return value;
throw new TypeError(`Invalid enumerated value: ${value}`);
}
coerce(value, defaultValue) {
return this.isDefined(value) ? value : defaultValue;
}
entries() {
return Object.entries(this);
}
isDefined(value) {
return this.values().includes(value);
}
getIndex(value) {
return this.values().indexOf(value);
}
getName(value) {
const index = this.getIndex(value);
return index >= 0 ? this.names()[index] : '';
}
names() {
return Object.keys(this);
}
values() {
return Object.values(this);
}
}
exports.Enum = Enum;
}(this.window = this.window || {}));
# Changelog
## Version [5.4.0](https://github.com/cedx/enum.js/compare/v5.3.0...v5.4.0)
- Added support for [ECMAScript modules](https://nodejs.org/api/esm.html).
- Replaced [Webpack](https://webpack.js.org) bundler by [Rollup](https://rollupjs.org) and [Babel Minify](https://github.com/babel/minify).
- Updated the package dependencies.
## Version [5.3.0](https://github.com/cedx/enum.js/compare/v5.2.0...v5.3.0)

@@ -4,0 +9,0 @@ - Updated the package dependencies.

# Changelog
## Version [5.4.0](https://github.com/cedx/enum.js/compare/v5.3.0...v5.4.0)
- Added support for [ECMAScript modules](https://nodejs.org/api/esm.html).
- Replaced [Webpack](https://webpack.js.org) bundler by [Rollup](https://rollupjs.org) and [Babel Minify](https://github.com/babel/minify).
- Updated the package dependencies.
## Version [5.3.0](https://github.com/cedx/enum.js/compare/v5.2.0...v5.3.0)

@@ -4,0 +9,0 @@ - Updated the package dependencies.

19

doc/installation.md

@@ -14,6 +14,6 @@ # Installation

node --version
# v11.6.0
# v11.13.0
npm --version
# 6.5.0
# 6.7.0
```

@@ -42,3 +42,3 @@

!!! info
This library is packaged as [CommonJS modules](https://nodejs.org/api/modules.html).
This library is packaged as [CommonJS modules](https://nodejs.org/api/modules.html) (`.js` files) and [ECMAScript modules](https://nodejs.org/api/esm.html) (`.mjs` files).
To consume it in a browser, you must use a dedicated tool chain, like a build system coupled with a bundler.

@@ -55,6 +55,15 @@

<!-- jsDelivr -->
<script src="https://cdn.jsdelivr.net/npm/@cedx/enum/build/enum.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@cedx/enum/build/enum.min.js"></script>
<!-- UNPKG -->
<script src="https://unpkg.com/@cedx/enum/build/enum.js"></script>
<script src="https://unpkg.com/@cedx/enum/build/enum.min.js"></script>
```
The `Enum` class from this library is exposed as a property on the `window` global object:
```html
<script>
// Optional: `Enum` is a global property.
const {Enum} = window;
</script>
```

@@ -27,3 +27,3 @@ path: blob/master

!!! warning
Only scalar values (boolean, numbers, and strings) are retained
Only scalar values (booleans, numbers, and strings) are retained
when iterating on the enumerable properties of the provided object.

@@ -30,0 +30,0 @@

@@ -1,75 +0,16 @@

/**
* Defines the shape of an enumerated value.
*/
export declare type EnumValue = boolean | number | string;
/**
* Defines the shape of an enumerated type.
*/
export interface EnumLike<T extends EnumValue> {
/**
* Gets the enumerated value corresponding to the given key.
*/
[key: string]: T;
}
/**
* Provides helper methods for enumerations.
*/
export declare abstract class Enum<T extends EnumValue> {
/**
* Gets the enumerated value corresponding to the given key.
*/
[key: string]: any;
/**
* Creates an enumeration from the specified type definition.
* @param typeDef An object defining the shape of the enumerated type.
* @return The newly created enumeration.
*/
static create<T extends EnumValue>(typeDef: EnumLike<T>): Enum<T>;
/**
* Returns the specified value if it exists in the specified enumeration, otherwise throws an exception.
* @param value The value of a constant in the specified enumeration.
* @return The specified enumerated constant.
* @throws {TypeError} No such constant was found.
*/
assert(value: T): T;
/**
* Returns the specified value if it exists in the specified enumeration, otherwise returns the given default value.
* @param value The value of a constant in the specified enumeration.
* @param defaultValue The default value to return if the specified constant does not exist.
* @return The specified enumerated constant, or the default value if no such constant is found.
*/
coerce(value: T, defaultValue?: T): T | undefined;
/**
* Gets an array of the `[name, value]` pairs of the constants in the specified enumeration.
* @return An array that contains the `[name, value]` pairs of the constants in the specified enumeration.
*/
entries(): Array<[string, T]>;
/**
* Gets an indication whether a constant with a specified value exists in the specified enumeration.
* @param value The value of a constant in the specified enumeration.
* @return `true` if a constant in the specified enumeration has the specified value, otherwise `false`.
*/
isDefined(value: T): boolean;
/**
* Gets the zero-based position of the constant in the specified enumeration that has the specified value.
* @param value The value of a constant in the specified enumeration.
* @return The zero-based position of the constant that has the specified value, or `-1` if no such constant is found.
*/
getIndex(value: T): number;
/**
* Gets the name of the constant in the specified enumeration that has the specified value.
* @param value The value of a constant in the specified enumeration.
* @return A string containing the name of the constant that has the specified value, or an empty string if no such constant is found.
*/
getName(value: T): string;
/**
* Gets an array of the names of the constants in the specified enumeration.
* @return An array that contains the names of the constants in the specified enumeration.
*/
names(): string[];
/**
* Gets an array of the values of the constants in the specified enumeration.
* @return An array that contains the values of the constants in the specified enumeration.
*/
values(): T[];
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Provides helper methods for enumerations.
*/
class Enum {
/**
* Creates an enumeration from the specified type definition.
* @param typeDef An object defining the shape of the enumerated type.
* @return The newly created enumeration.
*/
static create(typeDef) {
const enumType = new class extends this {
const enumType = new class extends Enum {
};

@@ -20,8 +12,2 @@ for (const [key, value] of Object.entries(typeDef))

}
/**
* Returns the specified value if it exists in the specified enumeration, otherwise throws an exception.
* @param value The value of a constant in the specified enumeration.
* @return The specified enumerated constant.
* @throws {TypeError} No such constant was found.
*/
assert(value) {

@@ -32,39 +18,14 @@ if (this.isDefined(value))

}
/**
* Returns the specified value if it exists in the specified enumeration, otherwise returns the given default value.
* @param value The value of a constant in the specified enumeration.
* @param defaultValue The default value to return if the specified constant does not exist.
* @return The specified enumerated constant, or the default value if no such constant is found.
*/
coerce(value, defaultValue) {
return this.isDefined(value) ? value : defaultValue;
}
/**
* Gets an array of the `[name, value]` pairs of the constants in the specified enumeration.
* @return An array that contains the `[name, value]` pairs of the constants in the specified enumeration.
*/
entries() {
return Object.entries(this);
}
/**
* Gets an indication whether a constant with a specified value exists in the specified enumeration.
* @param value The value of a constant in the specified enumeration.
* @return `true` if a constant in the specified enumeration has the specified value, otherwise `false`.
*/
isDefined(value) {
return this.values().includes(value);
}
/**
* Gets the zero-based position of the constant in the specified enumeration that has the specified value.
* @param value The value of a constant in the specified enumeration.
* @return The zero-based position of the constant that has the specified value, or `-1` if no such constant is found.
*/
getIndex(value) {
return this.values().indexOf(value);
}
/**
* Gets the name of the constant in the specified enumeration that has the specified value.
* @param value The value of a constant in the specified enumeration.
* @return A string containing the name of the constant that has the specified value, or an empty string if no such constant is found.
*/
getName(value) {

@@ -74,13 +35,5 @@ const index = this.getIndex(value);

}
/**
* Gets an array of the names of the constants in the specified enumeration.
* @return An array that contains the names of the constants in the specified enumeration.
*/
names() {
return Object.keys(this);
}
/**
* Gets an array of the values of the constants in the specified enumeration.
* @return An array that contains the values of the constants in the specified enumeration.
*/
values() {

@@ -87,0 +40,0 @@ return Object.values(this);

{
"browser": "./build/enum.js",
"bugs": "https://github.com/cedx/enum.js/issues",

@@ -7,7 +6,8 @@ "description": "A simple implementation of enumerated types.",

"license": "MIT",
"main": "./lib/index.js",
"main": "lib/index",
"module": "lib/index.mjs",
"name": "@cedx/enum",
"repository": "github:cedx/enum.js",
"types": "./lib/index.d.ts",
"version": "5.3.0",
"types": "lib/index.d.ts",
"version": "5.4.0",
"author": {

@@ -19,20 +19,25 @@ "email": "cedric@belin.io",

"devDependencies": {
"@cedx/coveralls": "^8.3.0",
"@cedx/coveralls": "^8.5.0",
"@types/chai": "^4.1.7",
"@types/node": "^10.12.18",
"babel-minify-webpack-plugin": "^0.3.1",
"@types/node": "^11.13.0",
"babel-minify": "^0.5.0",
"chai": "^4.2.0",
"del": "^3.0.0",
"del": "^4.1.0",
"gulp": "^4.0.0",
"gulp-rename": "^1.4.0",
"http-server": "^0.11.1",
"mocha": "^5.2.0",
"karma": "^4.0.1",
"karma-chrome-launcher": "^2.2.0",
"karma-mocha": "^1.3.0",
"karma-typescript": "^4.0.0",
"mocha": "^6.0.2",
"mocha-typescript": "^1.1.17",
"nyc": "^13.1.0",
"source-map-support": "^0.5.10",
"ts-node": "^7.0.1",
"tslint": "^5.12.1",
"typedoc": "^0.14.1",
"typescript": "^3.2.2",
"webpack": "^4.28.4",
"webpack-cli": "^3.2.1"
"nyc": "^13.3.0",
"rollup": "^1.9.0",
"rollup-plugin-node-resolve": "^4.1.0",
"source-map-support": "^0.5.11",
"ts-node": "^8.0.3",
"tslint": "^5.15.0",
"typedoc": "^0.14.2",
"typescript": "^3.4.1"
},

@@ -54,4 +59,4 @@ "engines": {

"start": "gulp watch",
"test": "gulp test"
"test": "gulp test:node"
}
}

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