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 / fromStringToCache.ts
Size: Mime:
import { config } from '../config'
import { fromCookieStringToPairs } from './fromCookieStringToPairs'

/**
 * @alias getCacheFromString
 */
export const fromStringToCache = (
  documentCookie: string
): { [key: string]: string } => {
  // removed safety of not passing in string, asserting instead (smaller build)
  if (process.env.NODE_ENV !== 'production') {
    if (typeof documentCookie !== 'string') {
      if (
        documentCookie &&
        typeof (documentCookie as any).split === 'function'
      ) {
        console.warn('[@skava/cookie] using a weird cookie')
      } else {
        console.error('[@skava/cookie] using invalid cookie, will error')
      }
    }
  }

  const cookieCache = {}

  documentCookie.split('; ').forEach(stringPair => {
    const { key, value } = fromCookieStringToPairs(stringPair)
    const property = config.get('cacheKeyPrefix') + key
    if (cookieCache[property] === undefined) {
      cookieCache[property] = value
    }
  })

  return cookieCache
}