Skip to content

Commit

Permalink
Add isHttpMethod refinement (#4250)
Browse files Browse the repository at this point in the history
Co-authored-by: Tim <[email protected]>
  • Loading branch information
thewilkybarkid and tim-smart authored Jan 14, 2025
1 parent bcc600b commit c9e5e1b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/long-waves-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/platform": patch
---

Add isHttpMethod refinement
24 changes: 24 additions & 0 deletions packages/platform/src/HttpMethod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,27 @@ export declare namespace HttpMethod {
* @since 1.0.0
*/
export const hasBody = (method: HttpMethod): boolean => method !== "GET" && method !== "HEAD" && method !== "OPTIONS"

/**
* @since 1.0.0
*/
export const all: ReadonlySet<HttpMethod> = new Set(["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"])

/**
* Tests if a value is a `HttpMethod`.
*
* @param input - The value to test.
*
* @example
* ```ts
* import { HttpMethod } from "@effect/platform"
*
* assert.deepStrictEqual(HttpMethod.isHttpMethod("GET"), true)
* assert.deepStrictEqual(HttpMethod.isHttpMethod("get"), false)
* assert.deepStrictEqual(HttpMethod.isHttpMethod(1), false)
* ```
*
* @since 1.0.0
* @category refinements
*/
export const isHttpMethod = (u: unknown): u is HttpMethod => all.has(u as HttpMethod)

0 comments on commit c9e5e1b

Please sign in to comment.