-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bump deps, replace barely maintained deps with source code
- Loading branch information
v1rtl
committed
Aug 28, 2021
1 parent
a408455
commit 2fa2c9d
Showing
25 changed files
with
959 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
import { Accepts } from '../../deps.ts' | ||
import { Accepts } from '../../utils/accepts.ts' | ||
import type { Req } from '../../deps.ts' | ||
|
||
export const getAccepts = <Request extends Req = Req>(req: Request) => (...types: string[]) => | ||
new Accepts(req.headers).types(types) | ||
export const getAccepts = | ||
<Request extends Req = Req>(req: Request) => | ||
(...types: string[]) => | ||
new Accepts(req.headers).types(types) | ||
|
||
export const getAcceptsEncodings = <Request extends Req = Req>(req: Request) => (...encodings: string[]) => | ||
new Accepts(req.headers).encodings(encodings) | ||
export const getAcceptsEncodings = | ||
<Request extends Req = Req>(req: Request) => | ||
(...encodings: string[]) => | ||
new Accepts(req.headers).encodings(encodings) | ||
|
||
export const getAcceptsCharsets = <Request extends Req = Req>(req: Request) => (...charsets: string[]) => | ||
new Accepts(req.headers).charsets(charsets) | ||
export const getAcceptsCharsets = | ||
<Request extends Req = Req>(req: Request) => | ||
(...charsets: string[]) => | ||
new Accepts(req.headers).charsets(charsets) | ||
|
||
export const getAcceptsLanguages = <Request extends Req = Req>(req: Request) => (...languages: string[]) => | ||
new Accepts(req.headers).languages(languages) | ||
export const getAcceptsLanguages = | ||
<Request extends Req = Req>(req: Request) => | ||
(...languages: string[]) => | ||
new Accepts(req.headers).languages(languages) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { assertEquals } from 'https://deno.land/std@0.104.0/testing/asserts.ts' | ||
import { Accepts } from '../../../utils/accepts.ts' | ||
|
||
const { test } = Deno | ||
|
||
function createRequest(charset?: string) { | ||
const header = new Headers() | ||
if (charset !== undefined) { | ||
header.set('accept-charset', charset) | ||
} | ||
return header | ||
} | ||
|
||
test('accepts.charsets() with no arguments when Accept-Charset is populated should return accepted types', function () { | ||
const header = createRequest('utf-8, iso-8859-1;q=0.2, utf-7;q=0.5') | ||
const accept = new Accepts(header) | ||
assertEquals(accept.charsets(), ['utf-8', 'utf-7', 'iso-8859-1']) | ||
}) | ||
|
||
test('accepts.charsets() when Accept-Charset is not in request should return *', function () { | ||
const header = createRequest() | ||
const accept = new Accepts(header) | ||
assertEquals(accept.charsets(), ['*']) | ||
}) | ||
|
||
test('accepts.charsets() when Accept-Charset is empty should return an empty array', function () { | ||
const header = createRequest('') | ||
const accept = new Accepts(header) | ||
assertEquals(accept.charsets(), []) | ||
}) | ||
|
||
test('accepts.charsets() with multiple arguments when Accept-Charset is populated if any types match should return the best fit', function () { | ||
const header = createRequest('utf-8, iso-8859-1;q=0.2, utf-7;q=0.5') | ||
const accept = new Accepts(header) | ||
assertEquals(accept.charsets(['utf-7', 'utf-8']), 'utf-8') | ||
}) | ||
|
||
test('accepts.charsets() with multiple arguments when Accept-Charset is populated if no types match should return []', function () { | ||
const header = createRequest('utf-8, iso-8859-1;q=0.2, utf-7;q=0.5') | ||
const accept = new Accepts(header) | ||
assertEquals(accept.charsets(['utf-16']), false) | ||
}) | ||
|
||
test('accepts.charsets() with multiple arguments when Accept-Charset is populated when Accept-Charset is not populated should return the first type', function () { | ||
const header = createRequest() | ||
const accept = new Accepts(header) | ||
assertEquals(accept.charsets(['utf-7', 'utf-8']), 'utf-7') | ||
}) | ||
|
||
test('accepts.charsets() with an array should return the best fit', function () { | ||
const header = createRequest('utf-8, iso-8859-1;q=0.2, utf-7;q=0.5') | ||
const accept = new Accepts(header) | ||
assertEquals(accept.charsets(['utf-7', 'utf-8']), 'utf-8') | ||
}) |
Oops, something went wrong.