UNPKG

nicolive

Version:
45 lines (35 loc) 941 B
// Generated by CoffeeScript 1.10.0 var Session, fs; fs = require('fs'); Session = (function() { function Session(path) { this.path = path; if (!this.path.match(/.json$/)) { this.path = this.path + '.json'; } this.cache = {}; if (fs.existsSync(this.path)) { this.cache = require(this.path); } } Session.prototype.set = function(cookie) { return this.cache.cookie = cookie; }; Session.prototype.get = function() { return this.cache.cookie; }; Session.prototype.save = function() { fs.writeFileSync(this.path, JSON.stringify(this.cache)); return delete require.cache[require.resolve(this.path)]; }; Session.prototype.destroy = function() { if (!fs.existsSync(this.path)) { return; } this.cache = {}; fs.unlinkSync(this.path); return delete require.cache[require.resolve(this.path)]; }; return Session; })(); module.exports = Session;