Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/cookies / src / core / fromCookieStringToPairs.ts
Size: Mime:
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),
  }
}