Skip to content

Commit 9b01401

Browse files
committed
refactor: use external module
1 parent 50e5693 commit 9b01401

File tree

6 files changed

+20
-135
lines changed

6 files changed

+20
-135
lines changed

_tools/meta.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,15 @@ export const makeOptions = (version: string): BuildOptions => ({
4242
version: "1.1.0",
4343
subPath: "is_string",
4444
},
45+
"https://deno.land/x/http_utils@1.2.0/token.ts": {
46+
name: "@httpland/http-utils",
47+
version: "1.2.0",
48+
subPath: "token.js",
49+
},
50+
"https://deno.land/x/http_utils@1.2.0/list.ts": {
51+
name: "@httpland/http-utils",
52+
version: "1.2.0",
53+
subPath: "list.js",
54+
},
4555
},
4656
});

deps.ts

Lines changed: 5 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -2,77 +2,8 @@
22
// This module is browser compatible.
33

44
export { isString } from "https://deno.land/x/isx@1.1.0/is_string.ts";
5-
6-
// TODO:(miyauci) Packaging and externalization this module.
7-
8-
/** Types for uppercase letter. */
9-
export type UppercaseLetter =
10-
| "A"
11-
| "B"
12-
| "C"
13-
| "D"
14-
| "E"
15-
| "F"
16-
| "G"
17-
| "H"
18-
| "I"
19-
| "J"
20-
| "K"
21-
| "L"
22-
| "M"
23-
| "N"
24-
| "O"
25-
| "P"
26-
| "Q"
27-
| "R"
28-
| "S"
29-
| "T"
30-
| "U"
31-
| "V"
32-
| "W"
33-
| "X"
34-
| "Y"
35-
| "Z";
36-
37-
/** Types for lowercase letter. */
38-
export type LowercaseLetter = Lowercase<UppercaseLetter>;
39-
40-
/** Types for letter. */
41-
export type Letter = UppercaseLetter | LowercaseLetter;
42-
43-
/** Types for digit. */
44-
export type Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
45-
46-
/** Deserialize types. */
47-
export type Stringify<
48-
T extends string | number | bigint | boolean | null | undefined,
49-
> = `${T}`;
50-
51-
/** Representation of [`<DIGIT>`](https://www.rfc-editor.org/rfc/rfc5234#appendix-B.1). */
52-
export type DIGIT = Stringify<Digit>;
53-
54-
/** Representation of [`<ALPHA>`](https://www.rfc-editor.org/rfc/rfc5234#appendix-B.1). */
55-
export type ALPHA = Letter;
56-
57-
/** Representation of [`<tchar>`](https://www.rfc-editor.org/rfc/rfc9110#section-5.6.2-2). */
58-
export type TChar =
59-
| "!"
60-
| "#"
61-
| "$"
62-
| "%"
63-
| "&"
64-
| "'"
65-
| "*"
66-
| "+"
67-
| "-"
68-
| "."
69-
| "^"
70-
| "_"
71-
| "`"
72-
| "|"
73-
| "~"
74-
| ALPHA
75-
| DIGIT;
76-
77-
/** Representation of [`<token>`](https://www.rfc-editor.org/rfc/rfc9110#section-5.6.2-2). */
78-
export type Token = `${TChar}${string}`;
5+
export {
6+
isToken,
7+
type Token,
8+
} from "https://deno.land/x/http_utils@1.2.0/token.ts";
9+
export { parseListFields } from "https://deno.land/x/http_utils@1.2.0/list.ts";

parse.ts

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

4-
import { isTokenFormat } from "./utils.ts";
4+
import { isToken, parseListFields } from "./deps.ts";
55
import { Msg } from "./constants.ts";
66
import type { AcceptRanges } from "./types.ts";
77

@@ -18,13 +18,10 @@ import type { AcceptRanges } from "./types.ts";
1818
* @throws {SyntaxError} If the input is invalid [`<Accept-Ranges>`](https://www.rfc-editor.org/rfc/rfc9110.html#section-14.3-2) syntax.
1919
*/
2020
export function parseAcceptRanges(input: string): AcceptRanges {
21-
const acceptableRanges = input
22-
.trim()
23-
.split(",")
24-
.map((v) => v.trim());
21+
const acceptableRanges = parseListFields(input);
2522

2623
acceptableRanges.forEach((token) => {
27-
if (!isTokenFormat(token)) {
24+
if (!isToken(token)) {
2825
throw SyntaxError(`${Msg.InvalidSyntax} "${input}"`);
2926
}
3027
});

stringify.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { isString } from "./deps.ts";
2-
import { isTokenFormat } from "./utils.ts";
1+
import { isString, isToken } from "./deps.ts";
32
import { Msg } from "./constants.ts";
43

54
/** Serialize string of array into string.
@@ -20,7 +19,7 @@ export function stringifyAcceptRanges(
2019
const targets = isString(acceptRanges) ? [acceptRanges] : acceptRanges;
2120

2221
targets.forEach((rangeUnit) => {
23-
if (!isTokenFormat(rangeUnit)) {
22+
if (!isToken(rangeUnit)) {
2423
throw TypeError(`${Msg.InvalidRangeUnit} "${rangeUnit}"`);
2524
}
2625
});

utils.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

utils_test.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)