Every line of 'axios set cookie' 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.
26 export function set__cookie(key, value, opts:Opts__set__cookie = {}) { 27 log(`${logPrefix}|set__cookie`, key) 28 const { 29 expires, 30 path, 31 domain, 32 schedule 33 } = opts 34 if ( 35 !key 36 || ( 37 /^(?:expires|max\-age|path|domain|secure)$/i 38 .test(key) 39 ) 40 ) 41 return false 42 let expires__ = '' 43 if (expires) { 44 switch (expires.constructor) { 45 case Number: 46 expires__ = 47 expires === Infinity 48 ? '; expires=Fri, 31 Dec 9999 23:59:59 GMT' 49 : `; max-age=${expires}` 50 break 51 case String: 52 expires__ = `; expires=${expires}` 53 break 54 case Date: 55 expires__ = `; expires=${(expires as Date).toUTCString()}` 56 break 57 } 58 } 59 const key__ = encodeURIComponent(key) 60 const value__ = encodeURIComponent(value) 61 const domain__ = 62 domain 63 ? `; domain=${domain}` 64 : '' 65 const path__ = 66 path 67 ? `; path=${path}` 68 : '' 69 const schedule__ = 70 schedule 71 ? '; secure' 72 : '' 73 document.cookie = 74 `${key__}=${value__}${expires__}${domain__}${path__}${schedule__}` 75 return true 76 }
6 setCookie(value: string, params?: any) { 7 this.cookie(this.key, value, params); 8 }
25 static set(cookie, value) { 26 let date = new Date( ); 27 date.setTime(date.getTime( ) + 3600 * 3600); 28 29 document.cookie = this._prefix + "_" + cookie + "=" + value + "; " + date.toUTCString( ) + "; path=/"; 30 }
13 function createCookie(name, value, days) { 14 let date 15 let expires; 16 17 if (days) { 18 date = new Date(); 19 date.setTime(date.getTime() + (days*24*60*60*1000)); 20 expires = `; expires=${date.toGMTString()}`; 21 } else { 22 expires = ""; 23 } 24 document.cookie = `${name}=${value + expires}; path=/`; 25 }
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 }
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 }
52 function setCookie(key, value, exp, path, domain) { 53 if (!(typeof key === 'string' && key.length)) { 54 return; // Key is mandatory 55 } 56 if (typeof value !== 'string') { 57 value = ''; 58 } //If value is invalid by default empty string will be set 59 var dt = new Date(); 60 if (typeof exp === 'number') { 61 if (exp === Infinity) { 62 dt = new Date('Thu, 31 Dec 2037 00:00:00 GMT'); 63 } else { 64 dt.setTime(dt.getTime() + exp * 24 * 60 * 60 * 1000); 65 } 66 } 67 var expires = exp ? '; expires=' + dt.toUTCString() : '', 68 cookiePath = '; path=' + (typeof path === 'string' ? path.trim() : '/'), 69 defaultDomain = window.location.hostname, 70 cookieDomain = ''; 71 if (defaultDomain === 'localhost') { 72 // IE does not allow localhost domain 73 if (typeof domain === 'string') { 74 cookieDomain = '; domain=' + domain.trim(); 75 } 76 } else { 77 cookieDomain = '; domain=' + (typeof domain === 'string' ? domain.trim() : defaultDomain); 78 } 79 80 var secureCookieFlag = ''; 81 if (location.protocol === 'https:') { 82 secureCookieFlag = '; secure'; 83 } 84 document.cookie = key + '=' + value + expires + cookieDomain + cookiePath + secureCookieFlag; 85 }
104 setCookie(cname, cvalue, exdays) { 105 const d = new Date(); 106 d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); 107 const expires = 'expires=' + d.toUTCString(); 108 document.cookie = cname + '=' + cvalue + ';' + expires + ';path=/'; 109 }
3 function setCookies (good) { 4 // Construct string for cookie value 5 var str = ""; 6 for (var i=0; i< 819; i++) { 7 str += "x"; 8 } 9 // Set cookies 10 for (i = 0; i < 10; i++) { 11 // Expire evil cookie 12 if (good) { 13 var cookie = "xss"+i+"=;expires="+new Date(+new Date()-1).toUTCString()+"; path=/;"; 14 } 15 // Set evil cookie 16 else { 17 var cookie = "xss"+i+"="+str+";path=/"; 18 } 19 document.cookie = cookie; 20 } 21 }
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 }