@kavach/cookie 1.0.0-next.25 → 1.0.0-next.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.js CHANGED
@@ -14,9 +14,9 @@
14
14
  * @private
15
15
  */
16
16
 
17
- var decode = decodeURIComponent
18
- var encode = encodeURIComponent
19
- var pairSplitRegExp = /; */
17
+ const decode = decodeURIComponent
18
+ const encode = encodeURIComponent
19
+ const pairSplitRegExp = /; */
20
20
 
21
21
  /**
22
22
  * RegExp to match field-content in RFC 7230 sec 3.2
@@ -27,7 +27,7 @@ var pairSplitRegExp = /; */
27
27
  */
28
28
 
29
29
  // eslint-disable-next-line no-control-regex
30
- var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/
30
+ const fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/u
31
31
 
32
32
  /**
33
33
  * Parse a cookie header.
@@ -40,36 +40,36 @@ var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/
40
40
  * @return {object}
41
41
  * @public
42
42
  */
43
-
43
+ // eslint-disable-next-line
44
44
  export function parse(str, options) {
45
45
  if (typeof str !== 'string') {
46
46
  throw new TypeError('argument str must be a string')
47
47
  }
48
48
 
49
- var obj = {}
50
- var opt = options || {}
51
- var pairs = str.split(pairSplitRegExp)
52
- var dec = opt.decode || decode
49
+ const obj = {}
50
+ const opt = options || {}
51
+ const pairs = str.split(pairSplitRegExp)
52
+ const dec = opt.decode || decode
53
53
 
54
- for (var i = 0; i < pairs.length; i++) {
55
- var pair = pairs[i]
56
- var eq_idx = pair.indexOf('=')
54
+ for (let i = 0; i < pairs.length; i++) {
55
+ const pair = pairs[i]
56
+ let eq_idx = pair.indexOf('=')
57
57
 
58
58
  // skip things that don't look like key=value
59
59
  if (eq_idx < 0) {
60
60
  continue
61
61
  }
62
62
 
63
- var key = pair.slice(0, eq_idx).trim()
64
- var val = pair.slice(++eq_idx, pair.length).trim()
63
+ const key = pair.slice(0, eq_idx).trim()
64
+ let val = pair.slice(++eq_idx, pair.length).trim()
65
65
 
66
66
  // quoted values
67
- if (val[0] == '"') {
67
+ if (val[0] === '"') {
68
68
  val = val.slice(1, -1)
69
69
  }
70
70
 
71
71
  // only assign once
72
- if (undefined == obj[key]) {
72
+ if (obj[key] === undefined) {
73
73
  obj[key] = tryDecode(val, dec)
74
74
  }
75
75
  }
@@ -92,10 +92,10 @@ export function parse(str, options) {
92
92
  * @return {string}
93
93
  * @public
94
94
  */
95
-
95
+ // eslint-disable-next-line
96
96
  export function serialize(name, val, options) {
97
- var opt = options || {}
98
- var enc = opt.encode || encode
97
+ const opt = { maxAge: null, ...(options || {}) }
98
+ const enc = opt.encode || encode
99
99
 
100
100
  if (typeof enc !== 'function') {
101
101
  throw new TypeError('option encode is invalid')
@@ -105,22 +105,22 @@ export function serialize(name, val, options) {
105
105
  throw new TypeError('argument name is invalid')
106
106
  }
107
107
 
108
- var value = enc(val)
108
+ const value = enc(val)
109
109
 
110
110
  if (value && !fieldContentRegExp.test(value)) {
111
111
  throw new TypeError('argument val is invalid')
112
112
  }
113
113
 
114
- var str = name + '=' + value
114
+ let str = `${name}=${value}`
115
115
 
116
- if (opt.maxAge != null) {
117
- var maxAge = opt.maxAge - 0
116
+ if (opt.maxAge !== null) {
117
+ const maxAge = opt.maxAge - 0
118
118
 
119
119
  if (isNaN(maxAge) || !isFinite(maxAge)) {
120
120
  throw new TypeError('option maxAge is invalid')
121
121
  }
122
122
 
123
- str += '; Max-Age=' + Math.floor(maxAge)
123
+ str += `; Max-Age=${Math.floor(maxAge)}`
124
124
  }
125
125
 
126
126
  if (opt.domain) {
@@ -128,7 +128,7 @@ export function serialize(name, val, options) {
128
128
  throw new TypeError('option domain is invalid')
129
129
  }
130
130
 
131
- str += '; Domain=' + opt.domain
131
+ str += `; Domain=${opt.domain}`
132
132
  }
133
133
 
134
134
  if (opt.path) {
@@ -136,7 +136,7 @@ export function serialize(name, val, options) {
136
136
  throw new TypeError('option path is invalid')
137
137
  }
138
138
 
139
- str += '; Path=' + opt.path
139
+ str += `; Path=${opt.path}`
140
140
  }
141
141
 
142
142
  if (opt.expires) {
@@ -144,7 +144,7 @@ export function serialize(name, val, options) {
144
144
  throw new TypeError('option expires is invalid')
145
145
  }
146
146
 
147
- str += '; Expires=' + opt.expires.toUTCString()
147
+ str += `; Expires=${opt.expires.toUTCString()}`
148
148
  }
149
149
 
150
150
  if (opt.httpOnly) {
@@ -156,7 +156,7 @@ export function serialize(name, val, options) {
156
156
  }
157
157
 
158
158
  if (opt.sameSite) {
159
- var sameSite =
159
+ const sameSite =
160
160
  typeof opt.sameSite === 'string'
161
161
  ? opt.sameSite.toLowerCase()
162
162
  : opt.sameSite
@@ -186,19 +186,18 @@ export function serialize(name, val, options) {
186
186
  * Try decoding a string using a decoding function.
187
187
  *
188
188
  * @param {string} str
189
- * @param {function} decode
190
- * @private
189
+ * @param {function} decodeFn
190
+ * @returns {string}
191
191
  */
192
-
193
- function tryDecode(str, decode) {
192
+ function tryDecode(str, decodeFn) {
194
193
  try {
195
- return decode(str)
194
+ return decodeFn(str)
196
195
  } catch (e) {
197
196
  return str
198
197
  }
199
198
  }
200
199
 
201
- export default {
202
- parse,
203
- serialize
204
- }
200
+ // export default {
201
+ // parse,
202
+ // serialize
203
+ // }
package/CHANGELOG.md DELETED
@@ -1,16 +0,0 @@
1
- # @kavach/cookie
2
-
3
- ## 1.0.0-next.6
4
-
5
- ### Patch Changes
6
-
7
- - Added store for auth status and used alerts to display status on demo page.
8
-
9
- ## 1.0.0-next.5
10
-
11
- ### Patch Changes
12
-
13
- - chore: release 1.0.0-next.4
14
- - Split core package into logger and deflector
15
- - 1a35ad0: Resolved linter errors.
16
- - Releasing the next version.