Вход Регистрация
Файл: error-kitty/node_modules/express/node_modules/cookie/index.js
Строк: 61
<?php
/// Serialize the a name value pair into a cookie string suitable for
/// http headers. An optional options object specified cookie parameters
///
/// serialize('foo', 'bar', { httpOnly: true })
///   => "foo=bar; httpOnly"
///
/// @param {String} name
/// @param {String} val
/// @param {Object} options
/// @return {String}
var serialize = function(namevalopt){
    
opt opt || {};
    var 
enc opt.encode || encode;
    var 
pairs = [name '=' enc(val)];

    if (
null != opt.maxAge) {
        var 
maxAge opt.maxAge 0;
        if (
isNaN(maxAge)) throw new Error('maxAge should be a Number');
        
pairs.push('Max-Age=' maxAge);
    }

    if (
opt.domainpairs.push('Domain=' opt.domain);
    if (
opt.pathpairs.push('Path=' opt.path);
    if (
opt.expirespairs.push('Expires=' opt.expires.toUTCString());
    if (
opt.httpOnlypairs.push('HttpOnly');
    if (
opt.securepairs.push('Secure');

    return 
pairs.join('; ');
};

/// Parse the given cookie header string into an object
/// The object has the various cookies as keys(names) => values
/// @param {String} str
/// @return {Object}
var parse = function(stropt) {
    
opt opt || {};
    var 
obj = {}
    var 
pairs str.split(/; */);
    var 
dec opt.decode || decode;

    
pairs.forEach(function(pair) {
        var 
eq_idx pair.indexOf('=')

        
// skip things that don't look like key=value
        
if (eq_idx 0) {
            return;
        }

        var 
key pair.substr(0eq_idx).trim()
        var 
val pair.substr(++eq_idxpair.length).trim();

        
// quoted values
        
if ('"' == val[0]) {
            
val val.slice(1, -1);
        }

        
// only assign once
        
if (undefined == obj[key]) {
            try {
                
obj[key] = dec(val);
            } catch (
e) {
                
obj[key] = val;
            }
        }
    });

    return 
obj;
};

var 
encode encodeURIComponent;
var 
decode decodeURIComponent;

module.exports.serialize serialize;
module.exports.parse parse;
?>
Онлайн: 0
Реклама