# enumobj

> Define enum objects

Latest version **3.0.0** (published 2016-05-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install enumobj
pnpm add enumobj
yarn add enumobj
bun add enumobj
```

## 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 | 3.0.0 |
| Published | 2016-05-14 |
| First published | 2015-09-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Taka Okunishi |
| Maintainers | okunishinishi |
| Keywords | enum, type |

## Links

- npm: https://www.npmjs.com/package/enumobj
- Repository: https://github.com/okunishinishi/node-enumobj
- Homepage: https://github.com/okunishinishi/node-enumobj#readme
- Issues: https://github.com/okunishinishi/node-enumobj/issues
- npm.io page: https://npm.io/package/enumobj

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 3.0.0 (latest) — 2016-05-14
- 2.1.0 — 2016-03-13
- 2.0.4 — 2016-02-24
- 2.0.3 — 2016-02-24
- 2.0.2 — 2016-02-20
- 2.0.1 — 2016-02-20
- 2.0.0 — 2016-02-19
- 1.0.3 — 2015-09-01
- 1.0.2 — 2015-09-01
- 1.0.1 — 2015-09-01
- 1.0.0 — 2015-09-01

## README

enumobj
==========

<!---
This file is generated by ape-tmpl. Do not update manually.
--->

<!-- Badge Start -->
<a name="badges"></a>

[![Build Status][bd_travis_shield_url]][bd_travis_url]
[![Code Climate][bd_codeclimate_shield_url]][bd_codeclimate_url]
[![Code Coverage][bd_codeclimate_coverage_shield_url]][bd_codeclimate_url]
[![npm Version][bd_npm_shield_url]][bd_npm_url]
[![JS Standard][bd_standard_shield_url]][bd_standard_url]

[bd_repo_url]: https://github.com/okunishinishi/node-enumobj
[bd_travis_url]: http://travis-ci.org/okunishinishi/node-enumobj
[bd_travis_shield_url]: http://img.shields.io/travis/okunishinishi/node-enumobj.svg?style=flat
[bd_license_url]: https://github.com/okunishinishi/node-enumobj/blob/master/LICENSE
[bd_codeclimate_url]: http://codeclimate.com/github/okunishinishi/node-enumobj
[bd_codeclimate_shield_url]: http://img.shields.io/codeclimate/github/okunishinishi/node-enumobj.svg?style=flat
[bd_codeclimate_coverage_shield_url]: http://img.shields.io/codeclimate/coverage/github/okunishinishi/node-enumobj.svg?style=flat
[bd_gemnasium_url]: https://gemnasium.com/okunishinishi/node-enumobj
[bd_gemnasium_shield_url]: https://gemnasium.com/okunishinishi/node-enumobj.svg
[bd_npm_url]: http://www.npmjs.org/package/enumobj
[bd_npm_shield_url]: http://img.shields.io/npm/v/enumobj.svg?style=flat
[bd_standard_url]: http://standardjs.com/
[bd_standard_shield_url]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg

<!-- Badge End -->


<!-- Description Start -->
<a name="description"></a>

Define enum objects

<!-- Description End -->




<!-- Sections Start -->
<a name="sections"></a>

<!-- Section from "doc/guides/01.Installation.md.hbs" Start -->

<a name="section-doc-guides-01-installation-md"></a>
Installation
-----

```bash
npm install enumobj --save
```


<!-- Section from "doc/guides/01.Installation.md.hbs" End -->

<!-- Section from "doc/guides/02.Usage.md.hbs" Start -->

<a name="section-doc-guides-02-usage-md"></a>
Usage
-----

### Basic usage

```javascript
#!/usr/bin/env node

'use strict'

const enumobj = require('enumobj')

let levels = enumobj({
  TRACE: 0,
  DEBUG: 1,
  INFO: 2,
  ERROR: 3,
  FATAL: 4
})

console.log(levels) // -> {TRACE: 0, DEBUG: 1, INFO: 2, ERROR: 3, FATAL: 4}

function doSomething (level) {
  switch (level) {
    case levels.TRACE:
      /* ... */
      break;
    default:
      break;
  }
}

//--------------
// Get enum size
//--------------
console.log(levels.size()) // -> 5

//--------------
// Get a enum value
//--------------
console.log(levels.INFO) // -> 2
console.log(levels.get("INFO")) // -> 2
console.log(levels.get("_UNKNOWN_")) // -> undefined

//--------------
// Check key contained
//--------------
console.log(levels.has("ERROR")) // -> true
console.log(levels.has("_UNKNOWN_")) // -> false

//--------------
// Get key for value
//--------------
console.log(levels.has(0)) // -> "TRACE"
console.log(levels.has(100)) // -> undefined

```


### Add Descriptions

```javascript
#!/usr/bin/env node
'use strict'

const enumobj = require('enumobj')

let roles = enumobj({
  ADMIN: { $val: 1, $desc: "Nothing is off limits." },
  STAFF: { $val: 2, $desc: "Can view admin area, but not edit." },
  CUSTOMER: { $val: 3, $desc: "Can not access admin area." }
})

console.log(roles) // -> {ADMIN: 1, STAFF: 2, CUSTOMER:3}

console.log(roles.get('ADMIN')) // -> 1
console.log(roles.desc('ADMIN')) // -> "Nothing is off limits."
```


<!-- Section from "doc/guides/02.Usage.md.hbs" End -->


<!-- Sections Start -->


<!-- LICENSE Start -->
<a name="license"></a>

License
-------
This software is released under the [MIT License](https://github.com/okunishinishi/node-enumobj/blob/master/LICENSE).

<!-- LICENSE End -->

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