strict-cookie-parser

Parses cookie headers according to RFC 6265.

Usage no npm install needed!

<script type="module">
  import strictCookieParser from 'https://cdn.skypack.dev/strict-cookie-parser';
</script>

README

Build status

Parses cookie headers according to RFC 6265, producing a Map.

For Connect (Express) middleware, see strict-cookie-middleware.

const strictCookieParser = require('strict-cookie-parser');

strictCookieParser.parseCookieHeader('hello=world; foo=bar ')
// Map { 'hello' => 'world', 'foo' => 'bar' }

strictCookieParser.parseCookieHeader('not a cookie')
// null

strictCookieParser.parseCookiePair('single=pair')
// { name: 'single', value: 'pair' }

strictCookieParser.isCookieName('foo')
// true

strictCookieParser.isCookieName('m=m')
// invalid - cookie names cannot contain =
// false

strictCookieParser.parseCookieValue('"foo"')
// 'foo'

strictCookieParser.parseCookieValue(' foo')
// invalid - unquoted cookie values cannot begin with a space
// null