cookie-monster
Advanced tools
Comparing version 0.0.1 to 0.0.2
63
index.js
var exports = module.exports = function (doc) { | ||
if (!doc) doc = {}; | ||
if (typeof doc === 'string') doc = { cookie: doc }; | ||
if (doc.cookie === undefined) doc.cookie = ''; | ||
if (!doc) doc = {}; | ||
if (typeof doc === 'string') doc = { cookie: doc }; | ||
if (doc.cookie === undefined) doc.cookie = ''; | ||
var self = {}; | ||
self.get = function (key) { | ||
var splat = doc.cookie.split(/;\s*/); | ||
for (var i = 0; i < splat.length; i++) { | ||
var ps = splat[i].split('='); | ||
var k = unescape(ps[0]); | ||
if (k === key) return unescape(ps[1]); | ||
} | ||
return undefined; | ||
}; | ||
var self = {}; | ||
self.get = function (key) { | ||
var cookiesSplat = doc.cookie.split(/;\s*/); | ||
for (var i = 0; i < cookiesSplat.length; i++) { | ||
var ps = cookiesSplat[i].split('='); | ||
var k = unescape(ps[0]); | ||
if (k === key) return unescape(ps[1]); | ||
} | ||
return undefined; | ||
}; | ||
self.set = function (key, value, opts) { | ||
if (!opts) opts = {}; | ||
var s = escape(key) + '=' + escape(value); | ||
if (opts.expires) s += '; expires=' + opts.expires; | ||
if (opts.path) s += '; path=' + escape(opts.path); | ||
if (opts.domain) s += '; domain=' + opts.domain; | ||
doc.cookie = s; | ||
return s; | ||
}; | ||
return self; | ||
self.set = function (key, value, opts) { | ||
if (!opts) opts = {}; | ||
var newCookie = escape(key) + '=' + escape(value); | ||
if (opts.expires){ | ||
newCookie += '; expires=' + opts.expires; | ||
} | ||
if (opts.path) { | ||
newCookie += '; path=' + escape(opts.path); | ||
} | ||
if (opts.domain) { | ||
newCookie += '; domain=' + opts.domain; | ||
} | ||
doc.cookie = newCookie; | ||
return newCookie; | ||
}; | ||
return self; | ||
}; | ||
if (typeof document !== 'undefined') { | ||
var cookie = exports(document); | ||
exports.get = cookie.get; | ||
exports.set = cookie.set; | ||
var cookie = exports(document); | ||
exports.get = cookie.get; | ||
exports.set = cookie.set; | ||
} |
{ | ||
"name" : "cookie-monster", | ||
"description" : "Browserify-compatible module to get and set cookies in the browser", | ||
"version" : "0.0.1", | ||
"repository" : { | ||
"type" : "git", | ||
"url" : "git://github.com/kahnjw/cookie-monster.git" | ||
}, | ||
"main" : "index.js", | ||
"keywords" : [ | ||
"cookie", | ||
"browser", | ||
"browserify" | ||
], | ||
"license" : "MIT", | ||
"author" : { | ||
"name" : "Jarrod Kahn", | ||
"email" : "jarrod.kahn@gmail.com" | ||
} | ||
"name": "cookie-monster", | ||
"description": "Browserify-compatible module to get and set cookies in the browser", | ||
"version": "0.0.2", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/kahnjw/cookie-monster.git" | ||
}, | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"main": "index.js", | ||
"keywords": [ | ||
"cookie", | ||
"browser", | ||
"browserify" | ||
], | ||
"license": "MIT", | ||
"author": { | ||
"name": "Jarrod Kahn", | ||
"email": "jarrod.kahn@gmail.com" | ||
}, | ||
"devDependencies": { | ||
"chai": "^1.9.2", | ||
"mocha": "^1.21.5" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
4390
9
76
58
2