🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

enum-class

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package version was removed
This package version has been unpublished, mostly likely due to security reasons

enum-class

JavaScript enum type.

unpublished
Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
4
Maintainers
1
Weekly downloads
 
Created
Source

enum-class

JavaScript enumerable type.

Features

  • Enumerable constants can be checked for type safety using the instanceof operator.
    • MyEnum.contant instanceof MyEnum
  • Enumerable constants can have explicitly defined values.
    • new Enum({ foo: "value" })
  • Enumerable constants with the same name and value, in two different types, are not strictly equal.
    • Enum1.foo !== Enum2.foo
  • Enumerable types are frozen.

Example

const Enum = require("enum-class");

Without Values

var MyEnum = Enum.create("foo", "bar");

MyEnum.foo.valueOf(); // 0
MyEnum.bar.valueOf(); // 1

MyEnum.foo.toString(); // "foo"
MyEnum.bar.toString(); // "bar"

MyEnum.foo === 0; // false
MyEnum.foo === "foo"; // false
MyEnum.get("foo"); // MyEnum.foo

{ [foo.foo]: true }; // { "foo": true }

MyEnum.names; // [ "foo", "bar" ]
MyEnum.values; // [ 0, 1 ]
MyEnum.constants; // [ MyEnum.foo, MyEnum.bar ]

MyEnum instanceof Enum; // true
MyEnum.foo instanceof Enum; // true
MyEnum.foo instanceof MyEnum; // true

With Values

var MyEnum = Enum.create({ foo: 2, bar: 4 });

MyEnum.foo.valueOf(); // 2
MyEnum.foo.valueOf(); // 4

MyEnum.foo.toString(); // "foo"
MyEnum.bar.toString(); // "bar"

API

new Enum("foo", "bar", ...);

new Enum(["foo", "bar", ...]);

new Enum({ foo: 0, bar: 1, ... });

Enum.create("foo", "bar", ...);

Enum.create(["foo", "bar", ...]);

Enum.create({ foo: 0, bar: 1, ... });

Return a new Enum instance with the defined constants.

enum.names

Return a list of the enum names.

enum.values

Return a list of the enum values.

enum.constants

Return a list of the enum constants.

enum.get(name)

Return the enum constant that matches name.

enum.[constant].toString()

Return the constant name string.

enum.[constant].valueOf()

Return the contant value.

Keywords

enumerable

FAQs

Package last updated on 22 Feb 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts