# symbol-enum

> Enum with symbols

Latest version **4.0.3** (published 2020-06-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install symbol-enum
pnpm add symbol-enum
yarn add symbol-enum
bun add symbol-enum
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.3 |
| Published | 2020-06-17 |
| First published | 2014-10-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6 |
| Dependencies | 0 |
| Unpacked size | 7.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Sean Marvi Oliver Genabe |
| Maintainers | seangenabe |
| Keywords | symbol, enum |

## Links

- npm: https://www.npmjs.com/package/symbol-enum
- Repository: https://github.com/seangenabe/symbol-enum
- Homepage: https://github.com/seangenabe/symbol-enum#readme
- Issues: https://github.com/seangenabe/symbol-enum/issues
- npm.io page: https://npm.io/package/symbol-enum

## Recent versions

- 4.0.3 (latest) — 2020-06-17
- 4.0.3-0 — 2016-12-05
- 4.0.2 — 2016-06-19
- 4.0.1 — 2016-06-19
- 4.0.0 — 2016-06-18
- 3.3.0 — 2016-06-13
- 3.2.2-0 — 2015-09-29
- 3.2.1 — 2015-09-29
- 3.2.0 — 2015-09-29
- 3.1.0 — 2015-08-05
- 2.0.1-0 — 2015-02-07
- 2.0.0 — 2015-02-07
- 3.0.0 — 2015-02-07
- 1.0.1-1 — 2014-10-26
- 1.0.1-0 — 2014-10-26
- … 1 more at https://npm.io/package/symbol-enum/versions

## README

# SymbolEnum

Enum with symbols.

[![npm](https://img.shields.io/npm/v/symbol-enum.svg?style=flat-square)](https://www.npmjs.com/package/symbol-enum)
[![Build Status](https://img.shields.io/travis/seangenabe/symbol-enum/master.svg?style=flat-square)](https://travis-ci.org/seangenabe/symbol-enum)
[![Coverage Status](https://img.shields.io/coveralls/seangenabe/symbol-enum/master.svg?style=flat-square)](https://coveralls.io/github/seangenabe/symbol-enum?branch=master)
[![Dependency Status](https://img.shields.io/david/seangenabe/symbol-enum.svg?style=flat-square)](https://david-dm.org/seangenabe/symbol-enum)
[![devDependency Status](https://img.shields.io/david/dev/seangenabe/symbol-enum.svg?style=flat-square)](https://david-dm.org/seangenabe/symbol-enum#info=devDependencies)
[![node](https://img.shields.io/node/v/symbol-enum.svg?style=flat-square)](https://nodejs.org/en/download/)

## Usage

```javascript
const SymbolEnum = require('symbol-enum')
```

### `#constructor(...keys)`

Creates a new Enum with the specified keys.

````javascript
const MyEnum = new SymbolEnum('a', 'b', 'c')
````

### `#[`*key*`]`

Retrieves the symbol corresponding to the key.

````javascript
const val = MyEnum.a
val // Symbol(a)
````

### `#[`*symbol*`]`

Retrieves the key corresponding to the symbol.

````javascript
MyEnum[val] // "a"
````

### `#[SymbolEnum.keys]()`

Returns an iterator that can be used to iterate through the keys.

```javascript
Array.from(MyEnum[SymbolEnum.keys]) // "[ a, b, c ]"
```

### `#[SymbolEnum.values]()`

Returns an iterator that can be used to iterate through the values.

```javascript
Array.from(MyEnum[SymbolEnum.values]) // "[ Symbol(a), Symbol(b), Symbol(c) ]"
```

### `#[SymbolEnum.has](key)`

Returns whether the enum contains the specified key.

```javascript
MyEnum[SymbolEnum.has]('b') // true
```

### `#[SymbolEnum.hasValue](value)`

Returns whether the enum contains the specified value.

```javascript
MyEnum[Symbol.hasValue](MyEnum.c) // true
```

### `#[SymbolEnum.size]`

Returns the number of keys passed to the constructor.

### 'Underscore'd properties

For your convenience, the following properties are also available directly on the object itself, but only if you don't specify `keys` and `values` as a member of the enum itself.

* `#[SymbolEnum.keys]` as `keys`
* `#[SymbolEnum.values]` as `values`
* `#[SymbolEnum.has]` as `has`
* `#[SymbolEnum.hasValue]` as `hasValue`

If you do, underscores will be prepended to the property name until it becomes available. For example, if you added both `keys` and `_keys` in the Enum, `#[SymbolEnum.keys]` will also be available at `#__keys`.

### Extends from null

`SymbolEnum` extends from null and does not have any string prototype methods so we have a clean slate. This means we don't inherit from `Object` and have any of its properties.

#### Exception: `#constructor`

Since we're using classes here, that means [`constructor`][Object.prototype.constructor] will still be defined by default. No worries, if you specify `constructor` as a key, it will be overridden.

## License

MIT

[Object.prototype.constructor]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor

---
_Source: https://npm.io/package/symbol-enum · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
