You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+19-19Lines changed: 19 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,31 +9,31 @@
9
9
## Synopsis
10
10
11
11
```javascript
12
-
var tough =require("tough-cookie");
13
-
var Cookie =tough.Cookie;
14
-
var cookie =Cookie.parse(header);
15
-
cookie.value="somethingdifferent";
16
-
header =cookie.toString();
17
-
var cookiejar =newtough.CookieJar();
12
+
var tough =require('tough-cookie')
13
+
var Cookie =tough.Cookie
14
+
var cookie =Cookie.parse(header)
15
+
cookie.value='somethingdifferent'
16
+
header =cookie.toString()
17
+
var cookiejar =newtough.CookieJar()
18
18
19
19
// Asynchronous!
20
20
var cookie =awaitcookiejar.setCookie(
21
21
cookie,
22
-
"https://currentdomain.example.com/path"
23
-
);
24
-
var cookies =awaitcookiejar.getCookies("https://example.com/otherpath");
22
+
'https://currentdomain.example.com/path',
23
+
)
24
+
var cookies =awaitcookiejar.getCookies('https://example.com/otherpath')
25
25
26
26
// Or with callbacks!
27
27
cookiejar.setCookie(
28
28
cookie,
29
-
"https://currentdomain.example.com/path",
29
+
'https://currentdomain.example.com/path',
30
30
function (err, cookie) {
31
31
/* ... */
32
-
}
33
-
);
34
-
cookiejar.getCookies("http://example.com/otherpath", function (err, cookies) {
32
+
},
33
+
)
34
+
cookiejar.getCookies('http://example.com/otherpath', function (err, cookies) {
35
35
/* ... */
36
-
});
36
+
})
37
37
```
38
38
39
39
Why the name? NPM modules `cookie`, `cookies` and `cookiejar` were already taken.
@@ -113,8 +113,8 @@ For use with `.sort()`, sorts a list of cookies into the recommended order given
113
113
```javascript
114
114
var cookies = [
115
115
/* unsorted array of Cookie objects */
116
-
];
117
-
cookies =cookies.sort(cookieCompare);
116
+
]
117
+
cookies =cookies.sort(cookieCompare)
118
118
```
119
119
120
120
> **Note**: Since the JavaScript `Date` is limited to a 1-ms precision, cookies within the same millisecond are entirely possible. This is especially true when using the `now` option to `.setCookie()`. The `.creationIndex` property is a per-process global counter, assigned during construction with `new Cookie()`, which preserves the spirit of the RFC sorting: older cookies go first. This works great for `MemoryCookieStore` since `Set-Cookie` headers are parsed in order, but is not so great for distributed systems. Sophisticated `Store`s may wish to set this to some other _logical clock_ so that if cookies A and B are created in the same millisecond, but cookie A is created before cookie B, then `A.creationIndex < B.creationIndex`. If you want to alter the global counter, which you probably _shouldn't_ do, it's stored in `Cookie.cookiesCreated`.
@@ -144,9 +144,9 @@ If options is not an object it is ignored, which means it can be used with [`Arr
144
144
To process the Set-Cookie header(s) on a node HTTP/HTTPS response:
145
145
146
146
```javascript
147
-
if (Array.isArray(res.headers["set-cookie"]))
148
-
cookies =res.headers["set-cookie"].map(Cookie.parse);
149
-
else cookies = [Cookie.parse(res.headers["set-cookie"])];
147
+
if (Array.isArray(res.headers['set-cookie']))
148
+
cookies =res.headers['set-cookie'].map(Cookie.parse)
149
+
else cookies = [Cookie.parse(res.headers['set-cookie'])]
150
150
```
151
151
152
152
_Note:_ In version 2.3.3, tough-cookie limited the number of spaces before the `=` to 256 characters. This limitation was removed in version 2.3.4.
0 commit comments