Repository URL to install this package:
|
Version:
4.0.5 ▾
|
import { attemptToDecodeURIComponent } from '../deps'
export const fromCookieStringToPairs = (cookieString: string) => {
// "=" is a valid character in a cookie value according to RFC6265
// so cannot `split('=')`
const equalsIndex = cookieString.indexOf('=')
// IE omits the "=" when the cookie value is an empty string
const separatorIndex = equalsIndex < 0 ? cookieString.length : equalsIndex
const key = cookieString.substr(0, separatorIndex)
const decodedKey = attemptToDecodeURIComponent(key)
return {
key: decodedKey,
// Defer decoding value until accessed
// getter
value: cookieString.substr(separatorIndex + 1),
}
}