From cebaf63ddd683ef8fec8d866139588c749d0ac50 Mon Sep 17 00:00:00 2001 From: Nato Boram Date: Sat, 4 May 2024 15:22:17 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20Delete=20toNumericRange?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/utils/adapters.test.ts | 24 +----------------------- src/lib/utils/adapters.ts | 12 ------------ src/routes/[site]/post/[post]/+page.ts | 3 +-- 3 files changed, 2 insertions(+), 37 deletions(-) diff --git a/src/lib/utils/adapters.test.ts b/src/lib/utils/adapters.test.ts index 5485bee..bbf7630 100644 --- a/src/lib/utils/adapters.test.ts +++ b/src/lib/utils/adapters.test.ts @@ -1,5 +1,5 @@ import { describe, test } from 'vitest' -import { isLessThan, isNumericRange, toLessThan, toNumericRange } from './adapters.js' +import { isLessThan, isNumericRange, toLessThan } from './adapters.js' describe.concurrent('isLessThan', () => { test('returns `true` if input is less than max', ({ expect }) => { @@ -56,25 +56,3 @@ describe.concurrent('isNumericRange', () => { expect(result).toBe(true) }) }) - -describe.concurrent('toNumericRange', () => { - test('returns min if input is less than min', ({ expect }) => { - const result = toNumericRange(0, 1, 3) - expect(result).toBe(1) - }) - - test('returns input if input is within range', ({ expect }) => { - const result = toNumericRange(2, 1, 3) - expect(result).toBe(2) - }) - - test('returns max if input is greater than max', ({ expect }) => { - const result = toNumericRange(4, 1, 3) - expect(result).toBe(3) - }) - - test('returns input if input is equal to min and max', ({ expect }) => { - const result = toNumericRange(1, 1, 1) - expect(result).toBe(1) - }) -}) diff --git a/src/lib/utils/adapters.ts b/src/lib/utils/adapters.ts index 29bc6a7..4da23f2 100644 --- a/src/lib/utils/adapters.ts +++ b/src/lib/utils/adapters.ts @@ -1,7 +1,6 @@ /* eslint-disable @typescript-eslint/no-unsafe-return */ import type { LessThan, NumericRange } from '@sveltejs/kit' -// @ts-expect-error Type instantiation is excessively deep and possibly infinite. export function isLessThan(input: number, max: Max): input is LessThan { return input < max } @@ -15,17 +14,6 @@ export function isNumericRange( } export function toLessThan(input: number, max: Max): LessThan { - // @ts-expect-error Type instantiation is excessively deep and possibly infinite. if (isLessThan(input, max)) return input return (max - 1) as LessThan } - -export function toNumericRange( - input: number, - min: Min, - max: Max, -): NumericRange { - if (isLessThan(input, min)) return min as NumericRange - if (isLessThan(input, max)) return input - return max as NumericRange -} diff --git a/src/routes/[site]/post/[post]/+page.ts b/src/routes/[site]/post/[post]/+page.ts index 6af8614..f2bf84d 100644 --- a/src/routes/[site]/post/[post]/+page.ts +++ b/src/routes/[site]/post/[post]/+page.ts @@ -1,6 +1,5 @@ import { error, type HttpError } from '@sveltejs/kit' import { LemmyHttp } from 'lemmy-js-client' -import { toNumericRange } from '$lib/utils/adapters.js' import { formGetComments, headers, serverFetch } from '$lib/utils/index.js' import type { PageLoad } from './$types.js' @@ -29,7 +28,7 @@ export const load = (async ({ params, fetch, url, parent, depends }) => { default: console.error(e) - throw error(toNumericRange(e.status, 400, 599), 'Failed to load post.') + throw error(e.status, 'Failed to load post.') } }), client.getComments(formComment).catch((e: Response) => {