├── .all-contributorsrc ├── .github ├── FUNDING.yml ├── dependabot.yml └── workflows │ ├── build-test.yml │ └── codeql-analysis.yml ├── .gitignore ├── .prettierrc ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── assets └── enum2array.svg ├── jestconfig.json ├── package-lock.json ├── package.json ├── scripts ├── checkTag.sh └── run.sh ├── src ├── array-value.ts └── index.ts ├── test ├── array-value.test.ts └── index.test.ts ├── tsconfig.json └── tslint.json /.all-contributorsrc: -------------------------------------------------------------------------------- 1 | { 2 | "files": [ 3 | "README.md" 4 | ], 5 | "imageSize": 100, 6 | "commit": false, 7 | "commitConvention": "angular", 8 | "contributors": [ 9 | { 10 | "login": "sametcelikbicak", 11 | "name": "Samet ÇELİKBIÇAK", 12 | "avatar_url": "https://avatars.githubusercontent.com/u/5312741?v=4", 13 | "profile": "https://sametcelikbicak.com/", 14 | "contributions": [ 15 | "infra", 16 | "code", 17 | "bug", 18 | "doc", 19 | "example", 20 | "maintenance", 21 | "test" 22 | ] 23 | } 24 | ], 25 | "contributorsPerLine": 7, 26 | "skipCi": true, 27 | "repoType": "github", 28 | "repoHost": "https://github.com", 29 | "projectName": "enum2array", 30 | "projectOwner": "sametcelikbicak" 31 | } 32 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: ['https://www.buymeacoffee.com/sametcelikbicak']# Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | 4 | # Maintain dependencies for GitHub Actions 5 | - package-ecosystem: "github-actions" 6 | directory: "/" 7 | schedule: 8 | interval: "monthly" 9 | 10 | # Maintain dependencies for npm 11 | - package-ecosystem: "npm" 12 | directory: "/" 13 | schedule: 14 | interval: "monthly" -------------------------------------------------------------------------------- /.github/workflows/build-test.yml: -------------------------------------------------------------------------------- 1 | name: Build & Test 2 | 3 | on: [ push ] 4 | 5 | jobs: 6 | build: 7 | name: Build & Test 8 | runs-on: ubuntu-latest 9 | steps: 10 | - name: Checkout repository 11 | uses: actions/checkout@v3 12 | 13 | - name: Initialize Node 14 | uses: actions/setup-node@v3 15 | with: 16 | node-version: 12 17 | registry-url: https://registry.npmjs.org/ 18 | 19 | 20 | - name: Install deps 21 | run: npm ci 22 | 23 | - name: Build application 24 | run: npm run build 25 | 26 | - name: Run tests 27 | run: npm run test -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | name: "CodeQL Analyze" 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | schedule: 9 | - cron: '0 0 * * *' # Runs at 00:00 UTC every day 10 | 11 | jobs: 12 | analyze: 13 | name: Analyze 14 | runs-on: ubuntu-latest 15 | permissions: 16 | actions: read 17 | contents: read 18 | security-events: write 19 | 20 | strategy: 21 | fail-fast: false 22 | matrix: 23 | language: [ 'javascript' ] 24 | 25 | steps: 26 | - name: Checkout repository 27 | uses: actions/checkout@v3 28 | 29 | - name: Initialize CodeQL 30 | uses: github/codeql-action/init@v2 31 | with: 32 | languages: ${{ matrix.language }} 33 | 34 | - name: Autobuild 35 | uses: github/codeql-action/autobuild@v2 36 | 37 | - name: Perform CodeQL Analysis 38 | uses: github/codeql-action/analyze@v2 39 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | /lib 3 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 120, 3 | "trailingComma": "all", 4 | "singleQuote": true 5 | } -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # enum2array function changes 2 | 3 | ## 2023.3.19 4 | - Fix dependabot issues 5 | ## 2023.1.2 6 | - Fix dependabot issues 7 | ## 2022.12.05 8 | - Add stars badge 9 | - Fix dependabot issues 10 | ## 2022.11.11 11 | - Add CODE_OF_CONDUCT file 12 | - Add CONTRIBUTING file 13 | - Update README file 14 | ## 2022.10.23 15 | - Fix dependabot issues 16 | ## 2022.09.10 17 | - Fix dependabot issues 18 | ## 2022.08.06 19 | - Change version number to year.month.day instead of major.minor.patch numbers. 20 | ## 1.1.30 21 | - Fix dependabot issues 22 | ## 1.1.29 23 | - Fix dependabot issues 24 | ## 1.1.28 25 | - Fix dependabot issues 26 | ## 1.1.27 27 | - Fix dependabot issues 28 | ## 1.1.26 29 | - Fix dependabot issues 30 | ## 1.1.25 31 | - Fix dependabot issues 32 | ## 1.1.24 33 | - Fix dependabot issues 34 | ## 1.1.23 35 | - Fix dependabot issues 36 | ## 1.1.22 37 | - Fix dependabot issues 38 | - Update README 39 | - Deactivate NPM Publish script 40 | ## 1.1.21 41 | - Fix dependabot issues 42 | ## 1.1.20 43 | - Add logo 44 | ## 1.1.19 45 | - Fix dependabot issues 46 | ## 1.1.18 47 | - Fix dependabot issues 48 | - Update README 49 | - Add missing `v.1.1.17` to CHANGELOG 50 | ## 1.1.17 51 | - Add GitHub action for test 52 | - Update README 53 | ## 1.1.16 54 | - Update README 55 | ## 1.1.15 56 | - Update README 57 | ## 1.1.14 58 | - Add CHANGELOG file 59 | - Update README file with CodeQL Analyze badge 60 | - Rename `publish.sh` to `checkTag.sh` 61 | - Update `npm-publish.yml` 62 | ## 1.1.13 63 | - Update action scripts with git tag control 64 | ## 1.1.12 65 | - Fix dependabot issues 66 | ## 1.1.11 67 | - Fix vulnerability issue 68 | ## 1.1.10 69 | - Fix dependabot issues 70 | ## 1.1.9 71 | - 72 | ## 1.1.7 73 | - 74 | ## 1.1.6 75 | - Fix dependabot issues 76 | - Fix Jest issues 77 | ## 1.1.4 78 | - 79 | ## 1.1.3 80 | - 81 | ## 1.1.2 82 | - 83 | ## 1.1.1 84 | - 85 | ## 1.1.0 86 | - 87 | ## 1.0.8 88 | - 89 | ## 1.0.7 90 | - 91 | ## 1.0.6 92 | - 93 | ## 1.0.5 94 | - 95 | ## 1.0.4 96 | - 97 | ## 1.0.3 98 | - 99 | ## 1.0.2 100 | - 101 | ## 1.0.1 102 | - 103 | ## 1.0.0 104 | - First version released 105 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity 10 | and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the 26 | overall community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | . 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series 86 | of actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or 93 | permanent ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within 113 | the community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.0, available at 119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 120 | 121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 122 | enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | https://www.contributor-covenant.org/faq. Translations are available at 128 | https://www.contributor-covenant.org/translations. -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to [enum2array](https://github.com/sametcelikbicak/enum2array) 2 | 3 | First off, thanks for taking the time to contribute! 🎉👍 4 | 5 | ## How Can I Contribute? 6 | It is publicly open for any contribution. Reporting bugs, suggesting 7 | enhancements, bugfixes, new features and extras are welcome. 8 | 9 | - To contribute to code: 10 | - Fork the repo 11 | - Create a branch for your change(s) 12 | - Push your change(s) to your fork 13 | - Open a Pull Request(PR). 14 | - To report a bug: If something does not work, please report it using 15 | [GitHub Issues](https://github.com/sametcelikbicak/enum2array/issues). 16 | 17 | ## Development setup 🛠 18 | Install dependencies first. 19 | ``` 20 | npm install 21 | ``` 22 | Build your changes. 23 | ``` 24 | npm run build 25 | ``` 26 | Run the test after your changes. 27 | ``` 28 | npm run test 29 | ``` 30 | Before push your changes run lint and format scripts. 31 | ``` 32 | npm run lint 33 | npm run format 34 | ``` 35 | 36 | ## Testing your changes 🧪 37 | After your changes and run the build script you can install your changes locally and test the changes. First build your changes. 38 | ``` 39 | npm run build 40 | ``` 41 | Then pack your package by running below command root of your folder. 42 | ``` 43 | npm pack 44 | ``` 45 | After all you can use newly created package in your test app to verify your changes, just take newly created package path and go to your test app and run below command. 46 | ``` 47 | npm install 48 | # i.e: npm install /Users/sametcelikbicak/enum2array/enum2array-2022.10.23.tgz 49 | ```` 50 | 51 | ### Code of Conduct 52 | This project and everyone participating in it is governed by the 53 | [Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to 54 | uphold this code. 55 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Samet ÇELİKBIÇAK 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | Logo 3 | 4 | # Enum2Array 5 | ![npm](https://img.shields.io/npm/v/enum2array?color=g&label=enum2array&logo=npm) ![npm](https://img.shields.io/npm/dy/enum2array?label=Downloads&logo=npm) [![CodeQL Analyze](https://github.com/sametcelikbicak/enum2array/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/sametcelikbicak/enum2array/actions/workflows/codeql-analysis.yml) [![Build & Test](https://github.com/sametcelikbicak/enum2array/actions/workflows/build-test.yml/badge.svg)](https://github.com/sametcelikbicak/enum2array/actions/workflows/build-test.yml) ![dependabot](https://img.shields.io/badge/Dependabot-active-g?logo=dependabot) 6 | 7 | ![GitHub Repo stars](https://img.shields.io/github/stars/sametcelikbicak/enum2array?style=social) 8 | 9 | A function to help converting enums to an array. Define an enum then use this function to convert that enum to an array. 10 |
11 | 12 | ## Installation 13 | 14 | ``` 15 | npm i enum2array 16 | ``` 17 | 18 | ## Usage 19 | 20 | ### Define an enum for testing 21 | ```typescript 22 | export enum CustomType { 23 | TypeA = 1, 24 | TypeB = 2, 25 | TypeC = 3, 26 | TypeD = 4, 27 | } 28 | 29 | export enum CustomValue { 30 | TypeA = "valueA", 31 | TypeB = "valueB", 32 | TypeC = "valueC", 33 | TypeD = "valueD", 34 | } 35 | ``` 36 | 37 | ### Usage enum2array function 38 | 39 | ```typescript 40 | import { enum2array } from "enum2array"; 41 | 42 | console.log(enum2array(CustomType)); 43 | 44 | console.log(enum2array(CustomValue)); 45 | ``` 46 | 47 | ## Results 48 | 49 | ### That is the result about function with "CustomType" enum 50 | 51 | ``` 52 | (4) [ArrayValue, ArrayValue, ArrayValue, ArrayValue] 53 | 0: ArrayValue {title: "TypeA", value: 1} 54 | 1: ArrayValue {title: "TypeB", value: 2} 55 | 2: ArrayValue {title: "TypeC", value: 3} 56 | 3: ArrayValue {title: "TypeD", value: 4} 57 | length: 4 58 | __proto__: Array(0) 59 | ``` 60 | 61 | ### That is the result about function with "CustomValue" enum 62 | 63 | ``` 64 | (4) [ArrayValue, ArrayValue, ArrayValue, ArrayValue] 65 | 0: ArrayValue {title: "TypeA", value: "valueA"} 66 | 1: ArrayValue {title: "TypeB", value: "valueB"} 67 | 2: ArrayValue {title: "TypeC", value: "valueC"} 68 | 3: ArrayValue {title: "TypeD", value: "valueD"} 69 | length: 4 70 | __proto__: Array(0) 71 | ``` 72 | 73 | ### Want to contribute? 74 | You can read and follow our [CONTRIBUTING.md](CONTRIBUTING.md) and report it using 75 | [GitHub Issues](https://github.com/sametcelikbicak/enum2array/issues)! for reporting bugs, suggesting enhancements, bugfixes, new features and extras are welcome. 76 | 77 | 78 | ## Contributors ✨ 79 | 80 | [![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors-) 81 | 82 | Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)): 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 |
Samet ÇELİKBIÇAK
Samet ÇELİKBIÇAK

🚇 💻 🐛 📖 💡 🚧 ⚠️
94 | 95 | 96 | 97 | 98 | 99 | 100 | This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! 101 | 102 | -------------------------------------------------------------------------------- /assets/enum2array.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /jestconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "transform": { 3 | "^.+\\.(t|j)s?$": "ts-jest" 4 | }, 5 | "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(js?|ts?)$", 6 | "moduleFileExtensions": [ 7 | "ts", 8 | "tsx", 9 | "js", 10 | "jsx", 11 | "json", 12 | "node" 13 | ] 14 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "enum2array", 3 | "version": "2023.3.19", 4 | "description": "A function to help converting enums to an array", 5 | "main": "lib/index.js", 6 | "types": "lib/index.d.ts", 7 | "scripts": { 8 | "test": "jest --config jestconfig.json", 9 | "build": "tsc", 10 | "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\" ", 11 | "lint": "tslint -p tsconfig.json", 12 | "prepare": "npm run build", 13 | "prepublishOnly": "npm test && npm run lint", 14 | "preversion": "npm run lint", 15 | "version": "npm run format && git add -A src", 16 | "postversion": "git push && git push --tags" 17 | }, 18 | "repository": { 19 | "type": "git", 20 | "url": "git+https://github.com/sametcelikbicak/enum2array.git" 21 | }, 22 | "keywords": [ 23 | "enum", 24 | "array", 25 | "enum to array", 26 | "enum2array", 27 | "front-end", 28 | "frontend" 29 | ], 30 | "author": "Samet ÇELİKBIÇAK", 31 | "license": "MIT", 32 | "bugs": { 33 | "url": "https://github.com/sametcelikbicak/enum2array/issues" 34 | }, 35 | "homepage": "https://github.com/sametcelikbicak/enum2array#readme", 36 | "devDependencies": { 37 | "@types/jest": "^27.0.1", 38 | "jest": "^27.0.5", 39 | "prettier": "^3.0.0", 40 | "ts-jest": "^27.0.3", 41 | "tslint": "^6.1.3", 42 | "tslint-config-prettier": "^1.18.0", 43 | "typescript": "^4.9.3" 44 | }, 45 | "files": [ 46 | "lib/**/*" 47 | ] 48 | } 49 | -------------------------------------------------------------------------------- /scripts/checkTag.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | GIT_COMMIT=$(git rev-parse --short HEAD) 4 | GIT_TAG=$(git describe --tags --exact-match $COMMIT || :) 5 | 6 | if [[ ${GIT_TAG} == v* ]] ; then 7 | echo "$GIT_TAG Tag found..." 8 | else 9 | echo "No git tag found, action cancelled..." 10 | exit 1 11 | fi -------------------------------------------------------------------------------- /scripts/run.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | echo -e "Hello, "$USER".\nWelcome to the Enum2Array build script!" 4 | echo -e "Which version option do you wish to use?\n1. Major [1.x.x]\n2. Minor [x.1.x]\n3. Patch [x.x.1] (Default)\n4. Manuel [x.x.x]" 5 | echo -n "Enter your choice [1-2-3-4] or press [ENTER]:" 6 | read choice 7 | 8 | if [ $choice == 1 ]; then 9 | echo "Major vesion is preparing..." 10 | npm version major 11 | elif [ $choice == 2 ]; then 12 | echo "Minor version is preparing..." 13 | npm version minor 14 | elif [ $choice == 4 ]; then 15 | echo -n "Enter your new version with [x.x.x] format:" 16 | read version 17 | echo "$version version is preparing..." 18 | npm version $version 19 | else 20 | echo "Patch version is preparing..." 21 | npm version patch 22 | fi 23 | -------------------------------------------------------------------------------- /src/array-value.ts: -------------------------------------------------------------------------------- 1 | export interface IArrayValue { 2 | readonly title: string; 3 | readonly value: any; 4 | } 5 | 6 | export class ArrayValue implements IArrayValue { 7 | public readonly title: string; 8 | public readonly value: any; 9 | 10 | constructor(title: string = '', value: any = '') { 11 | this.title = title; 12 | this.value = value; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import { ArrayValue, IArrayValue } from './array-value'; 2 | 3 | export function enum2array(enumObject: any): IArrayValue[] { 4 | if (Object.keys(enumObject).some((value) => Number(value))) { 5 | return Object.keys(enumObject) 6 | .filter((value) => isNaN(Number(value)) === false) 7 | .map((key) => new ArrayValue(enumObject[key], Number(key))); 8 | } 9 | 10 | return Object.keys(enumObject).map((key) => new ArrayValue(key, enumObject[key])); 11 | } 12 | -------------------------------------------------------------------------------- /test/array-value.test.ts: -------------------------------------------------------------------------------- 1 | import { ArrayValue } from '../src/array-value'; 2 | 3 | describe('ArrayValue', () => { 4 | it('should be defined', () => { 5 | expect(ArrayValue).toBeDefined(); 6 | }); 7 | 8 | it('should match valid object', () => { 9 | const expected = { title: 'TypeA', value: 1 }; 10 | 11 | const result = new ArrayValue('TypeA', 1); 12 | 13 | expect(result).toEqual(expected); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /test/index.test.ts: -------------------------------------------------------------------------------- 1 | import { ArrayValue } from '../src/array-value'; 2 | import { enum2array } from '../src/index'; 3 | 4 | enum CustomType { 5 | TypeA = 1, 6 | TypeB = 2, 7 | TypeC = 3, 8 | TypeD = 4, 9 | } 10 | 11 | enum CustomValue { 12 | TypeA = 'valueA', 13 | TypeB = 'valueB', 14 | TypeC = 'valueC', 15 | TypeD = 'valueD', 16 | } 17 | 18 | describe('enum2array', () => { 19 | it('should be defined', () => { 20 | expect(enum2array).toBeDefined(); 21 | }); 22 | 23 | it('should match valid array with number value', () => { 24 | const expected = [ 25 | new ArrayValue('TypeA', 1), 26 | new ArrayValue('TypeB', 2), 27 | new ArrayValue('TypeC', 3), 28 | new ArrayValue('TypeD', 4), 29 | ]; 30 | 31 | const result = enum2array(CustomType); 32 | 33 | expect(result).toEqual(expected); 34 | }); 35 | 36 | it('should match valid array with string value', () => { 37 | const expected = [ 38 | new ArrayValue('TypeA', 'valueA'), 39 | new ArrayValue('TypeB', 'valueB'), 40 | new ArrayValue('TypeC', 'valueC'), 41 | new ArrayValue('TypeD', 'valueD'), 42 | ]; 43 | 44 | const result = enum2array(CustomValue); 45 | 46 | expect(result).toEqual(expected); 47 | }); 48 | }); 49 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "declaration": true, 6 | "outDir": "./lib", 7 | "strict": true 8 | }, 9 | "include": ["src"], 10 | "exclude": ["node_modules"] 11 | } -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["tslint:recommended", "tslint-config-prettier"] 3 | } --------------------------------------------------------------------------------