GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - tselect-npm/http-method: HTTP methods related enums and utilities.

BranchesTags
Open more actions menu

Latest commit

 

History

19 Commits
19 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
src
src
 
 
test
test
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
biome.json
biome.json
 
 
package.json
package.json
 
 
pnpm-lock.yaml
pnpm-lock.yaml
 
 
pnpm-workspace.yaml
pnpm-workspace.yaml
 
 
tsconfig.json
tsconfig.json
 
 
tsdown.config.ts
tsdown.config.ts
 
 
vitest.config.ts
vitest.config.ts
 
 

Repository files navigation

@tselect/http-method

npm npm CI coverage license

HTTP methods related enums and utilities.

Zero runtime dependencies. Ships both ESM and CommonJS builds, with TypeScript types for each.

Requirements

Node 22 or newer (engines.node is >=22) — every line still receiving security support. Each release is tested on 22, 24 and 26; the declared floor is the lowest version CI actually runs, not a guess.

Installation

npm i @tselect/http-method
pnpm add @tselect/http-method

Usage

import { HTTPMethod, isHTTPMethod } from '@tselect/http-method';

HTTPMethod.GET; // 'get'
isHTTPMethod(HTTPMethod.GET); // true

Namespace imports and require() both work:

import * as HTTPMethodUtils from '@tselect/http-method';
const { HTTPMethod, isHTTPMethod } = require('@tselect/http-method');

API

HTTPMethod

A string enum of the supported HTTP methods. Every member's value is lower case.

HTTPMethod.GET; // 'get'
HTTPMethod.POST; // 'post'
HTTPMethod.PATCH; // 'patch'
HTTPMethod.DELETE; // 'delete'
HTTPMethod.HEAD; // 'head'
HTTPMethod.OPTIONS; // 'options'
HTTPMethod.PUT; // 'put'

THTTPMethod

A union of every method name in both lower and constant case — 'get' | 'post' | … | 'GET' | 'POST' | …. Every function below accepts it, so the enum, a lower case literal and a constant case literal are all valid arguments.

import type { THTTPMethod } from '@tselect/http-method';

const method: THTTPMethod = 'PATCH';

isHTTPMethod(candidate: string): boolean

Returns whether an arbitrary string names an HTTP method. Case-insensitive, and unlike the functions below it accepts any string, so it is the one to reach for when validating untrusted input.

isHTTPMethod('get'); // true
isHTTPMethod('GET'); // true
isHTTPMethod('gEt'); // true
isHTTPMethod('foo'); // false

toLowerCase(method: THTTPMethod): THTTPMethod

Returns the lower case form, which is the form the HTTPMethod enum uses.

toLowerCase('GET'); // 'get'
toLowerCase('get'); // 'get'

toConstantCase(method: THTTPMethod): THTTPMethod

Returns the upper case form, as used in most HTTP tooling and in the Allow header.

toConstantCase('get'); // 'GET'
toConstantCase('GET'); // 'GET'

toPascalCase(method: THTTPMethod): string

Returns the method with its first character upper cased and the rest lower cased. Useful for building method-derived identifiers such as onGet or handlePost.

toPascalCase('get'); // 'Get'
toPascalCase('POST'); // 'Post'

License

MIT © Sylvain Estevez

About

HTTP methods related enums and utilities.

Resources

Readme
MIT license
Activity
Custom properties

Stars

0 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.