Every line of 'js-cookie npm' 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.
33 function 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 }
1 module.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 }
24 function createCookie(namespace, value, days, opts) { 25 value = encodeURIComponent(value); 26 days = days || default_days; 27 var date = new Date(); 28 date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); 29 30 var cookiePath = opts.path || path; 31 32 var cookieDataArray = [ 33 namespace + '=' + value, 34 'expires=' + date.toGMTString(), 35 'path=' + (opts.isPathless ? '/' : cookiePath) 36 ]; 37 if (opts.domain){ 38 cookieDataArray.push('domain='+opts.domain); 39 } 40 if (opts.secure){ 41 cookieDataArray.push('secure'); 42 } 43 document.cookie = cookieDataArray.join('; '); 44 }
254 function 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 }
25 function 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 }
468 function 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 }
99 function 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 }
23 export function setCookie(name, value = '', expireDays, path) { 24 const expiresDate = Date.now() + expireDays * 24 * 60 * 60 * 1000; 25 const expiresTime = new Date(expiresDate).toUTCString(); 26 //http://stackoverflow.com/questions/1134290/cookies-on-localhost-with-explicit-domain 27 const cookie = `${name}=${value}; expires=${expiresTime}; path=${path}`; 28 return (document.cookie = cookie); 29 }
13 export function setCookie(name, value = '', expireDays, path) { 14 const expiresDate = Date.now() + expireDays * 24 * 60 * 60 * 1000 15 const expiresTime = new Date(expiresDate).toUTCString() 16 //http://stackoverflow.com/questions/1134290/cookies-on-localhost-with-explicit-domain 17 const cookie = `${name}=${value}; expires=${expiresTime}; path=${path}` 18 return document.cookie = cookie 19 }
66 function createCookie(name,value) 67 { 68 var days = 100; 69 70 var date = new Date(); 71 date.setTime(date.getTime()+(days*24*60*60*1000)); 72 var expires = "; expires="+date.toUTCString(); 73 74 document.cookie = name+"="+value+expires+"; path=/"; 75 }