Repository URL to install this package:
|
Version:
4.0.5 ▾
|
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
}