You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.1 KiB

  1. ## Caseless -- wrap an object to set and get property with caseless semantics but also preserve caseing.
  2. 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.
  3. ## Usage
  4. ```javascript
  5. var headers = {}
  6. , c = caseless(headers)
  7. ;
  8. c.set('a-Header', 'asdf')
  9. c.get('a-header') === 'asdf'
  10. ```
  11. ## has(key)
  12. Has takes a name and if it finds a matching header will return that header name with the preserved caseing it was set with.
  13. ```javascript
  14. c.has('a-header') === 'a-Header'
  15. ```
  16. ## set(key, value[, clobber=true])
  17. Set is fairly straight forward except that if the header exists and clobber is disabled it will add `','+value` to the existing header.
  18. ```javascript
  19. c.set('a-Header', 'fdas')
  20. c.set('a-HEADER', 'more', false)
  21. c.get('a-header') === 'fdsa,more'
  22. ```
  23. ## swap(key)
  24. Swaps the casing of a header with the new one that is passed in.
  25. ```javascript
  26. var headers = {}
  27. , c = caseless(headers)
  28. ;
  29. c.set('a-Header', 'fdas')
  30. c.swap('a-HEADER')
  31. c.has('a-header') === 'a-HEADER'
  32. headers === {'a-HEADER': 'fdas'}
  33. ```