The `parse-http-header` package (version 1.0.1) is a lightweight JavaScript utility specifically designed to extract structured information from parameterized HTTP header *value strings*. For instance, a common header value like `text/html; charset=UTF-8` is parsed into an object where `text/html` is accessible as the first element of an array, and parameters like `charset` are exposed as direct properties of that object. This allows developers to easily access both the primary media type and its associated attributes in a unified structure. Originally published around 2014, the library appears to be stable but has not seen active development or new releases in many years. Its key differentiators include its focused scope on parsing *just* the value string portion of a header, rather than handling full HTTP messages or multiple header lines, and its minimal footprint with no external runtime dependencies. It exclusively uses CommonJS module syntax.
npm install parse-http-headerVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to parse common parameterized HTTP header value strings like Content-Type and Content-Disposition, showing access to both the primary value and its parameters.
Use `const parseHttpHeader = require('parse-http-header');` for module import.Always access the main value via `[0]` (e.g., `parsedHeader[0]`) and parameters via named properties (e.g., `parsedHeader.paramName`).
For new projects or applications requiring robust and up-to-date HTTP header parsing, consider alternatives like `http-link-header` (for Link headers specifically), or more general-purpose HTTP parsing libraries that are actively maintained.
Ensure that only the header's value string (the part after the colon) is passed to the `parseHttpHeader` function. If processing full header lines, pre-process them to extract only the value.
Change the import statement to `const parseHttpHeader = require('parse-http-header');`.Ensure the input to `parseHttpHeader` is a valid string. Add a null/undefined check before accessing properties: `const parsed = parseHttpHeader(headerString); if (parsed) { console.log(parsed[0]); }`.Verify the exact format of the header value. This library might have limitations with complex or non-standard parameter escaping. For advanced parsing, consider more robust HTTP header parsing libraries.
No dependency data recorded yet.