Skip to content

Commit f134bcc

Browse files
Merge pull request #4 from httpland/beta
Beta
2 parents bf2c888 + 2198b6b commit f134bcc

File tree

9 files changed

+142
-8
lines changed

9 files changed

+142
-8
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# [1.2.0-beta.1](https://github.com/httpland/http-utils/compare/1.1.0...1.2.0-beta.1) (2023-04-29)
2+
3+
4+
### Features
5+
6+
* **list:** add parser for list-based fields ([47f69bd](https://github.com/httpland/http-utils/commit/47f69bda005ef4adfabf34ad02e94e35cb51e06a))
7+
* **token:** export related types ([35e0839](https://github.com/httpland/http-utils/commit/35e08398e1ac369f1c20f5365fe5668b1840f0ba))
8+
19
# [1.1.0](https://github.com/httpland/http-utils/compare/1.0.0...1.1.0) (2023-04-29)
210

311

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,34 @@ assert(response.headers.get(header), value);
542542
assert(init !== response);
543543
```
544544

545+
## Lists
546+
547+
Compliant with
548+
[RFC 9110, 5.6.1. Lists](https://www.rfc-editor.org/rfc/rfc9110.html#section-5.6.1).
549+
550+
### parseListFields
551+
552+
Parse
553+
[list-based fields](https://www.rfc-editor.org/rfc/rfc9110.html#section-5.5-7)
554+
into array.
555+
556+
Strings enclosed in double quotes are safely handled.
557+
558+
```ts
559+
import { parseListFields } from "https://deno.land/x/http_utils@$VERSION/list.ts";
560+
import { assertEquals } from "https://deno.land/std@$VERSION/testing/asserts.ts";
561+
562+
assertEquals(parseListFields("foo , ,bar,charlie"), [
563+
"foo",
564+
"bar",
565+
"charlie",
566+
]);
567+
assertEquals(parseListFields(`"Sat, 04 May 1996", "Wed, 14 Sep 2005"`), [
568+
`"Sat, 04 May 1996"`,
569+
`"Wed, 14 Sep 2005"`,
570+
]);
571+
```
572+
545573
## Tokens
546574

547575
Compliant with
@@ -625,7 +653,8 @@ assertFalse(isQuotedPair("\\"));
625653
### isQuotedString
626654

627655
Whether the input is
628-
[quoted-string](https://www.rfc-editor.org/rfc/rfc9110.html#section-5.6.4-2).
656+
[quoted-string](https://www.rfc-editor.org/rfc/rfc9110.html#section-5.6.4-2) or
657+
not.
629658

630659
```ts
631660
import { isQuotedString } from "https://deno.land/x/http_utils@$VERSION/quoted_string.ts";

_tools/meta.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,15 @@ export const makeOptions = (version: string): BuildOptions => ({
102102
},
103103
packageManager: "pnpm",
104104
mappings: {
105-
"https://deno.land/x/isx@1.1.1/is_null.ts": {
105+
"https://deno.land/x/isx@1.3.1/is_null.ts": {
106106
name: "@miyauci/isx",
107-
version: "1.1.1",
108-
subPath: "is_null",
107+
version: "1.3.1",
108+
subPath: "is_null.js",
109+
},
110+
"https://deno.land/x/[email protected]/trim.ts": {
111+
name: "@miyauci/prelude",
112+
version: "1.2.0",
113+
subPath: "trim.js",
109114
},
110115
},
111116
});

deno.lock

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deps.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright 2023-latest the httpland authors. All rights reserved. MIT license.
22
// This module is browser compatible.
33

4-
export { isNull } from "https://deno.land/x/[email protected]/is_null.ts";
4+
export { isNull } from "https://deno.land/x/[email protected]/is_null.ts";
5+
export { trim } from "https://deno.land/x/[email protected]/trim.ts";

list.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2023-latest the httpland authors. All rights reserved. MIT license.
2+
// This module is browser compatible.
3+
4+
import { trim } from "./deps.ts";
5+
6+
/** Parse [list-based fields](https://www.rfc-editor.org/rfc/rfc9110.html#section-5.5-7) into array.
7+
* Strings enclosed in double quotes are safely handled.
8+
*
9+
* @example
10+
* ```ts
11+
* import { parseListFields } from "https://deno.land/x/http_utils@$VERSION/list.ts";
12+
* import { assertEquals } from "https://deno.land/std@$VERSION/testing/asserts.ts";
13+
*
14+
* assertEquals(parseListFields("foo , ,bar,charlie"), [
15+
* "foo",
16+
* "bar",
17+
* "charlie",
18+
* ]);
19+
* assertEquals(parseListFields(`"Sat, 04 May 1996", "Wed, 14 Sep 2005"`), [
20+
* `"Sat, 04 May 1996"`,
21+
* `"Wed, 14 Sep 2005"`,
22+
* ]);
23+
* ```
24+
*/
25+
export function parseListFields(input: string): string[] {
26+
return input
27+
.split(/,(?=(?:(?:[^"]*?"){2})*?[^"]*?$)/)
28+
.map(trim)
29+
.filter(Boolean);
30+
}

list_test.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { parseListFields } from "./list.ts";
2+
import { assertEquals, describe, it } from "./_dev_deps.ts";
3+
4+
describe("parseListFields", () => {
5+
it("should ", () => {
6+
const table: [string, string[]][] = [
7+
["", []],
8+
["a", ["a"]],
9+
["a, b, c", ["a", "b", "c"]],
10+
[" a, a , a ", ["a", "a", "a"]],
11+
[`"", `, [`""`]],
12+
[`","`, [`","`]],
13+
[`",", `, [`","`]],
14+
[`"," ,`, [`","`]],
15+
[`",,," ,`, [`",,,"`]],
16+
[`"," , " , "`, [`","`, `" , "`]],
17+
[`","abc,`, [`","abc`]],
18+
["a, b,,,,", ["a", "b"]],
19+
["a, b, c", ["a", "b", "c"]],
20+
["a,b,c", ["a", "b", "c"]],
21+
["a,,c", ["a", "c"]],
22+
[",,,", []],
23+
[`"a,b"`, [`"a,b"`]],
24+
[`"a,b",c, "d,e", f f , g `, [`"a,b"`, "c", `"d,e"`, "f f", "g"]],
25+
[` complex,pattern,"abc", "abc , def", ,,,, """, , ",""`, [
26+
"complex",
27+
"pattern",
28+
`"abc"`,
29+
`"abc , def"`,
30+
`""", , "`,
31+
`""`,
32+
]],
33+
[`",","`, [`"`, `","`]],
34+
[`",",","`, [`","`, `","`]],
35+
[`",",",",`, [`","`, `","`]],
36+
[`",",",","`, [`"`, `","`, `","`]],
37+
[`",",",",",`, [`"`, `","`, `","`]],
38+
[`",",",",","`, [`","`, `","`, `","`]],
39+
[`"`, [`"`]],
40+
[`""`, [`""`]],
41+
[`"""`, [`"""`]],
42+
[`""""`, [`""""`]],
43+
[`"",""`, [`""`, `""`]],
44+
[`",",`, [`","`]],
45+
[`"abc,def", "efg, hij", "lmn, opq"`, [
46+
'"abc,def"',
47+
'"efg, hij"',
48+
'"lmn, opq"',
49+
]],
50+
];
51+
52+
table.forEach(([input, expected]) => {
53+
assertEquals(parseListFields(input), expected);
54+
});
55+
});
56+
});

quoted_string.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export type QuotedString = `"${string}"`;
7272
const reQuotedString =
7373
/^"(?:[\t \x21\x23-\x5B\x5D-\x7E\x80-\xFF]|\\[\t \x21-\x7E\x80-\xFF])*?"$/;
7474

75-
/** Whether the input is [quoted-string](https://www.rfc-editor.org/rfc/rfc9110.html#section-5.6.4-2).
75+
/** Whether the input is [quoted-string](https://www.rfc-editor.org/rfc/rfc9110.html#section-5.6.4-2) or not.
7676
*
7777
* @example
7878
* ```ts

token.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ export type Tchar =
6464
*/
6565
const reToken = /^[\w!#$%&'*+.^`|~-]+$/;
6666

67+
/** Representation of [token](https://www.rfc-editor.org/rfc/rfc9110.html#section-5.6.2-2). */
68+
export type Token = `${Tchar}${string}`;
69+
6770
/** Whether the input is [token](https://www.rfc-editor.org/rfc/rfc9110.html#section-5.6.2-2) or not.
6871
*
6972
* @example
@@ -79,7 +82,7 @@ const reToken = /^[\w!#$%&'*+.^`|~-]+$/;
7982
* assertFalse(isToken(""));
8083
* ```
8184
*/
82-
export function isToken(input: string): input is `${Tchar}${string}` {
85+
export function isToken(input: string): input is Token {
8386
return reToken.test(input);
8487
}
8588

0 commit comments

Comments
 (0)