Skip to content

Commit 7edc4ab

Browse files
committed
Updates in merge headers function
1 parent b58ef1a commit 7edc4ab

6 files changed

Lines changed: 110 additions & 7 deletions

File tree

package/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@
3939
"import": "./dist/response/json/struct.mjs",
4040
"require": "./dist/response/json/struct.js"
4141
},
42-
"./response/headers/merge": {
43-
"types": "./dist/response/headers/merge.d.ts",
44-
"import": "./dist/response/headers/merge.mjs",
45-
"require": "./dist/response/headers/merge.js"
42+
"./functions/merge-headers": {
43+
"types": "./dist/functions/merge-headers.d.ts",
44+
"import": "./dist/functions/merge-headers.mjs",
45+
"require": "./dist/functions/merge-headers.js"
4646
},
4747
"./package.json": "./package.json"
4848
},

package/src/response/common/struct.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { HeaderTuple } from "#/@types/response";
22

3-
import { mergeHeaders } from "#/response/headers/merge";
3+
import { mergeHeaders } from "#/functions/merge-headers";
44

55
/** Options of `createResponseStruct` function. */
66
type CreateResponseStructOptions<B extends BodyInit = BodyInit> = {

package/src/response/json/struct.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66
JsonResponseError,
77
} from "#/@types/response";
88

9-
import { mergeHeaders } from "#/response/headers/merge";
9+
import { mergeHeaders } from "#/functions/merge-headers";
1010

1111
type CreateJsonSuccessResponseStructOptions<D = unknown> = {
1212
/**

package/tsdown.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const options: Options = {
99
// internal
1010
"response/common/struct": "./src/response/common/struct.ts",
1111
"response/json/struct": "./src/response/json/struct.ts",
12-
"response/headers/merge": "./src/response/headers/merge.ts",
12+
"functions/merge-headers": "./src/functions/merge-headers.ts",
1313
},
1414
dts: false,
1515
outDir: "./dist",

test/src/header.test.ts

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import type { HeaderTuple } from "@jderjs/core";
2+
3+
import { mergeHeaders } from "@jderjs/core/functions/merge-headers";
4+
import { describe, expect, it } from "vitest";
5+
6+
describe("mergeHeaders test", (): void => {
7+
it("should work", async (): Promise<void> => {
8+
const headers: HeaderTuple[] = [
9+
[
10+
"Content-Type",
11+
"application/json",
12+
],
13+
[
14+
"X-Test",
15+
"test",
16+
],
17+
];
18+
19+
const result: HeaderTuple[] = mergeHeaders(headers);
20+
21+
expect(result).toStrictEqual([
22+
[
23+
"Content-Type",
24+
"application/json",
25+
],
26+
[
27+
"X-Test",
28+
"test",
29+
],
30+
]);
31+
});
32+
33+
it("should work with array", async (): Promise<void> => {
34+
const headers: HeaderTuple[] = [
35+
[
36+
"Content-Type",
37+
"application/json",
38+
],
39+
[
40+
"X-Test",
41+
"test",
42+
],
43+
];
44+
45+
const headers2: HeaderTuple[] = [
46+
[
47+
"X-Test-2",
48+
"test2",
49+
],
50+
];
51+
52+
const result: HeaderTuple[] = mergeHeaders(headers, headers2);
53+
54+
expect(result).toStrictEqual([
55+
[
56+
"Content-Type",
57+
"application/json",
58+
],
59+
[
60+
"X-Test",
61+
"test",
62+
],
63+
[
64+
"X-Test-2",
65+
"test2",
66+
],
67+
]);
68+
});
69+
70+
it("should work with array and object", async (): Promise<void> => {
71+
const headers: HeaderTuple[] = [
72+
[
73+
"Content-Type",
74+
"application/json",
75+
],
76+
[
77+
"X-Test",
78+
"test",
79+
],
80+
];
81+
82+
const headers2: Record<string, string> = {
83+
"X-Test-2": "test2",
84+
};
85+
86+
const result: HeaderTuple[] = mergeHeaders(headers, headers2);
87+
88+
expect(result).toStrictEqual([
89+
[
90+
"Content-Type",
91+
"application/json",
92+
],
93+
[
94+
"X-Test",
95+
"test",
96+
],
97+
[
98+
"X-Test-2",
99+
"test2",
100+
],
101+
]);
102+
});
103+
});

0 commit comments

Comments
 (0)