Skip to content

Commit

Permalink
refactor(scan): resolve battle of types
Browse files Browse the repository at this point in the history
  • Loading branch information
derevnjuk committed Apr 29, 2022
1 parent 91437b4 commit e1a4c6c
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions packages/core/src/utils/check-boundaries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,20 @@ export interface NumBoundaries {
exclusiveMax?: boolean;
}

type WithRequiredProperty<Type, Key extends keyof Type> = Type & {
[Property in Key]-?: Type[Property];
};

type MaxBoundary = WithRequiredProperty<
Omit<NumBoundaries, 'min' | 'exclusiveMin'>,
'max'
>;
type MinBoundary = WithRequiredProperty<
Omit<NumBoundaries, 'max' | 'exclusiveMax'>,
'min'
>;

const checkMinimum = (
value: number,
{ min, exclusiveMin = false }: MinBoundary
{
min,
exclusiveMin = false
}: Required<Pick<NumBoundaries, 'min'>> & Pick<NumBoundaries, 'exclusiveMin'>
): boolean => (exclusiveMin ? value > min : value >= min);

const checkMaximum = (
value: number,
{ max, exclusiveMax = false }: MaxBoundary
{
max,
exclusiveMax = false
}: Required<Pick<NumBoundaries, 'max'>> & Pick<NumBoundaries, 'exclusiveMax'>
): boolean => (exclusiveMax ? value < max : value <= max);

export const checkBoundaries = (
Expand Down

0 comments on commit e1a4c6c

Please sign in to comment.