@pankod/typescript-enum-helper
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

You can use this enum-helper module to easier get the names and value in TypeScript.

Created by Pankod

Getting Started

$ npm install @pankod/typescript-enum-helper --save

Usage

import { EnumHelper } from '@pankod/typescript-enum-helper';

API

Enum Data

enum Gods {
    Pan,Ares,Zeus,Hermes,Apollo,Uranus,Achelous,Atlas,Castor,Chaos,Hades,Heracles,Poseidon
}
API Description Example Output
getKeys It should enum helper get keys array in enum [0, 1, 2, 3, 4]
getValues It should enum helper get values array in enum ['Pan','Ares','Zeus','Hermes','Apollo','Uranus','Achelous','Atlas','Castor','Chaos','Hades','Heracles','Poseidon']
getName It should get value in enum with enum helper Pan

Example in TypeScript

import { EnumHelper } from "@pankod/typescript-enum-helper"

enum Gods {
    Pan,
    Ares,
    Zeus,
    Hermes,
    Apollo,
    Uranus,
    Achelous,
    Atlas,
    Castor,
    Chaos,
    Hades,
    Heracles,
    Poseidon
}

// resultKeys will be equal to: [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ]
const resultKeys = EnumHelper.getKeys(Gods);

// resultValues  will be equal to:[ 'Pan','Ares','Zeus','Hermes','Apollo','Uranus','Achelous','Atlas','Castor','Chaos','Hades','Heracles','Poseidon' ]
const resultValues = EnumHelper.getValues(Gods);

// resultName  will be equal to: Pan
const resultName = EnumHelper.getName(Gods, 0);

Dependencies (0)

    Dev Dependencies (8)

    Package Sidebar

    Install

    npm i @pankod/typescript-enum-helper

    Weekly Downloads

    1

    Version

    1.0.6

    License

    MIT

    Unpacked Size

    9.85 kB

    Total Files

    16

    Last publish

    Collaborators

    • willico
    • alicanerdurmaz
    • omerfarukaplak
    • pankodbot
    • aliemirsen