Skip to content

Commit 3126ef2

Browse files
committed
docs(parse): add code block
1 parent cd98dcf commit 3126ef2

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

parse.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,29 @@ const reAuthorization =
1414
/^(?<authScheme>[!#$%&'*+.^_`|~\dA-Za-z-]+)(?: +(?:(?<token68>(?:[A-Za-z]|\d|[-._~+/])+=*)|(?<authParam>.+)))?$/;
1515

1616
/** Parse string into {@link Authorization}.
17+
*
18+
* @example
19+
* ```ts
20+
* import { parseAuthorization } from "https://deno.land/x/authorization_parser@$VERSION/parse.ts";
21+
* import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
22+
*
23+
* const result = parseAuthorization("Basic token68");
24+
*
25+
* assertEquals(parseAuthorization("Basic token68"), {
26+
* authScheme: "Basic",
27+
* token: "token68",
28+
* });
29+
* assertEquals(
30+
* parseAuthorization(`Bearer realm="example", error="invalid_token"`),
31+
* {
32+
* authScheme: "Bearer",
33+
* token: {
34+
* realm: `"example"`,
35+
* error: `"invalid_token"`,
36+
* },
37+
* },
38+
* );
39+
* ```
1740
*
1841
* @throws {SyntaxError} If the input is invalid.
1942
* @throws {Error} If the auth param key is duplicated.

0 commit comments

Comments
 (0)