{"library":"parse-prefer-header","title":"HTTP Prefer Header Parser","description":"The `parse-prefer-header` library provides a lightweight utility for parsing the HTTP `Prefer` header, as defined in RFC7240. Currently at version 1.0.0, this package focuses on accurately transforming the header's comma-separated tokens and their optional parameters into a user-friendly JavaScript object. It handles various intricacies like token normalization (e.g., `respond-async` to `respondAsync`) and correctly interprets quoted values. Its core functionality is to map preference tokens to either `true` (for preferences without explicit values) or their parsed string value. Given its stable 1.0.0 version and specific parsing scope, its release cadence is effectively stable with no new major versions anticipated for such a focused utility. Key differentiators include its strict adherence to RFC7240 and its minimal API surface for a common, yet often complex, HTTP header.","language":"javascript","status":"maintenance","last_verified":"Wed Apr 22","install":{"commands":["npm install parse-prefer-header"],"cli":null},"imports":["const parsePreferHeader = require('parse-prefer-header');","import parsePreferHeader from 'parse-prefer-header';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import parsePreferHeader from 'parse-prefer-header';\n\n// Example 1: Basic preferences\nlet preferences = parsePreferHeader('respond-async, wait=300');\nconsole.log('Example 1:', preferences);\n// Expected: { respondAsync: true, wait: '300' }\n\n// Example 2: Preferences with quoted values and parameters\npreferences = parsePreferHeader('foo=\"key=value;other\", bar;baz=123');\nconsole.log('Example 2:', preferences);\n// Expected: { foo: 'key=value;other', bar: true, baz: '123' }\n\n// Example 3: Handling an array of header values (RFC allows multiple Prefer headers)\nconst multipleHeaders = [\n  'respond-async, wait=500',\n  'handling=lenient;max-age=3600'\n];\npreferences = parsePreferHeader(multipleHeaders);\nconsole.log('Example 3:', preferences);\n// Expected: { respondAsync: true, wait: '500', handling: 'lenient', 'max-age': '3600' }\n\n// Example 4: Empty or invalid input\npreferences = parsePreferHeader('');\nconsole.log('Example 4 (empty):', preferences);\n// Expected: {}\npreferences = parsePreferHeader(null);\nconsole.log('Example 4 (null):', preferences);\n// Expected: {} (or throws, depending on internal implementation for null/undefined - testing shows it handles it gracefully)\n","lang":"typescript","description":"This quickstart demonstrates parsing various HTTP Prefer header string formats, including single strings, arrays, values with parameters, and quoted values, and shows how the output is structured as a JavaScript object.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}