Commit 9cd5c980 authored by Ray Schamp's avatar Ray Schamp

Make Jar formatting consistent with everything else

parent 3c307e17
...@@ -9,41 +9,39 @@ var xhr = require('xhr'); ...@@ -9,41 +9,39 @@ var xhr = require('xhr');
* set(name, value) – synchronously sets the cookie * set(name, value) – synchronously sets the cookie
* use(name, uri, callback) – can by sync or async, gets cookie from the uri if not there. * use(name, uri, callback) – can by sync or async, gets cookie from the uri if not there.
*/ */
var Jar = {}; var Jar = {
get: function (name, callback) {
Jar.get = function (name, callback) {
// Get cookie by name // Get cookie by name
var obj = cookie.parse(document.cookie) || {}; var obj = cookie.parse(document.cookie) || {};
// Handle optional callback // Handle optional callback
if (typeof callback === 'function') { if (typeof callback === 'function') {
if (typeof obj === 'undefined') return callback('Cookie not found.'); if (typeof obj === 'undefined') return callback('Cookie not found.');
return callback(null, obj[name]); return callback(null, obj[name]);
} }
return obj[name]; return obj[name];
}; },
use: function (name, uri, callback) {
Jar.use = function (name, uri, callback) { // Attempt to get cookie
// Attempt to get cookie Jar.get(name, function (err, obj) {
Jar.get(name, function (err, obj) { if (typeof obj !== 'undefined') return callback(null, obj);
if (typeof obj !== 'undefined') return callback(null, obj);
// Make XHR request to cookie setter uri
// Make XHR request to cookie setter uri xhr({
xhr({ uri: uri
uri: uri }, function (err) {
}, function (err) { if (err) return callback(err);
if (err) return callback(err); Jar.get(name, callback);
Jar.get(name, callback); });
}); });
}); },
}; set: function (name, value) {
var obj = cookie.serialize(name, value);
Jar.set = function (name, value) { var expires = '; expires=' + new Date(new Date().setYear(new Date().getFullYear() + 1)).toUTCString();
var obj = cookie.serialize(name, value); var path = '; path=/';
var expires = '; expires=' + new Date(new Date().setYear(new Date().getFullYear() + 1)).toUTCString(); document.cookie = obj + expires + path;
var path = '; path=/'; }
document.cookie = obj + expires + path;
}; };
module.exports = Jar; module.exports = Jar;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment