1.0.4 • Published 3 years ago

com.recoyxgroup.javascript.enum v1.0.4

Weekly downloads
4
License
ISC
Repository
github
Last release
3 years ago

JavaScriptEnum

This package allows defining flexible enum classes.

import { Enum, FlagsEnum } from 'com.recoyxgroup.javascript.enum';

// regular enums

const E = Enum('E', [
	'FOO_CONST',

	// const definition can manually specify a (String, Number) pair
	['BAR_CONST', 1],
	['BAR2_CONST', 10, 'barTwo'],
]);

// flags enums

const E = FlagsEnum('E', [
	'FA',
	'FB',
]);

Applying enums:

class C {
	_e = E(undefined);
	get e() { return this._e }
	set e(v) { this._e = E(v) }
}

var o = new C;

o.e = 'fa';
o.e = ['fa', 'fb'];
o.e = undefined; // o.e = 0
o.e = E.FA;

console.log( o.e == 'fa' );
console.log( 'fa' in o.e );

Instance properties:

  • number:Number

FlagsEnum products > Instance methods:

  • set(arg:E):E
  • exclude(arg:E):E
  • toggle(arg:E):E
  • filter(arg:E):E
  • toString():String

Related utilities:

  • com.recoyxgroup.javascript.enum.JSON.stringify(value:*, options:* = undefined):String This is a JSON.stringify() specialization that will convert any enum object to a Number.
1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

4 years ago

1.0.0

4 years ago