HTTP Header Case Normalizer

1.0.3 · maintenance · verified Wed Apr 22

This library provides a utility function to convert HTTP header names into their most commonly used casing (e.g., "user-agent" becomes "User-Agent"). It is particularly useful when interfacing with systems or APIs that expect specific header casing, despite the HTTP specification stating that headers are case-insensitive. Currently at version 1.0.3, `header-case-normalizer` appears to be a stable, focused utility with infrequent updates, indicating it is likely operating in a maintenance mode rather than undergoing active feature development. Its primary differentiator is its specific focus on normalizing a known set of common HTTP header names, based on a list tested with MDN data. This ensures consistent output for widely recognized headers, making it reliable for standard HTTP operations where specific casing might be a requirement for certain environments or legacy systems. It does not attempt to "smart-case" arbitrary strings, only those identified as common HTTP headers.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to import and use the `normalizeHeaderCase` function for various HTTP header names, showing both successful normalizations and a note about custom headers.

import normalizeHeaderCase from 'header-case-normalizer';

// Normalize common HTTP headers
console.log(normalizeHeaderCase('user-agent'));       // Expected: User-Agent
console.log(normalizeHeaderCase('content-type'));      // Expected: Content-Type
console.log(normalizeHeaderCase('x-requested-with'));  // Expected: X-Requested-With
console.log(normalizeHeaderCase('etag'));              // Expected: ETag

// Demonstrate case insensitivity handling
console.log(normalizeHeaderCase('uSeR-aGeNt'));      // Expected: User-Agent
console.log(normalizeHeaderCase('CONTENT-type'));    // Expected: Content-Type

// Headers not in its internal list might not be normalized as expected
console.log(normalizeHeaderCase('my-custom-header')); // Expected: My-Custom-Header (might return input or a partial normalization)

view raw JSON →