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

easy-enum

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

easy-enum

Enums as easy as can be

  • 2.0.2
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

easy-enum

Enums so easy...

Install

npm install --save easy-enum

Usage

import Enum from 'easy-enum';

let Status = new Enum([
  'INCOMPLETE',
  'COMPLETE'
]);

Status.COMPLETE === 'COMPLETE'; // => true
typeof Status.COMPLETE === 'string'; // => true

// Don't need to serialize it? Use Symbols!
// You can use any value you want.

Status = new Enum({
  INCOMPLETE: Symbol(),
  COMPLETE: Symbol()
});

//Enums are immutable
Status.COMPLETE = 123; // => NOPE!

API

let Status = new Enum({
  INCOMPLETE: Symbol(),
  COMPLETE: Symbol()
});

// Whether a key exists
Status.has('COMPLETE'); // => true
Status.has('BLORG'); // => false

// Whether a value is an enum value
Status.is(Status.COMPLETE); // => true
Status.is('COMPLETE'); // => false

// Enums are iterable
for (let status of Status) {
  Status.is(status); // => true
}

Status.keys(); // Iterate over enum keys
Status.entries(); // Iterate over [key, value]
Status.values(); // Iterate over enum values

Keywords

FAQs

Package last updated on 11 May 2017

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

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