Skip to content

Commit 6d168d5

Browse files
authored
Change getEnumValues and GetEnumValueFromName return type (#45)
1 parent f4217d5 commit 6d168d5

3 files changed

Lines changed: 43 additions & 4 deletions

File tree

.github/workflows/pkg.pr.new.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: PKG PR New
2+
on:
3+
workflow_dispatch:
4+
pull_request:
5+
types: [opened, synchronize, ready_for_review]
6+
push:
7+
branches:
8+
- main
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- uses: actions/setup-node@v4
19+
with:
20+
node-version: 20
21+
22+
- run: yarn --frozen-lockfile
23+
24+
# append the git commit to the package.json version.
25+
# We do this because some cache mechanisms (like nextjs) don't work well with the same version and ignore the changes
26+
# until you manually delete the cache
27+
- run: jq '.version = .version + "-" + env.GITHUB_SHA' package.json > package.json.tmp && mv package.json.tmp package.json
28+
29+
- run: npx pkg-pr-new publish

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- `pkg.pr.new` workflow
13+
14+
### Changed
15+
16+
- :boom: `getEnumValues` and `getEnumValueFromName` return type from `string | number` to enum type
17+
1018
## [0.7.0] - 2024-10-02
1119

1220
### dependabot: \#42 Bump rollup from 3.21.4 to 3.29.5

src/lib/enum.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ export function getEnumNameFromValue<T>(enumVariable: StandardEnum<T>, enumValue
2222
* @param enumName The name of the enum for which you want to get the value
2323
* @returns A string containing the value of the enum
2424
*/
25-
export function getEnumValueFromName<T>(enumVariable: StandardEnum<T>, enumName: string): number | string {
25+
export function getEnumValueFromName<T>(enumVariable: StandardEnum<T>, enumName: string): T {
2626
const value = Object.values(enumVariable)[Object.keys(enumVariable).findIndex((x) => x === enumName)] as string;
27-
return isEnumString(enumVariable) ? value : Number.parseInt(value);
27+
return (isEnumString(enumVariable) ? value : Number.parseInt(value)) as T;
2828
}
2929

3030
/**
@@ -44,11 +44,13 @@ export function getEnumNames<T>(enumVariable: StandardEnum<T>) {
4444
* @param enumVariable The enum for which you want to get the values
4545
* @returns A string or number array containing the values of the enum
4646
*/
47-
export function getEnumValues<T>(enumVariable: StandardEnum<T>) {
47+
export function getEnumValues<T>(enumVariable: StandardEnum<T>): T[] {
4848
const keys = Object.keys(enumVariable);
4949

5050
// If enum is with values integer, object.keys returns a list of [values, names].
51-
return isEnumString(enumVariable) ? Object.values(enumVariable) : keys.slice(0, keys.length / 2).map((value) => Number.parseInt(value));
51+
return (
52+
isEnumString(enumVariable) ? Object.values(enumVariable) : keys.slice(0, keys.length / 2).map((value) => Number.parseInt(value))
53+
) as T[];
5254
}
5355

5456
/**

0 commit comments

Comments
 (0)