Socket
Socket
Sign inDemoInstall

caseless

Package Overview
Dependencies
0
Maintainers
3
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

caseless

Caseless object set/get/has, very useful when working with HTTP headers.


Version published
Maintainers
3
Weekly downloads
16,958,413
decreased by-10.7%

Weekly downloads

Package description

What is caseless?

The caseless npm package is a utility for managing HTTP headers in a case-insensitive manner. It allows you to get, set, and delete headers on an object without worrying about the case sensitivity of the header names.

What are caseless's main functionalities?

Setting headers

This feature allows you to set headers on an object. The headers are managed in a case-insensitive way, so setting 'A-Header' would overwrite 'a-header' if it already exists.

{"var caseless = require('caseless');\nvar headers = {};\nvar c = caseless(headers);\nc.set('a-Header', 'the value');\nconsole.log(headers); // Output will be { 'a-header': 'the value' }"}

Getting headers

This feature allows you to retrieve the value of headers regardless of the case of the header name you provide.

{"var caseless = require('caseless');\nvar headers = {'a-header': 'the value'};\nvar c = caseless(headers);\nconsole.log(c.get('A-Header')); // Output will be 'the value'"}

Checking if a header exists

This feature allows you to check if a header exists in the object, regardless of the case of the header name.

{"var caseless = require('caseless');\nvar headers = {'content-type': 'application/json'};\nvar c = caseless(headers);\nconsole.log(c.has('Content-Type')); // Output will be true"}

Deleting headers

This feature allows you to delete headers from the object. The deletion is case-insensitive.

{"var caseless = require('caseless');\nvar headers = {'content-type': 'application/json'};\nvar c = caseless(headers);\nc.delete('Content-Type');\nconsole.log(headers); // Output will be {}"}

Other packages similar to caseless

Readme

Source

Caseless -- wrap an object to set and get property with caseless semantics but also preserve caseing.

This library is incredibly useful when working with HTTP headers. It allows you to get/set/check for headers in a caseless manner while also preserving the caseing of headers the first time they are set.

Usage

var headers = {}
  , c = caseless(headers)
  ;
c.set('a-Header', 'asdf')
c.get('a-header') === 'asdf'

has(key)

Has takes a name and if it finds a matching header will return that header name with the preserved caseing it was set with.

c.has('a-header') === 'a-Header'

set(key, value[, clobber=true])

Set is fairly straight forward except that if the header exists and clobber is disabled it will add ','+value to the existing header.

c.set('a-Header', 'fdas')
c.set('a-HEADER', 'more', false)
c.get('a-header') === 'fdsa,more'

swap(key)

Swaps the casing of a header with the new one that is passed in.

var headers = {}
  , c = caseless(headers)
  ;
c.set('a-Header', 'fdas')
c.swap('a-HEADER')
c.has('a-header') === 'a-HEADER'
headers === {'a-HEADER': 'fdas'}

Keywords

FAQs

Last updated on 26 Jan 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc