Skip to content

zhaber/symbol-enum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 

Repository files navigation

Javascript Enum

An enum data type that is based on the javascript symbol primitive type. Using symbol values ensures type safety of the enum as each symbol value is guaranteed by javascript to be unique.

Example:

const color = new Enum('RED', 'BLUE')

color.RED.toString() // 'Symbol(RED)'
color.getName(color.RED) // 'RED'
color.size // 2
color.values() // Symbol(RED), Symbol(BLUE)
color.toString() // 'RED,BLUE'
color.valueOf('RED') // Symbol(RED)

Plunker demo

About

Javascript enumeration type based on symbols

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published