2023.3.19 • Published 1 year ago

enum2array v2023.3.19

Weekly downloads
80
License
MIT
Repository
github
Last release
1 year ago

Enum2Array

npm npm CodeQL Analyze Build & Test dependabot

GitHub Repo stars

A function to help converting enums to an array. Define an enum then use this function to convert that enum to an array.

Installation

npm i enum2array

Usage

Define an enum for testing

export enum CustomType {
    TypeA = 1,
    TypeB = 2,
    TypeC = 3,
    TypeD = 4,
}

export enum CustomValue {
    TypeA = "valueA",
    TypeB = "valueB",
    TypeC = "valueC",
    TypeD = "valueD",
}

Usage enum2array function

import { enum2array } from "enum2array";

console.log(enum2array(CustomType));

console.log(enum2array(CustomValue));

Results

That is the result about function with "CustomType" enum

(4) [ArrayValue, ArrayValue, ArrayValue, ArrayValue]
0: ArrayValue {title: "TypeA", value: 1}
1: ArrayValue {title: "TypeB", value: 2}
2: ArrayValue {title: "TypeC", value: 3}
3: ArrayValue {title: "TypeD", value: 4}
length: 4
__proto__: Array(0)

That is the result about function with "CustomValue" enum

(4) [ArrayValue, ArrayValue, ArrayValue, ArrayValue]
0: ArrayValue {title: "TypeA", value: "valueA"}
1: ArrayValue {title: "TypeB", value: "valueB"}
2: ArrayValue {title: "TypeC", value: "valueC"}
3: ArrayValue {title: "TypeD", value: "valueD"}
length: 4
__proto__: Array(0)

Want to contribute?

You can read and follow our CONTRIBUTING.md and report it using GitHub Issues! for reporting bugs, suggesting enhancements, bugfixes, new features and extras are welcome.

Contributors ✨

All Contributors

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

2023.3.19

1 year ago

2022.12.5

1 year ago

2022.10.23

2 years ago

2023.1.2

1 year ago

2022.11.11

2 years ago

2022.9.10

2 years ago

1.1.29

2 years ago

1.1.30

2 years ago

2022.8.6

2 years ago

1.1.28

2 years ago

1.1.27

2 years ago

1.1.26

2 years ago

1.1.25

2 years ago

1.1.23

2 years ago

1.1.22

2 years ago

1.1.24

2 years ago

1.1.21

3 years ago

1.1.19

3 years ago

1.1.20

3 years ago

1.1.18

3 years ago

1.1.17

3 years ago

1.1.16

3 years ago

1.1.15

3 years ago

1.1.14

3 years ago

1.1.13

3 years ago

1.1.12

3 years ago

1.1.11

3 years ago

1.1.10

3 years ago

1.1.9

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.4

3 years ago

1.1.1

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.0

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago