Skip to content

Commit b9dd09c

Browse files
Merge pull request #2 from httpland/beta
Beta
2 parents 23abf77 + 18be7db commit b9dd09c

File tree

8 files changed

+630
-15
lines changed

8 files changed

+630
-15
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# [1.1.0-beta.1](https://github.com/httpland/http-utils/compare/1.0.0...1.1.0-beta.1) (2023-04-29)
2+
3+
4+
### Features
5+
6+
* **quoted_string:** add `isQdtext` function ([dfcd316](https://github.com/httpland/http-utils/commit/dfcd3167b159f5515aed07adf97fa2a48239ce48))
7+
* **quoted_string:** add `isQuotedString` function ([ca5dee2](https://github.com/httpland/http-utils/commit/ca5dee2bdd585e5731c40980e3074e0ffd50a0fd))
8+
* **quoted_string:** add `isQuotedString` function ([3c2f5a9](https://github.com/httpland/http-utils/commit/3c2f5a9b5dda5d6042f7db51620054991f824bd6))
9+
* **token:** add http token utilities ([c11449f](https://github.com/httpland/http-utils/commit/c11449f772bd8e15abf51bb1ef68ff2e595ccb88))
10+
* **token:** improve type inference ([a2b87b9](https://github.com/httpland/http-utils/commit/a2b87b9a4759121204c65878cd152265b2c9769b))
11+
112
# 1.0.0 (2023-04-02)
213

314

README.md

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

545+
## Tokens
546+
547+
Compliant with
548+
[RFC 9110, 5.6.2. Tokens](https://www.rfc-editor.org/rfc/rfc9110.html#section-5.6.2).
549+
550+
### isTchar
551+
552+
Whether the input is
553+
[tchar](https://www.rfc-editor.org/rfc/rfc9110.html#section-5.6.2-2) or not.
554+
555+
```ts
556+
import { isTchar } from "https://deno.land/x/http_utils@$VERSION/token.ts";
557+
import {
558+
assert,
559+
assertFalse,
560+
} from "https://deno.land/std@$VERSION/testing/asserts.ts";
561+
562+
assert(isTchar("!"));
563+
assert(isTchar("a"));
564+
assert(isTchar("Z"));
565+
assertFalse(isTchar(""));
566+
```
567+
568+
### isToken
569+
570+
Whether the input is
571+
[token](https://www.rfc-editor.org/rfc/rfc9110.html#section-5.6.2-2) or not.
572+
573+
```ts
574+
import { isToken } from "https://deno.land/x/http_utils@$VERSION/token.ts";
575+
import {
576+
assert,
577+
assertFalse,
578+
} from "https://deno.land/std@$VERSION/testing/asserts.ts";
579+
580+
assert(isToken("token"));
581+
assert(isToken("*!~"));
582+
assertFalse(isToken(""));
583+
```
584+
585+
## Quoted Strings
586+
587+
Compliant with
588+
[RFC 9110, 5.6.4. Quoted Strings](https://www.rfc-editor.org/rfc/rfc9110.html#section-5.6.4).
589+
590+
### isQdtext
591+
592+
Whether the input is
593+
[qdtext](https://www.rfc-editor.org/rfc/rfc9110.html#section-5.6.4-2) or not.
594+
595+
```ts
596+
import { isQdtext } from "https://deno.land/x/http_utils@$VERSION/quoted_string.ts";
597+
import {
598+
assert,
599+
assertFalse,
600+
} from "https://deno.land/std@$VERSION/testing/asserts.ts";
601+
602+
assert(isQdtext("\t"));
603+
assert(isQdtext("\xFF"));
604+
assertFalse(isQdtext(`"`));
605+
```
606+
607+
### isQuotedPair
608+
609+
Whether the input is
610+
[quoted-pair](https://www.rfc-editor.org/rfc/rfc9110.html#section-5.6.4-4) or
611+
not.
612+
613+
```ts
614+
import { isQuotedPair } from "https://deno.land/x/http_utils@$VERSION/quoted_string.ts";
615+
import {
616+
assert,
617+
assertFalse,
618+
} from "https://deno.land/std@$VERSION/testing/asserts.ts";
619+
620+
assert(isQuotedPair("\\\t"));
621+
assert(isQuotedPair("\\\xFF"));
622+
assertFalse(isQuotedPair("\\"));
623+
```
624+
625+
### isQuotedString
626+
627+
Whether the input is
628+
[quoted-string](https://www.rfc-editor.org/rfc/rfc9110.html#section-5.6.4-2).
629+
630+
```ts
631+
import { isQuotedString } from "https://deno.land/x/http_utils@$VERSION/quoted_string.ts";
632+
import {
633+
assert,
634+
assertFalse,
635+
} from "https://deno.land/std@$VERSION/testing/asserts.ts";
636+
637+
assert(isQuotedString(`""`));
638+
assert(isQuotedString(`"qdtext"`));
639+
assert(isQuotedString(`"quoted-pair"`));
640+
assertFalse(isQuotedString(""));
641+
```
642+
545643
## License
546644

547645
Copyright © 2023-present [httpland](https://github.com/httpland).

_tools/publish_npm.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ if (import.meta.main) {
1616
const tag = isPrerelease?.[0] ?? "latest";
1717

1818
const pkg = makeOptions(version);
19-
const result = await Deno.run({
20-
cmd: ["npm", "publish", pkg.outDir, "--tag", String(tag)],
21-
stdout: "piped",
22-
})
23-
.output();
19+
const command = new Deno.Command("npm", {
20+
args: ["publish", pkg.outDir, "--tag", String(tag)],
21+
});
22+
const result = await command.output();
2423

25-
console.log(new TextDecoder().decode(result));
24+
if (!result.success) {
25+
console.error(new TextDecoder().decode(result.stderr));
26+
}
2627
}

deno.json

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,12 @@
44
"build:npm": "deno run -A _tools/build_npm.ts"
55
},
66
"fmt": {
7-
"files": {
8-
"exclude": ["CHANGELOG.md", "CODE_OF_CONDUCT.md"]
9-
}
7+
"exclude": ["CHANGELOG.md", "CODE_OF_CONDUCT.md"]
108
},
119
"lint": {
12-
"files": {
13-
"exclude": ["CHANGELOG.md", "CODE_OF_CONDUCT.md"]
14-
}
10+
"exclude": ["CHANGELOG.md", "CODE_OF_CONDUCT.md"]
1511
},
1612
"test": {
17-
"files": {
18-
"exclude": ["CHANGELOG.md", "CODE_OF_CONDUCT.md"]
19-
}
13+
"exclude": ["CHANGELOG.md", "CODE_OF_CONDUCT.md"]
2014
}
2115
}

quoted_string.ts

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// Copyright 2023-latest the httpland authors. All rights reserved. MIT license.
2+
// This module is browser compatible.
3+
4+
/**
5+
* ```abnf
6+
* obs-text = %x80-FF
7+
* qdtext = HTAB / SP / %x21 / %x23-5B / %x5D-7E / obs-text
8+
* ```
9+
*/
10+
const reQdtext = /^[\t \x21\x23-\x5B\x5D-\x7E\x80-\xFF]$/;
11+
12+
/** Whether the input is [qdtext](https://www.rfc-editor.org/rfc/rfc9110.html#section-5.6.4-2) or not.
13+
*
14+
* @example
15+
* ```ts
16+
* import { isQdtext } from "https://deno.land/x/http_utils@$VERSION/quoted_string.ts";
17+
* import {
18+
* assert,
19+
* assertFalse,
20+
* } from "https://deno.land/std@$VERSION/testing/asserts.ts";
21+
*
22+
* assert(isQdtext("\t"));
23+
* assert(isQdtext("\xFF"));
24+
* assertFalse(isQdtext(`"`));
25+
* ```
26+
*/
27+
export function isQdtext(input: string): boolean {
28+
return reQdtext.test(input);
29+
}
30+
31+
/**
32+
* ```abnf
33+
* obs-text = %x80-FF
34+
* quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text )
35+
* ```
36+
*/
37+
const reQuotedPair = /^\\[\t \x21-\x7E\x80-\xFF]$/;
38+
39+
/** [Quoted pair](https://www.rfc-editor.org/rfc/rfc9110.html#section-5.6.4-4). */
40+
export type QuotedPair = `\\${string}`;
41+
42+
/** Whether the input is [quoted-pair](https://www.rfc-editor.org/rfc/rfc9110.html#section-5.6.4-4) or not.
43+
*
44+
* @example
45+
* ```ts
46+
* import { isQuotedPair } from "https://deno.land/x/http_utils@$VERSION/quoted_string.ts";
47+
* import {
48+
* assert,
49+
* assertFalse,
50+
* } from "https://deno.land/std@$VERSION/testing/asserts.ts";
51+
*
52+
* assert(isQuotedPair("\\\t"));
53+
* assert(isQuotedPair("\\\xFF"));
54+
* assertFalse(isQuotedPair("\\"));
55+
* ```
56+
*/
57+
export function isQuotedPair(input: string): input is QuotedPair {
58+
return reQuotedPair.test(input);
59+
}
60+
61+
/** [quoted-string](https://www.rfc-editor.org/rfc/rfc9110.html#section-5.6.4-2). */
62+
export type QuotedString = `"${string}"`;
63+
64+
/**
65+
* ```abnf
66+
* quoted-string = DQUOTE *( qdtext / quoted-pair ) DQUOTE
67+
* qdtext = HTAB / SP / %x21 / %x23-5B / %x5D-7E / obs-text
68+
* quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text )
69+
* obs-text = %x80-FF
70+
* ```
71+
*/
72+
const reQuotedString =
73+
/^"(?:[\t \x21\x23-\x5B\x5D-\x7E\x80-\xFF]|\\[\t \x21-\x7E\x80-\xFF])*?"$/;
74+
75+
/** Whether the input is [quoted-string](https://www.rfc-editor.org/rfc/rfc9110.html#section-5.6.4-2).
76+
*
77+
* @example
78+
* ```ts
79+
* import { isQuotedString } from "https://deno.land/x/http_utils@$VERSION/quoted_string.ts";
80+
* import {
81+
* assert,
82+
* assertFalse,
83+
* } from "https://deno.land/std@$VERSION/testing/asserts.ts";
84+
*
85+
* assert(isQuotedString(`""`));
86+
* assert(isQuotedString(`"qdtext"`));
87+
* assert(isQuotedString(`"quoted-pair"`));
88+
* assertFalse(isQuotedString(""));
89+
* ```
90+
*/
91+
export function isQuotedString(input: string): input is QuotedString {
92+
return reQuotedString.test(input);
93+
}

0 commit comments

Comments
 (0)