@@ 52-93 (lines=42) @@ | ||
49 | * |
|
50 | * @throws {TypeError} if argument sCookieName is empty or not a string |
|
51 | */ |
|
52 | set: function(sCookieName, sValue, oAttributes) { |
|
53 | var sAttributes = ''; |
|
54 | ||
55 | sValue = sValue || ''; |
|
56 | ||
57 | if (!sCookieName || typeof sCookieName !== 'string') { |
|
58 | throwTypeError('sCookieName', 'string'); |
|
59 | } |
|
60 | ||
61 | if (typeof sValue !== 'string') { |
|
62 | throwTypeError('sValue', 'string'); |
|
63 | } |
|
64 | ||
65 | if (oAttributes === undefined) { |
|
66 | sAttributes += '; path=/'; |
|
67 | } else { |
|
68 | if (typeof oAttributes !== 'object' || Array.isArray(oAttributes)) { |
|
69 | throwTypeError('oAttributes', 'object'); |
|
70 | } |
|
71 | ||
72 | Object.keys(oAttributes).forEach(function(sAttr) { |
|
73 | if (sAttr === 'secure') { |
|
74 | if (oAttributes[sAttr] === true || oAttributes[sAttr] === 'true') { |
|
75 | sAttributes += ';' + sAttr; |
|
76 | return; |
|
77 | } else { |
|
78 | throwTypeError(sAttr, 'boolean'); |
|
79 | } |
|
80 | } else if (typeof oAttributes[sAttr] !== 'string') { |
|
81 | throwTypeError(sAttr, 'string'); |
|
82 | } |
|
83 | ||
84 | sAttributes += ';' + sAttr + '=' + oAttributes[sAttr]; |
|
85 | }); |
|
86 | } |
|
87 | ||
88 | cookiejs.global.cookie = |
|
89 | encodeURIComponent(sCookieName) + |
|
90 | '=' + |
|
91 | encodeURIComponent(sValue) + |
|
92 | sAttributes; |
|
93 | }, |
|
94 | ||
95 | /** |
|
96 | * returns the value of a cookie |
@@ 31-72 (lines=42) @@ | ||
28 | * |
|
29 | * @throws {TypeError} if argument sCookieName is empty or not a string |
|
30 | */ |
|
31 | set: function(sCookieName, sValue, oAttributes) { |
|
32 | var sAttributes = ''; |
|
33 | ||
34 | sValue = sValue || ''; |
|
35 | ||
36 | if (!sCookieName || typeof sCookieName !== 'string') { |
|
37 | throwTypeError('sCookieName', 'string'); |
|
38 | } |
|
39 | ||
40 | if (typeof sValue !== 'string') { |
|
41 | throwTypeError('sValue', 'string'); |
|
42 | } |
|
43 | ||
44 | if (oAttributes === undefined) { |
|
45 | sAttributes += '; path=/'; |
|
46 | } else { |
|
47 | if (typeof oAttributes !== 'object' || Array.isArray(oAttributes)) { |
|
48 | throwTypeError('oAttributes', 'object'); |
|
49 | } |
|
50 | ||
51 | Object.keys(oAttributes).forEach(function(sAttr) { |
|
52 | if (sAttr === 'secure') { |
|
53 | if (oAttributes[sAttr] === true || oAttributes[sAttr] === 'true') { |
|
54 | sAttributes += ';' + sAttr; |
|
55 | return; |
|
56 | } else { |
|
57 | throwTypeError(sAttr, 'boolean'); |
|
58 | } |
|
59 | } else if (typeof oAttributes[sAttr] !== 'string') { |
|
60 | throwTypeError(sAttr, 'string'); |
|
61 | } |
|
62 | ||
63 | sAttributes += ';' + sAttr + '=' + oAttributes[sAttr]; |
|
64 | }); |
|
65 | } |
|
66 | ||
67 | cookiejs.global.cookie = |
|
68 | encodeURIComponent(sCookieName) + |
|
69 | '=' + |
|
70 | encodeURIComponent(sValue) + |
|
71 | sAttributes; |
|
72 | }, |
|
73 | ||
74 | /** |
|
75 | * returns the value of a cookie |