caseless
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Caseless is a very useful JavaScript package for working with HTTP headers. It allows you to wrap an object to carry out set, get, and has operations with caseless semantics while preserving the casing of headers when they are first set. This functionality is especially helpful in scenarios where the HTTP headers' case sensitivity might lead to difficulties or confusion.
Using caseless is quite straightforward. You start by importing the package then create an object to store your headers. You wrap this object with the caseless function. Now you can use the .set(key, value)
, .get(key)
, .has(key)
, and .swap(key)
methods on this object.
For instance, to set and get a header:
var headers = {};
var c = caseless(headers);
c.set('a-Header', 'asdf');
console.log(c.get('a-header')); // outputs: asdf
To check if a header exists:
console.log(c.has('a-header')); // outputs: a-Header
To append a value to an existing header:
c.set('a-Header', 'fdas');
c.set('a-HEADER', 'more', false);
console.log(c.get('a-header')); // outputs: fdsa,more
To swap the casing of a header:
var headers = {};
var c = caseless(headers);
c.set('a-Header', 'fdas');
c.swap('a-HEADER');
console.log(c.has('a-header')); // outputs: a-HEADER
console.log(headers); // outputs: {'a-HEADER': 'fdas'}
Please note that the set method by default clobbers the value of an existing header if one exists. To append to the existing value, pass false
as the third argument.
The documentation for Caseless is found within the README file in the package's GitHub repository. The repository's URL is git+https://github.com/mikeal/caseless.git. The README contains usage examples and detailed descriptions of the methods provided by the package.