Skip to content

Commit 2172828

Browse files
committed
fix formatting and linting issues
1 parent 7fa7984 commit 2172828

File tree

6 files changed

+58
-46
lines changed

6 files changed

+58
-46
lines changed

Diff for: .vscode/launch.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"--allow-all",
5353
"--allow-env"
5454
],
55-
"outputCapture": "std",
55+
"outputCapture": "std"
5656
}
5757
]
58-
}
58+
}

Diff for: .vscode/settings.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
"deno.enable": true,
33
"[typescript]": {
44
"editor.defaultFormatter": "denoland.vscode-deno",
5-
"editor.formatOnSave": true,
5+
"editor.formatOnSave": true
66
},
77
"[typescriptreact]": {
8-
"editor.defaultFormatter": "denoland.vscode-deno",
8+
"editor.defaultFormatter": "denoland.vscode-deno"
99
},
1010
"deno.unstable": true,
1111
"deno.lint": true,
1212
"debug.javascript.unmapMissingSources": true,
1313
"deno.import_intellisense_origins": {
1414
"https://deno.land": true
15-
},
16-
}
15+
}
16+
}

Diff for: CHANGELOG.md

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Changelog
32

43
## v4.1.0
@@ -24,7 +23,8 @@ Thanks @jonasb
2423
## v4.0.0
2524

2625
- BREAKING CHANGE: implement rfc6265 path matching properly and add test.
27-
- change `CookieJar.getCookieString()` to use `Cookie.canSendTo` function filtering cookies for a url
26+
- change `CookieJar.getCookieString()` to use `Cookie.canSendTo` function
27+
filtering cookies for a url
2828

2929
## v3.0.0
3030

@@ -57,7 +57,8 @@ Thanks @jonasb
5757

5858
## v2.2.2
5959

60-
- `CookieJar.setCookie()`: set cookie path from url's pathname if path is not defined inside cookie string (or Cookie). (it was already done for domain.)
60+
- `CookieJar.setCookie()`: set cookie path from url's pathname if path is not
61+
defined inside cookie string (or Cookie). (it was already done for domain.)
6162

6263
## v2.2.1
6364

@@ -73,14 +74,17 @@ Thanks @jonasb
7374

7475
## v2.1.0
7576

76-
- add `fetchFn` to wrap options. this allows you to wrap your fetch multiple times to add other helpers.
77+
- add `fetchFn` to wrap options. this allows you to wrap your fetch multiple
78+
times to add other helpers.
7779

7880
## v2.0.1
7981

8082
- fix headers not merged correctly and add test
8183

8284
## v2.0.0
8385

84-
- now `value`, `secure`, `httpOnly`, `maxAge`, `expires`, `sameSite` props will only be strictly checked only if
85-
when retrieving the cookies using `CookieOptions`, which means if you pass a cookie,
86-
it will only be checked if `name`, `path` and `domain` match. This should solve issue of replacing cookies.
86+
- now `value`, `secure`, `httpOnly`, `maxAge`, `expires`, `sameSite` props will
87+
only be strictly checked only if when retrieving the cookies using
88+
`CookieOptions`, which means if you pass a cookie, it will only be checked if
89+
`name`, `path` and `domain` match. This should solve issue of replacing
90+
cookies.

Diff for: README.md

+31-23
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
# deno-another-cookiejar
22

3-
This library offers a fetch wrapper that retain cookies. This library also provides a simple cookiejar;
3+
This library offers a fetch wrapper that retain cookies. This library also
4+
provides a simple cookiejar;
45

5-
Why the name ? because I didn't want to reserve the cookiejar name, since this library may not be good at it. (But I hope you like it)
6+
Why the name ? because I didn't want to reserve the cookiejar name, since this
7+
library may not be good at it. (But I hope you like it)
68

79
## usage
810

911
you can import `Cookie`, `CookieJar`, `wrapFetch` from `mod.ts` file.
1012

1113
```js
12-
import { Cookie, CookieJar, wrapFetch} from 'https://deno.land/x/[email protected]/mod.ts';
14+
import {
15+
Cookie,
16+
CookieJar,
17+
wrapFetch,
18+
} from "https://deno.land/x/[email protected]/mod.ts";
1319
```
1420

1521
### wrapFetch
@@ -30,8 +36,8 @@ const fetch = wrapFetch({ cookieJar });
3036
fetch("http://example.com");
3137
// and you can read your cookies from the jar
3238
cookieJar.getCookie({
33-
name: 'cookieName',
34-
})?.value // your cookie value
39+
name: "cookieName",
40+
})?.value; // your cookie value
3541
```
3642
3743
You can play around with it too see what it has to offer!
@@ -47,14 +53,14 @@ you can create cookies in two ways:
4753
```js
4854
// first: using Cookie constructor with CookieOptions
4955
const cookie = new Cookie({
50-
name: 'foo',
51-
value: 'bar'
56+
name: "foo",
57+
value: "bar",
5258
});
5359
```
5460
5561
```js
56-
// second:
57-
const cookie = Cookie.from('foo=bar;'); // any string from Set-Cookie header value is also valid.
62+
// second:
63+
const cookie = Cookie.from("foo=bar;"); // any string from Set-Cookie header value is also valid.
5864
```
5965
6066
### CookieJar
@@ -71,42 +77,42 @@ const cookieJar = new CookieJar(cookiesArray); // cookiesArray: Array<Cookie> |
7177
7278
#### Note on retrieving cookies (+v2.0.0)
7379
74-
You can get cookies using either `CookieOptions` or a `Cookie` itself.
75-
The difference is if you use `CookieOptions`, it will strictly check any prop that is passed against the cookie.
76-
But if you use a `Cookie` object, it will only check `name`, `path` and `domain`.
80+
You can get cookies using either `CookieOptions` or a `Cookie` itself. The
81+
difference is if you use `CookieOptions`, it will strictly check any prop that
82+
is passed against the cookie. But if you use a `Cookie` object, it will only
83+
check `name`, `path` and `domain`.
7784
7885
### JSON serializing `Cookie`
7986
8087
Each cookie object is easily serialized and deserialized. Example:
8188
8289
```js
83-
const exampleOption = { name: 'foo' , value: 'bar' };
90+
const exampleOption = { name: "foo", value: "bar" };
8491

8592
const myCookie = new Cookie(exampleOption);
8693

87-
new Cookie (
94+
new Cookie(
8895
JSON.parse(
89-
JSON.stringify(myCookie)
90-
)
96+
JSON.stringify(myCookie),
97+
),
9198
).toString() === myCookie.toString(); // true
92-
9399
```
94100
95101
### JSON serializing `CookieJar`
96102
97103
You can even easily serialize your `CookierJar`. Example:
98104
99105
```js
100-
const exampleOption = { name: 'foo' , value: 'bar' };
106+
const exampleOption = { name: "foo", value: "bar" };
101107

102108
const myCookie = new Cookie(exampleOption);
103109

104110
const cookieJar = new CookieJar([myCookie]);
105111

106-
new CookieJar (
112+
new CookieJar(
107113
JSON.parse(
108-
JSON.stringify(cookieJar)
109-
)
114+
JSON.stringify(cookieJar),
115+
),
110116
).cookies[0].toString() === myCookie.toString(); // true
111117
```
112118
@@ -118,8 +124,10 @@ run with `deno test --allow-net`
118124
119125
## notes
120126
121-
This library is only tested lightly. you can contribute to this if you want to make it better, but I probably won't add much feature/test anymore.
127+
This library is only tested lightly. you can contribute to this if you want to
128+
make it better, but I probably won't add much feature/test anymore.
122129
123-
This library does not strictly follow the specs, but does try to follow it loosely. just keep it in mind when using so you don't get surprises.
130+
This library does not strictly follow the specs, but does try to follow it
131+
loosely. just keep it in mind when using so you don't get surprises.
124132
125133
does not support handling of `__Secure-` and `__Host-` cookies.

Diff for: cookie_jar.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const MAX_TIME = 2147483647000; // 31-bit max
6060
/**
6161
* Cookies with longer paths are listed before cookies with
6262
* shorter paths.
63-
*
63+
*
6464
* Among cookies that have equal-length path fields, cookies with
6565
* earlier creation-times are listed before cookies with later
6666
* creation-times."
@@ -101,10 +101,10 @@ export class CookieJar {
101101
}
102102

103103
/**
104-
* Sets or replaces a cookie inside the jar.
104+
* Sets or replaces a cookie inside the jar.
105105
* Only sets new cookies if cookie is valid and not expired.
106106
* Validation and expiration checks are not run when replacing a cookie.
107-
* @param url - the url that this cookie from received from. mainly used by the fetch wrapper.
107+
* @param url - the url that this cookie from received from. mainly used by the fetch wrapper.
108108
* will automatically set domain and path if provided and it was not found inside Cookie/cookiestring.
109109
*/
110110
setCookie(cookie: Cookie | string, url?: string | Request | URL) {
@@ -143,7 +143,7 @@ export class CookieJar {
143143
this.cookies.sort(cookieCompare);
144144
}
145145

146-
/**
146+
/**
147147
* Gets the first cooking matching the defined properties of a given Cookie or CookieOptions.
148148
* returns undefined if not found or expired. `creationDate` prop is not checked.
149149
* Also removes the cookie and returns undefined if cookie is expired.
@@ -208,8 +208,8 @@ export class CookieJar {
208208
}
209209

210210
/**
211-
* Removes first cookie that matches the given option.
212-
*
211+
* Removes first cookie that matches the given option.
212+
*
213213
* Returns the deleted cookie if found or undefined otherwise.
214214
*/
215215
removeCookie(options: CookieOptions | Cookie): Cookie | undefined {
@@ -223,13 +223,13 @@ export class CookieJar {
223223
/**
224224
* Removes all cookies that matches the given option.
225225
* If options is not given, all cookies will be deleted.
226-
*
226+
*
227227
* Returns the deleted cookies if found or undefined otherwise.
228228
*/
229229
removeCookies(options?: CookieOptions | Cookie): Array<Cookie> | undefined {
230230
if (options) {
231231
const deletedCookies: Cookie[] = [];
232-
this.cookies = this.cookies.filter((cookie, index) => {
232+
this.cookies = this.cookies.filter((cookie) => {
233233
if (cookieMatches(options, cookie)) {
234234
deletedCookies.push(cookie);
235235
return false;

Diff for: fetch_wrapper_test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ handlers = [];
1717

1818
async function handleServer1() {
1919
await delay(100);
20-
server1 = serve({ hostname: "0.0.0.0", port: 54933 });
20+
server1 = serve({ hostname: "localhost", port: 54933 });
2121
for await (const request of server1) {
2222
if (request.url === "/") {
2323
const bodyContent = request.headers.get("cookie") || "";
@@ -34,7 +34,7 @@ async function handleServer1() {
3434

3535
async function handleServer2() {
3636
await delay(100);
37-
server2 = serve({ hostname: "0.0.0.0", port: 54934 });
37+
server2 = serve({ hostname: "localhost", port: 54934 });
3838
for await (const request of server2) {
3939
if (request.url === "/") {
4040
const bodyContent = request.headers.get("cookie") || "";

0 commit comments

Comments
 (0)