diff --git a/src/lib/index.test.ts b/src/lib/index.test.ts index b6aa671..39127ea 100644 --- a/src/lib/index.test.ts +++ b/src/lib/index.test.ts @@ -1,4 +1,4 @@ -import { safePath, timedExecution } from '$lib'; +import safePath, { timedExecution } from '$lib'; import { describe, it, expect } from 'vitest'; describe('safe path', () => { @@ -32,8 +32,8 @@ describe('safe path', () => { }); describe('timedExecution', () => { - const asyncIdentity = async (v) => v; - const identity = (v) => v; + const asyncIdentity = async (v: T): Promise => v; + const identity = (v: T): T => v; it('works with async', async () => { const { executionTime, result } = await timedExecution(() => asyncIdentity(5)); diff --git a/src/lib/index.ts b/src/lib/index.ts index 84ebbc6..cee56ae 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -8,7 +8,7 @@ export const log = bunyan.createLogger({ src: true, }); -function safePath(basePath: string, name: string): boolean { +const safePath = (basePath: string, name: string): boolean => { const fullPath = `${basePath}/${name}`; const relative = path.relative(basePath, fullPath); return ( @@ -20,7 +20,9 @@ function safePath(basePath: string, name: string): boolean { // result is not an absolute path !path.isAbsolute(relative) ); -} +}; + +export default safePath; const defaultPath: string = './uploads'; if (!('STORAGE_PATH' in process.env)) { @@ -30,8 +32,6 @@ export const storagePath: string = process.env.STORAGE_PATH ?? defaultPath; export const requestIdHeader = 'x-request-id'; -export default safePath; - export type MaybePromise = T | Promise; export async function timedExecution(