all files / blackbird/modules/utils/ stringifyCookie.js

77.78% Statements 14/18
60% Branches 12/20
100% Functions 1/1
77.78% Lines 14/18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47                        16×   16×       16×   16×       16× 13×     16×       16×       16× 13×     16×      
/**
 * Creates a cookie string using the given options, which may be any of
 * the following:
 *
 * - value
 * - domain
 * - path
 * - expires
 * - secure
 * - httpOnly or HttpOnly
 */
 const R = require("ramda"),
     {is} = R;
 function stringifyCookie(name, options) {
     options = options || {};
 
     Iif (R.is(String, options)) {
         options = {value: options};
     }
 
     let cookie = `${encodeURIComponent(name)}=${encodeURIComponent(options.value || "")}`;
 
     Iif (options.domain) {
         cookie += `; domain=${options.domain}`;
     }
 
     if (options.path) {
         cookie += `; path=${options.path}`;
     }
 
     Iif (options.expires) {
         cookie += `; expires=${is(Date, options.expires) ? options.expires.toUTCString() : options.expires}`;
     }
 
     Iif (options.secure) {
         cookie += "; secure";
     }
 
     if (options.httpOnly || options.HttpOnly) {
         cookie += "; HttpOnly";
     }
 
     return cookie;
 }
 
 module.exports = stringifyCookie;