diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 8d3eb8d6..cb66c1df 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -41,7 +41,7 @@ jobs: SKIP_TESTS: true - id: published-version run: echo "::set-output name=version::$(cat lerna.json | jq -r '.version')" - - uses: kyranjamie/pull-request-fixed-header@v1.0.1 + - uses: janniks/pull-request-fixed-header@v1.0.1 with: header: "> This PR was published to npm with the version `${{ steps.published-version.outputs.version }}`\n> e.g. `npm install @stacks/common@${{ steps.published-version.outputs.version }} --save-exact`" GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/packages/common/src/buffer.ts b/packages/common/src/buffer.ts index ede4d62f..67b5869a 100644 --- a/packages/common/src/buffer.ts +++ b/packages/common/src/buffer.ts @@ -1,5 +1,3 @@ -import { isEnum } from './enum'; - /** @ignore */ export function equals(a: Uint8Array, b: Uint8Array) { if (a.byteLength !== b.byteLength) return false; @@ -21,20 +19,6 @@ export function alloc(length: number, value: number) { return a; } -/** @ignore */ -export function readUInt8Enum( - source: Uint8Array, - offset: number, - enumVariable: { [key in T]: TEnumValue }, - invalidEnumErrorFormatter: (val: number) => Error -): TEnumValue { - const num = readUInt8(source, offset); - if (isEnum(enumVariable, num)) { - return num; - } - throw invalidEnumErrorFormatter(num); -} - /** @ignore */ export function readUInt16BE(source: Uint8Array, offset: number): number { return ((source[offset + 0] << 8) | source[offset + 1]) >>> 0; diff --git a/packages/common/src/enum.ts b/packages/common/src/enum.ts deleted file mode 100644 index 5c0aa106..00000000 --- a/packages/common/src/enum.ts +++ /dev/null @@ -1,40 +0,0 @@ -function createEnumChecker(enumVariable: { - [key in T]: TEnumValue; -}): (value: number) => value is TEnumValue { - // Create a set of valid enum number values. - const enumValues = Object.values(enumVariable).filter(v => typeof v === 'number'); - const enumValueSet = new Set(enumValues); - return (value: number): value is TEnumValue => enumValueSet.has(value); -} - -const enumCheckFunctions = new Map boolean>(); - -/** - * Type guard to check if a given value is a valid enum value. - * @param enumVariable - Literal `enum` type. - * @param value - A value to check against the enum's values. - * @example - * ```ts - * enum Color { - * Purple = 3, - * Orange = 5 - * } - * const val: number = 3; - * if (isEnum(Color, val)) { - * // `val` is known as enum type `Color`, e.g.: - * const colorVal: Color = val; - * } - * ``` - */ -export function isEnum( - enumVariable: { [key in T]: TEnumValue }, - value: number -): value is TEnumValue { - const checker = enumCheckFunctions.get(enumVariable); - if (checker !== undefined) { - return checker(value); - } - const newChecker = createEnumChecker(enumVariable); - enumCheckFunctions.set(enumVariable, newChecker); - return isEnum(enumVariable, value); -} diff --git a/packages/common/src/index.ts b/packages/common/src/index.ts index 4883c8a4..d4e02759 100644 --- a/packages/common/src/index.ts +++ b/packages/common/src/index.ts @@ -6,4 +6,3 @@ export * from './constants'; export * from './signatures'; export * from './keys'; export * from './buffer'; -export * from './enum';