123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- 'use strict';
- var merge = require('utils-merge')
- , cookie = require('cookie');
- var Cookie = module.exports = function Cookie(options) {
- this.path = '/';
- this.maxAge = null;
- this.httpOnly = true;
- if (options) merge(this, options);
- this.originalMaxAge = undefined == this.originalMaxAge
- ? this.maxAge
- : this.originalMaxAge;
- };
- Cookie.prototype = {
-
- set expires(date) {
- this._expires = date;
- this.originalMaxAge = this.maxAge;
- },
-
- get expires() {
- return this._expires;
- },
-
- set maxAge(ms) {
- this.expires = 'number' == typeof ms
- ? new Date(Date.now() + ms)
- : ms;
- },
-
- get maxAge() {
- return this.expires instanceof Date
- ? this.expires.valueOf() - Date.now()
- : this.expires;
- },
-
- get data() {
- return {
- originalMaxAge: this.originalMaxAge
- , expires: this._expires
- , secure: this.secure
- , httpOnly: this.httpOnly
- , domain: this.domain
- , path: this.path
- , sameSite: this.sameSite
- }
- },
-
- serialize: function(name, val){
- return cookie.serialize(name, val, this.data);
- },
-
- toJSON: function(){
- return this.data;
- }
- };
|