From 3c688e2250c9e61b0c6125c6b6aaf4bde94eb369 Mon Sep 17 00:00:00 2001 From: Kevin Whitley Date: Mon, 8 Apr 2024 22:50:31 -0500 Subject: [PATCH] released v5.0.11 - code-golfing --- package.json | 2 +- src/websocket.ts | 6 ++---- src/withParams.ts | 9 +++++---- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index a158f701..f70f48a5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "itty-router", - "version": "5.0.10", + "version": "5.0.11", "description": "A tiny, zero-dependency router, designed to make beautiful APIs in any environment.", "main": "./index.js", "module": "./index.mjs", diff --git a/src/websocket.ts b/src/websocket.ts index 452b6f37..94b9f30a 100644 --- a/src/websocket.ts +++ b/src/websocket.ts @@ -1,7 +1,5 @@ -import { createResponse } from './createResponse' - -export const websocket = (client: WebSocket, options: object = {}) => - createResponse()(null, { +export const websocket = (client: WebSocket, options?: ResponseInit) => + new Response(null, { status: 101, webSocket: client, ...options, diff --git a/src/withParams.ts b/src/withParams.ts index 2388a883..8861b79a 100644 --- a/src/withParams.ts +++ b/src/withParams.ts @@ -1,9 +1,10 @@ import { IRequest } from './types' export const withParams = (request: IRequest): void => { - request.proxy = new Proxy(request.proxy || request, { - get: (obj, prop) => obj[prop] !== undefined - ? obj[prop]?.bind?.(request) || obj[prop] - : obj?.params?.[prop] + request.proxy = new Proxy(request.proxy ?? request, { + get: (obj, prop) => + obj[prop]?.bind?.(request) // if prop exists (as function), return the function, bound to the original request + ?? obj[prop] // if prop exists, return it + ?? obj?.params?.[prop] // if no prop exists, try the params object }) }