10 examples of 'npm cookie-parser' in JavaScript

Every line of 'npm cookie-parser' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
1module.exports = function setcookie (name, value, expires, path, domain, secure) {
2 // discuss at: https://locutus.io/php/setcookie/
3 // original by: Jonas Raoni Soares Silva (https://www.jsfromhell.com)
4 // bugfixed by: Andreas
5 // bugfixed by: Onno Marsman (https://twitter.com/onnomarsman)
6 // improved by: Kevin van Zonneveld (https://kvz.io)
7 // example 1: setcookie('author_name', 'Kevin van Zonneveld')
8 // returns 1: true
9
10 var setrawcookie = require('../network/setrawcookie')
11 return setrawcookie(name, encodeURIComponent(value), expires, path, domain, secure)
12}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

99function cookie( name, value, days ){
100 var expires;
101 // if value is undefined, get the cookie value
102 if( value === undefined ){
103 var cookiestring = "; " + window.document.cookie;
104 var cookies = cookiestring.split( "; " + name + "=" );
105 if ( cookies.length == 2 ){
106 return cookies.pop().split( ";" ).shift();
107 }
108 return null;
109 }
110 else {
111 // if value is a false boolean, we'll treat that as a delete
112 if( value === false ){
113 days = -1;
114 }
115 if ( days ) {
116 var date = new Date();
117 date.setTime( date.getTime() + ( days * 24 * 60 * 60 * 1000 ) );
118 expires = "; expires="+date.toGMTString();
119 }
120 else {
121 expires = "";
122 }
123 window.document.cookie = name + "=" + value + expires + "; path=/";
124 }
125 }
33function createCookie(
34 name: string,
35 value: string,
36 options: CookieSerializeOptions,
37): Cookie {
38 return {
39 name: name,
40 expires: options.expires,
41 maxAge: options.maxAge,
42 secure: options.secure,
43 httpOnly: options.httpOnly,
44 domain: options.domain,
45 value: value,
46 path: options.path,
47 }
48}
37module.exports = function cookieParser(secret){
38 return function cookieParser(req, res, next) {
39 var cookie = req.headers.cookie;
40 if (req.cookies) return next();
41
42 req.secret = secret;
43 req.cookies = {};
44 req.signedCookies = {};
45
46 if (cookie) {
47 try {
48 req.cookies = utils.parseCookie(cookie);
49 if (secret) {
50 req.signedCookies = utils.parseSignedCookies(req.cookies, secret);
51 var obj = utils.parseJSONCookies(req.signedCookies);
52 req.signedCookies = obj.cookies;
53 req.cookieHashes = obj.hashes;
54 }
55 req.cookies = utils.parseJSONCookies(req.cookies).cookies;
56 } catch (err) {
57 return next(err);
58 }
59 }
60 next();
61 };
62};
8return function cookieParser(socket, next) {
9 var req = socket.request;
10 var res = req.res;
11
12 return fn(req, res, next);
13};
25function createCookie(name, value, days)
26{
27 var date, expires;
28
29 if ( days )
30 {
31 date = new Date();
32 date.setTime(date.getTime()+(days*24*60*60*1000));
33 expires = "; expires="+date.toGMTString();
34 } else
35 {
36 expires = "";
37 }
38
39 document.cookie = name+"="+value+expires+"; path=/";
40}
468function createCookie(name, value, days) {
469 days = days || 90;
470 var date = new Date();
471 date.setTime(date.getTime()+(days*24*60*60*1000));
472 var expires = "; expires="+date.toGMTString();
473 doc.cookie = name+"="+value+expires+"; path=/";
474}
254function createCookie(name,value,days) {
255 /**
256 if (days) {
257 var date = new Date();
258 date.setTime(date.getTime()+(days*24*60*60*1000));
259 var expires = "; expires="+date.toGMTString();
260 } else {
261 expires = "";
262 } document.cookie = name+"="+value+expires+"; path=/";
263 **/
264}
700function Cookie(name, value) {
701 /**
702 * The name of the Cookie
703 * @type String
704 */
705 this.name = name;
706
707 /**
708 * The value of the Cookie
709 * @type String
710 */
711 this.value = value;
712
713 /**
714 * An optional date defining the lifetime of this cookie
715 * @type Date
716 */
717 this.expires = null;
718
719 /**
720 * An optional path where this cookie is valid
721 * @type String
722 */
723 this.path = null;
724
725 /**
726 * An optional domain where this cookie is valid
727 * @type String
728 */
729 this.domain = null;
730
731 return this;
732}
6setCookie(value: string, params?: any) {
7 this.cookie(this.key, value, params);
8}

Related snippets