Skip to content

Commit

Permalink
chore: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
TomokiMiyauci committed May 5, 2023
0 parents commit 8c2cd93
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store
Thumbs.db
npm/
coverage
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"denoland.vscode-deno"
]
}
23 changes: 23 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"editor.defaultFormatter": "denoland.vscode-deno",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": true
},
"deno.enable": true,
"deno.codeLens.referencesAllFunctions": true,
"deno.internalDebug": true,
"deno.lint": true,
"deno.suggest.completeFunctionCalls": true,
"deno.unstable": true,
"deno.codeLens.references": true,
"deno.suggest.autoImports": true,
"deno.suggest.names": true,
"deno.suggest.imports.autoDiscover": true,
"deno.suggest.paths": true,
"deno.codeLens.test": true,
"deno.codeLens.implementations": true,
"deno.codeLens.testArgs": [
"--allow-all"
]
}
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
MIT License

Copyright (c) 2023 httpland

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
94 changes: 94 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# response-utils

[![deno land](http://img.shields.io/badge/available%20on-deno.land/x-lightgrey.svg?logo=deno)](https://deno.land/x/response_utils)
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/httpland/response-utils)](https://github.com/httpland/response-utils/releases)
[![codecov](https://codecov.io/github/httpland/response-utils/branch/main/graph/badge.svg)](https://codecov.io/gh/httpland/response-utils)
[![GitHub](https://img.shields.io/github/license/httpland/response-utils)](https://github.com/httpland/response-utils/blob/main/LICENSE)

[![test](https://github.com/httpland/response-utils/actions/workflows/test.yaml/badge.svg)](https://github.com/httpland/response-utils/actions/workflows/test.yaml)
[![NPM](https://nodei.co/npm/@httpland/response-utils.png?mini=true)](https://nodei.co/npm/@httpland/response-utils/)

Response utility collection.

## createResponse

Create a new `Response`

If you create a new `Response` from an existing `Response`, any options you set
in an options argument for the new response replace any corresponding options
set in the original `Response`.

```ts
import { createResponse } from "https://deno.land/x/response_utils@$VERSION/create.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";

declare const init: Response;
const response = createResponse(init, { status: 201 });

assertEquals(response.status, 201);
```

## equalsResponse

Check two `Response` fields equality.

```ts
import { equalsResponse } from "https://deno.land/x/response_utils@$VERSION/equal.ts";
import { assert } from "https://deno.land/std/testing/asserts.ts";

assert(
equalsResponse(
new Response(null, { status: 204, headers: { "content-length": "0" } }),
new Response(null, { status: 204, headers: { "content-length": "0" } }),
),
);
```

If you also want to check the equivalence of the body, set the mode to strict.

```ts
import { equalsResponse } from "https://deno.land/x/response_utils@$VERSION/equal.ts";
import { assert } from "https://deno.land/std/testing/asserts.ts";

assert(
await equalsResponse(
new Response("test1", { status: 200, headers: { "content-length": "5" } }),
new Response("test2", { status: 200, headers: { "content-length": "5" } }),
true,
),
);
```

### Throwing error

In strict mode, if response body has already been read.

```ts
import { equalsResponse } from "https://deno.land/x/response_utils@$VERSION/equal.ts";
import { assert, assertThrows } from "https://deno.land/std/testing/asserts.ts";

const response = new Response("");
await response.text();

assert(response.bodyUsed);
assertThrows(() => equalsResponse(response, response, true));
```

## isResponse

Whether the input is `Response` or not.

```ts
import { isResponse } from "https://deno.land/x/response_utils@$VERSION/is.ts";
import { assert, assertFalse } from "https://deno.land/std/testing/asserts.ts";

assert(isResponse(new Response()));
assertFalse(isResponse({}));
assertFalse(isResponse(null));
```

## License

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

Released under the [MIT](./LICENSE) license

0 comments on commit 8c2cd93

Please sign in to comment.