1.1.14 • Published 5 years ago

vanilla-enum v1.1.14

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

Instalation

npm install --save vanilla-enum
# or with yarn
yarn add vanilla-enum

Basic usage

Enum(object[, options])

import Enum from 'vanilla-enum'

const GENDER = new Enum({
  Male: {
    value: 1,
    description: "Male 🙋‍♂️"
  },
  Female: {
    value: 2,
    description: "Female 🙋‍♀️"
  }
}, {
  ignoreCase: false // default
})

GENDER.Male // 1
GENDER.getDescription(2) // "Female 🙋‍♀️"
GENDER.Male.toString() // "Male 🙋‍♂️"
GENDER.Female.is('Female 🙋‍♀️') // true
GENDER.Female.is('FEMALE 🙋‍♀️') // false
GENDER.Female.is('FEMALE 🙋‍♀️', { ignoreCase: true }) // true

Options

nametypedefaultdescription
ignoreCasebooleanfalseIgnore case when using the is function

Custom properties

All properties added at the enum item object have getters

import Enum from 'vanilla-enum'

const GENDER = new Enum({
  Male: {
    value: 1,
    description: "🙋‍♂️",
    isSelected: true
  },
  Female: {
    value: 2,
    description: "🙋‍♀️"
  }
})

GENDER.getIsSelected(GENDER.Male) // true
GENDER.getIsSelected(GENDER.Female) // undefined

License

Vanilla Enum uses the MIT license.

1.1.14

5 years ago

1.1.13

5 years ago

1.1.12

5 years ago

1.1.11

5 years ago

1.1.10

5 years ago

1.1.9

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago