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.1.1 to 5.2.0

build/enum.js

3

CHANGELOG.md
# Changelog
## Version [5.2.0](https://github.com/cedx/enum.js/compare/v5.1.1...v5.2.0)
- Added support for a redistributable bundle.
## Version [5.1.1](https://github.com/cedx/enum.js/compare/v5.1.0...v5.1.1)

@@ -4,0 +7,0 @@ - Fixed the [issue #2](https://github.com/cedx/enum.js/issues/2): relaxed the engine constraint.

@@ -8,3 +8,3 @@ # Installation

!!! warning
Enums for JS requires Node.js >= **10.9.0**.
Enums for JS requires Node.js >= **8.9.0**.

@@ -15,6 +15,6 @@ You can verify if you're already good to go with the following commands:

node --version
# v10.9.0
# v10.11.0
npm --version
# 6.2.0
# 6.4.1
```

@@ -41,1 +41,20 @@

```
!!! info
This library is packaged as [CommonJS modules](https://nodejs.org/api/modules.html).
To consume it in a browser, you must use a dedicated tool chain, like a build system coupled with a bundler.
### 3. Use it
See the [usage information](usage.md).
## Installing from a content delivery network
This library is also available as a ready-made bundle.
To install it, add this code snippet to the `<head>` of your HTML document:
```html
<!-- jsDelivr -->
<script src="https://cdn.jsdelivr.net/npm/@cedx/enum/build/enum.js"></script>
<!-- UNPKG -->
<script src="https://unpkg.com/@cedx/enum/build/enum.js"></script>
```

3

doc/usage.md
path: blob/master
source: src/enum.ts
# Usage

@@ -9,4 +10,2 @@

```ts
import {Enum} from '@cedx/enum';
/**

@@ -13,0 +12,0 @@ * Specifies the day of the week.

// @ts-ignore
import {Enum} from '@cedx/enum';
// tslint:disable:next-line: variable-name
/* tslint:disable: no-console variable-name */
const DayOfWeek = Enum.create<number>({

@@ -22,30 +22,30 @@ /* tslint:disable: object-literal-sort-keys */

// Check whether a value is defined among the enumerated type.
DayOfWeek.isDefined(DayOfWeek.sunday); // true
DayOfWeek.isDefined(123); // false
console.log(DayOfWeek.isDefined(DayOfWeek.sunday)); // true
console.log(DayOfWeek.isDefined(123)); // false
// Ensure that a value is defined among the enumerated type.
DayOfWeek.assert(DayOfWeek.monday); // DayOfWeek.monday
console.log(DayOfWeek.assert(DayOfWeek.monday)); // DayOfWeek.monday
DayOfWeek.assert(123); // (throws TypeError)
DayOfWeek.coerce(DayOfWeek.monday); // DayOfWeek.monday
DayOfWeek.coerce(123); // undefined
DayOfWeek.coerce(123, DayOfWeek.tuesday); // DayOfWeek.tuesday
console.log(DayOfWeek.coerce(DayOfWeek.monday)); // DayOfWeek.monday
console.log(DayOfWeek.coerce(123)); // undefined
console.log(DayOfWeek.coerce(123, DayOfWeek.tuesday)); // DayOfWeek.tuesday
// Get the zero-based position of a value in the enumerated type declaration.
DayOfWeek.getIndex(DayOfWeek.wednesday); // 3
DayOfWeek.getIndex(123); // -1
console.log(DayOfWeek.getIndex(DayOfWeek.wednesday)); // 3
console.log(DayOfWeek.getIndex(123)); // -1
// Get the name associated to an enumerated value.
DayOfWeek.getName(DayOfWeek.thursday); // "thursday"
DayOfWeek.getName(123); // "" (empty)
console.log(DayOfWeek.getName(DayOfWeek.thursday)); // "thursday"
console.log(DayOfWeek.getName(123)); // "" (empty)
// Get information about the enumerated type.
DayOfWeek.entries();
console.log(DayOfWeek.entries());
// [["sunday", 0], ["monday", 1], ["tuesday", 2], ["wednesday", 3], ["thursday", 4], ["friday", 5], ["saturday", 6]]
DayOfWeek.names();
console.log(DayOfWeek.names());
// ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"]
DayOfWeek.values();
console.log(DayOfWeek.values());
// [0, 1, 2, 3, 4, 5, 6]
}

@@ -13,3 +13,3 @@ "use strict";

static create(typeDef) {
const enumType = new class extends Enum {
const enumType = new class extends this {
};

@@ -16,0 +16,0 @@ for (const [key, value] of Object.entries(typeDef))

{
"author": "Cédric Belin <cedric@belin.io>",
"browser": "./build/enum.js",
"bugs": "https://github.com/cedx/enum.js/issues",

@@ -11,10 +12,12 @@ "description": "A simple implementation of enumerated types.",

"types": "./lib/index.d.ts",
"version": "5.1.1",
"version": "5.2.0",
"devDependencies": {
"@cedx/coveralls": "^8.0.0",
"@types/chai": "^4.1.4",
"@types/node": "^10.9.4",
"@types/chai": "^4.1.5",
"@types/node": "^10.11.0",
"babel-minify-webpack-plugin": "^0.3.1",
"chai": "^4.1.2",
"del": "^3.0.0",
"gulp": "^4.0.0",
"http-server": "^0.11.1",
"mocha": "^5.2.0",

@@ -27,3 +30,5 @@ "mocha-typescript": "^1.1.17",

"typedoc": "^0.12.0",
"typescript": "^3.0.3"
"typescript": "^3.0.3",
"webpack": "^4.19.1",
"webpack-cli": "^3.1.0"
},

@@ -30,0 +35,0 @@ "engines": {

# Enums for JS
![Runtime](https://img.shields.io/badge/node-%3E%3D10.9-brightgreen.svg) ![Release](https://img.shields.io/npm/v/@cedx/enum.svg) ![License](https://img.shields.io/npm/l/@cedx/enum.svg) ![Downloads](https://img.shields.io/npm/dt/@cedx/enum.svg) ![Dependencies](https://david-dm.org/cedx/enum.js.svg) ![Coverage](https://coveralls.io/repos/github/cedx/enum.js/badge.svg) ![Build](https://travis-ci.com/cedx/enum.js.svg)
![Runtime](https://img.shields.io/badge/node-%3E%3D8.9-brightgreen.svg) ![Release](https://img.shields.io/npm/v/@cedx/enum.svg) ![License](https://img.shields.io/npm/l/@cedx/enum.svg) ![Downloads](https://img.shields.io/npm/dt/@cedx/enum.svg) ![Dependencies](https://david-dm.org/cedx/enum.js.svg) ![Coverage](https://coveralls.io/repos/github/cedx/enum.js/badge.svg) ![Build](https://travis-ci.com/cedx/enum.js.svg)

@@ -4,0 +4,0 @@ Yet another implementation of enumerated types for [JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript).

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