Skip to content

Commit 8c2cd93

Browse files
committed
chore: initial commit
0 parents  commit 8c2cd93

6 files changed

Lines changed: 159 additions & 0 deletions

File tree

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.md]
13+
trim_trailing_whitespace = false

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.DS_Store
2+
Thumbs.db
3+
npm/
4+
coverage

.vscode/extensions.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recommendations": [
3+
"denoland.vscode-deno"
4+
]
5+
}

.vscode/settings.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"editor.defaultFormatter": "denoland.vscode-deno",
3+
"editor.formatOnSave": true,
4+
"editor.codeActionsOnSave": {
5+
"source.fixAll": true
6+
},
7+
"deno.enable": true,
8+
"deno.codeLens.referencesAllFunctions": true,
9+
"deno.internalDebug": true,
10+
"deno.lint": true,
11+
"deno.suggest.completeFunctionCalls": true,
12+
"deno.unstable": true,
13+
"deno.codeLens.references": true,
14+
"deno.suggest.autoImports": true,
15+
"deno.suggest.names": true,
16+
"deno.suggest.imports.autoDiscover": true,
17+
"deno.suggest.paths": true,
18+
"deno.codeLens.test": true,
19+
"deno.codeLens.implementations": true,
20+
"deno.codeLens.testArgs": [
21+
"--allow-all"
22+
]
23+
}

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
MIT License
2+
3+
Copyright (c) 2023 httpland
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# response-utils
2+
3+
[![deno land](http://img.shields.io/badge/available%20on-deno.land/x-lightgrey.svg?logo=deno)](https://deno.land/x/response_utils)
4+
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/httpland/response-utils)](https://github.com/httpland/response-utils/releases)
5+
[![codecov](https://codecov.io/github/httpland/response-utils/branch/main/graph/badge.svg)](https://codecov.io/gh/httpland/response-utils)
6+
[![GitHub](https://img.shields.io/github/license/httpland/response-utils)](https://github.com/httpland/response-utils/blob/main/LICENSE)
7+
8+
[![test](https://github.com/httpland/response-utils/actions/workflows/test.yaml/badge.svg)](https://github.com/httpland/response-utils/actions/workflows/test.yaml)
9+
[![NPM](https://nodei.co/npm/@httpland/response-utils.png?mini=true)](https://nodei.co/npm/@httpland/response-utils/)
10+
11+
Response utility collection.
12+
13+
## createResponse
14+
15+
Create a new `Response`
16+
17+
If you create a new `Response` from an existing `Response`, any options you set
18+
in an options argument for the new response replace any corresponding options
19+
set in the original `Response`.
20+
21+
```ts
22+
import { createResponse } from "https://deno.land/x/response_utils@$VERSION/create.ts";
23+
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
24+
25+
declare const init: Response;
26+
const response = createResponse(init, { status: 201 });
27+
28+
assertEquals(response.status, 201);
29+
```
30+
31+
## equalsResponse
32+
33+
Check two `Response` fields equality.
34+
35+
```ts
36+
import { equalsResponse } from "https://deno.land/x/response_utils@$VERSION/equal.ts";
37+
import { assert } from "https://deno.land/std/testing/asserts.ts";
38+
39+
assert(
40+
equalsResponse(
41+
new Response(null, { status: 204, headers: { "content-length": "0" } }),
42+
new Response(null, { status: 204, headers: { "content-length": "0" } }),
43+
),
44+
);
45+
```
46+
47+
If you also want to check the equivalence of the body, set the mode to strict.
48+
49+
```ts
50+
import { equalsResponse } from "https://deno.land/x/response_utils@$VERSION/equal.ts";
51+
import { assert } from "https://deno.land/std/testing/asserts.ts";
52+
53+
assert(
54+
await equalsResponse(
55+
new Response("test1", { status: 200, headers: { "content-length": "5" } }),
56+
new Response("test2", { status: 200, headers: { "content-length": "5" } }),
57+
true,
58+
),
59+
);
60+
```
61+
62+
### Throwing error
63+
64+
In strict mode, if response body has already been read.
65+
66+
```ts
67+
import { equalsResponse } from "https://deno.land/x/response_utils@$VERSION/equal.ts";
68+
import { assert, assertThrows } from "https://deno.land/std/testing/asserts.ts";
69+
70+
const response = new Response("");
71+
await response.text();
72+
73+
assert(response.bodyUsed);
74+
assertThrows(() => equalsResponse(response, response, true));
75+
```
76+
77+
## isResponse
78+
79+
Whether the input is `Response` or not.
80+
81+
```ts
82+
import { isResponse } from "https://deno.land/x/response_utils@$VERSION/is.ts";
83+
import { assert, assertFalse } from "https://deno.land/std/testing/asserts.ts";
84+
85+
assert(isResponse(new Response()));
86+
assertFalse(isResponse({}));
87+
assertFalse(isResponse(null));
88+
```
89+
90+
## License
91+
92+
Copyright © 2023-present [httpland](https://github.com/httpland).
93+
94+
Released under the [MIT](./LICENSE) license

0 commit comments

Comments
 (0)