Skip to content

Commit 95f8808

Browse files
committed
chore: initial commit
0 parents  commit 95f8808

File tree

6 files changed

+195
-0
lines changed

6 files changed

+195
-0
lines changed

.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: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# headers-utils
2+
3+
[![deno land](http://img.shields.io/badge/available%20on-deno.land/x-lightgrey.svg?logo=deno)](https://deno.land/x/headers_utils)
4+
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/httpland/headers-utils)](https://github.com/httpland/headers-utils/releases)
5+
[![codecov](https://codecov.io/github/httpland/headers-utils/branch/main/graph/badge.svg)](https://codecov.io/gh/httpland/headers-utils)
6+
[![GitHub](https://img.shields.io/github/license/httpland/headers-utils)](https://github.com/httpland/headers-utils/blob/main/LICENSE)
7+
8+
[![test](https://github.com/httpland/headers-utils/actions/workflows/test.yaml/badge.svg)](https://github.com/httpland/headers-utils/actions/workflows/test.yaml)
9+
[![NPM](https://nodei.co/npm/@httpland/headers-utils.png?mini=true)](https://nodei.co/npm/@httpland/headers-utils/)
10+
11+
Headers utility collection.
12+
13+
## equalHeaders
14+
15+
Check two `Headers` field name and field value equality.
16+
17+
```ts
18+
import { equalsHeaders } from "https://deno.land/x/headers_utils@$VERSION/equal.ts";
19+
import { assert, assertFalse } from "https://deno.land/std/testing/asserts.ts";
20+
21+
assert(equalsHeaders(new Headers({ a: "b" }), new Headers({ a: "b" })));
22+
assertFalse(equalsHeaders(new Headers({ a: "b" }), new Headers({ c: "d" })));
23+
```
24+
25+
## filterHeadersEntries
26+
27+
Returns a new `Headers` with all entries of the given headers except the ones
28+
that do not match the given predicate.
29+
30+
```ts
31+
import { filterHeadersEntries } from "https://deno.land/x/headers_utils@$VERSION/filter_entries.ts";
32+
import { assert, assertFalse } from "https://deno.land/std/testing/asserts.ts";
33+
34+
declare const isIMFDate: (input: string) => boolean;
35+
36+
const headers = filterHeadersEntries(
37+
new Headers({
38+
"date": "<date>",
39+
"content-type": "<content-type>",
40+
}),
41+
([key, value]) => isIMFDate(value),
42+
);
43+
44+
assert(headers.has("date"));
45+
assert(headers.has("content-type"));
46+
```
47+
48+
## filterHeadersKeys
49+
50+
Returns a new `Headers` with all entries of the given headers except the ones
51+
that have a key(header name or field name) that does not match the given
52+
predicate.
53+
54+
```ts
55+
import { filterHeadersKeys } from "https://deno.land/x/headers_utils@$VERSION/filter_keys.ts";
56+
import { assert, assertFalse } from "https://deno.land/std/testing/asserts.ts";
57+
58+
const headers = filterHeadersKeys(
59+
new Headers({
60+
"date": "<date>",
61+
"content-type": "<content-type>",
62+
}),
63+
(key) => key.startsWith("content"),
64+
);
65+
66+
assert(headers.has("content-type"));
67+
assertFalse(headers.has("date"));
68+
```
69+
70+
## filterHeadersValues
71+
72+
Returns a new `Headers` with all entries of the given headers except the ones
73+
that have a value(field value) that does not match the given predicate.
74+
75+
```ts
76+
import { filterHeadersValues } from "https://deno.land/x/headers_utils@$VERSION/filter_values.ts";
77+
import { assert, assertFalse } from "https://deno.land/std/testing/asserts.ts";
78+
79+
declare const isIMFDate: (input: string) => boolean;
80+
81+
const headers = filterHeadersValues(
82+
new Headers({
83+
"date": "<date>",
84+
"content-type": "<content-type>",
85+
}),
86+
isIMFDate,
87+
);
88+
89+
assert(headers.has("date"));
90+
assertFalse(headers.has("content-type"));
91+
```
92+
93+
## isHeaders
94+
95+
Whether the input is `Headers` or not.
96+
97+
```ts
98+
import { isHeaders } from "https://deno.land/x/headers_utils@$VERSION/is.ts";
99+
import { assert, assertFalse } from "https://deno.land/std/testing/asserts.ts";
100+
101+
assert(isHeaders(new Headers()));
102+
assertFalse(isHeaders({}));
103+
```
104+
105+
## stringifyHeaders
106+
107+
Serialize `Headers` into string.
108+
109+
```ts
110+
import { stringifyHeaders } from "https://deno.land/x/headers_utils@$VERSION/stringify.ts";
111+
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
112+
113+
assertEquals(stringifyHeaders(new Headers()), "");
114+
assertEquals(
115+
stringifyHeaders(
116+
new Headers({
117+
"content-type": "text/plain",
118+
"date": "Wed, 21 Oct 2015 07:28:00 GMT",
119+
}),
120+
),
121+
`content-type: text/plain
122+
date: Wed, 21 Oct 2015 07:28:00 GMT`,
123+
);
124+
```
125+
126+
## License
127+
128+
Copyright © 2023-present [httpland](https://github.com/httpland).
129+
130+
Released under the [MIT](./LICENSE) license

0 commit comments

Comments
 (0)