lib/cookies.js
function createJWPCookie (key, cookieString, converter = null) {
  let result = {};
  let cookies = cookieString ? cookieString.split('; ') : [];
  for (let cookie of cookies) {
    let parts = cookie.split('=');

    // get the first and second element as name and value
    let name = decodeURIComponent(parts.shift());
    let val = parts[0];

    // if name is key, this is the central element of the cookie, so add as `name`
    // otherwise it is an optional element
    if (key && key === name) {
      result.name = key;
      result.value = convertCookie(val, converter);
    } else {
      result[name] = convertCookie(val, converter);
    }
  }
  return result;
}
function createJWPCookie (key, cookieString, converter = null) {
  let result = {};
  let cookies = cookieString ? cookieString.split('; ') : [];
  for (let cookie of cookies) {
    let parts = cookie.split('=');

    // get the first and second element as name and value
    let name = decodeURIComponent(parts.shift());
    let val = parts[0];

    // if name is key, this is the central element of the cookie, so add as `name`
    // otherwise it is an optional element
    if (key && key === name) {
      result.name = key;
      result.value = convertCookie(val, converter);
    } else {
      result[name] = convertCookie(val, converter);
    }
  }
  return result;
}
function createJWPCookie ( key , cookieString , converter = null ) { let result = { } ; let cookies = cookieString ? cookieString . split ( '; ' ) : [ ] ; for ( let cookie of cookies ) { let parts = cookie . split ( '=' ) ; // get the first and second element as name and value let name = decodeURIComponent ( parts . shift ( ) ) ; let val = parts [ 0 ] ; // if name is key, this is the central element of the cookie, so add as `name` // otherwise it is an optional element if ( key && key === name ) { result . name = key ; result . value = convertCookie ( val , converter ) ; } else { result [ name ] = convertCookie ( val , converter ) ; } } return result ; }
takes the JavaScript cookieString and translates it into a JSONWire formatted cookie
takes the JavaScript cookieString and translates it into a JSONWire formatted cookie