npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

strict-enum

v1.0.3

Published

A JavaScript enum implementation

Readme

strict-enum

A JavaScript enum implementation, closely resembling that of other languages.

Install

	npm install strict-enum

##Syntax

The package exposes a single default object. The Enum constructor.

var Enum = require('strict-enum');

It can be used with or without the new keyword and will return the exact same result either way. The method without new is recommended to keep code cleaner.

new Enum('ENUM_ITEM')
// Equivalent to
Enum('ENUM_ITEM')

There are three ways to create Enums. By passing Strings, an Array or an Object. It's recommended to use uppercase for both the Enum name and values, using underscores got gaps.

var COLORS = Enum('RED', 'BLUE', 'GREEN');
var SIZES = Enum(['SMALL', 'MEDIUM', 'LARGE']);
var PET_TYPES = Enum({ DOG: 'CANINE', CAT: 'FELINE' });

// To access a specific Enum property
COLORS.RED // ==> Symbol(RED);

As you can see, strict-enum turns all property values to Symbols. As for the different methods The first two methods are identical and as such, the first one is recommended to keep code clean. The third method not only sets the name of the Enum, but also the identifier. As you'll find out the enum identifiers are mostly useful for debugging purposes.

The difference between this constructor and other enum libraries, and the reason 'strict' makes up half of its name is that all declared properties are unique, constant and enumerable.

// This means that given these Enums
var NUMBERS = Enum('ONE', 'TWO', 'THREE');
var POSITIONS = Enum('ONE', 'TWO', 'THREE');

// Despite having a seemingly equal value
// associated with their 'ONE' member
NUMBERS.ONE // ==> Symbol(ONE)
NUMBERS.ONE //

// If we try to compare items from both
NUMBERS.ONE === NUMBERS.ONE // ==> true
NUMBERS.ONE === POSITIONS.ONE // ==> false
// We see that the Symbol will only match with itself.

// The reason for this is that Symbol are unique

// Additionally after an Enum is created its frozen and
// values can no longer be set, added or removed
NUMBERS.ONE = 'Something else';
NUMBERS.FOUR = Symbol(4);
delete NUMBERS.TWO;

// It remains unchanged
NUMBERS // ==> { ONE: Symbol(ONE), TWO: Symbol(TWO), THREE: Symbol(THREE) }

// Enums can be enumarated. The only properties they'll return are their Enum members.
Object.keys(POSITIONS) // ==> ['ONE', 'TWO', 'THREE'];

Usage

Strict Enums might seem limiting, but they help you stick to good practices and standards. Here's a real world application for them, using them to define a State Machine.

var PLAYER_STATES = ('IDLE', 'WALKING', 'RUNNING', 'JUMPING', 'FALLING', 'ATTACKING');

player.state = PLAYER_STATES.IDLE;

// Define different behaviors
switch(state) {
	case PLAYER_STATES.IDLE:
	// Callback for idling
	case PLAYER_STATES.WALKING:
	// Callback for walking
	case PLAYER_STATES.RUNNING:
	// Callback for running
	case PLAYER_STATES.JUMPING:
	// Callback for jumping
	// etc..
}