diff --git a/.github/workflows/pkg.pr.new.yml b/.github/workflows/pkg.pr.new.yml new file mode 100644 index 0000000..47518f6 --- /dev/null +++ b/.github/workflows/pkg.pr.new.yml @@ -0,0 +1,29 @@ +name: PKG PR New +on: + workflow_dispatch: + pull_request: + types: [opened, synchronize, ready_for_review] + push: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: 20 + + - run: yarn --frozen-lockfile + + # append the git commit to the package.json version. + # We do this because some cache mechanisms (like nextjs) don't work well with the same version and ignore the changes + # until you manually delete the cache + - run: jq '.version = .version + "-" + env.GITHUB_SHA' package.json > package.json.tmp && mv package.json.tmp package.json + + - run: npx pkg-pr-new publish diff --git a/CHANGELOG.md b/CHANGELOG.md index efd72c9..d254e3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- `pkg.pr.new` workflow + +### Changed + +- :boom: `getEnumValues` and `getEnumValueFromName` return type from `string | number` to enum type + ## [0.7.0] - 2024-10-02 ### dependabot: \#42 Bump rollup from 3.21.4 to 3.29.5 diff --git a/src/lib/enum.ts b/src/lib/enum.ts index d5b1dc1..a253bff 100644 --- a/src/lib/enum.ts +++ b/src/lib/enum.ts @@ -22,9 +22,9 @@ export function getEnumNameFromValue(enumVariable: StandardEnum, enumValue * @param enumName The name of the enum for which you want to get the value * @returns A string containing the value of the enum */ -export function getEnumValueFromName(enumVariable: StandardEnum, enumName: string): number | string { +export function getEnumValueFromName(enumVariable: StandardEnum, enumName: string): T { const value = Object.values(enumVariable)[Object.keys(enumVariable).findIndex((x) => x === enumName)] as string; - return isEnumString(enumVariable) ? value : Number.parseInt(value); + return (isEnumString(enumVariable) ? value : Number.parseInt(value)) as T; } /** @@ -44,11 +44,13 @@ export function getEnumNames(enumVariable: StandardEnum) { * @param enumVariable The enum for which you want to get the values * @returns A string or number array containing the values of the enum */ -export function getEnumValues(enumVariable: StandardEnum) { +export function getEnumValues(enumVariable: StandardEnum): T[] { const keys = Object.keys(enumVariable); // If enum is with values integer, object.keys returns a list of [values, names]. - return isEnumString(enumVariable) ? Object.values(enumVariable) : keys.slice(0, keys.length / 2).map((value) => Number.parseInt(value)); + return ( + isEnumString(enumVariable) ? Object.values(enumVariable) : keys.slice(0, keys.length / 2).map((value) => Number.parseInt(value)) + ) as T[]; } /**