Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
"@vitest/coverage-v8": "^3.2.4",
"typescript": "~5.8.3",
"vite": "^7.1.2",
"vitest": "^3.2.4"
"vitest": "^3.2.4",
"jsdom": "^26.1.0"
},
"files": [
"dist"
Expand Down
1 change: 1 addition & 0 deletions package/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * as cookieUtil from "./cookieUtil";
export * as numberUtil from "./numberUtil";
export * as validationUtil from "./validationUtil";
export * as commonUtil from "./commonUtil";
export * as searchQueryUtil from "./searchQueryUtil";
26 changes: 26 additions & 0 deletions package/searchQueryUtil/getAllQuery/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { describe, expect, test, vi, afterEach } from "vitest";
import getAllQuery from ".";

describe("getAll 유틸 함수 테스트", () => {
afterEach(() => {
vi.unstubAllGlobals();
});

test("여러 개의 동일한 키가 있는 쿼리 스트링을 올바르게 처리해야 함", () => {
vi.stubGlobal("location", {
search: "?key=value1&key=value2&key=value3",
});

const result = getAllQuery();
expect(result).toEqual({ key: ["value1", "value2", "value3"] });
});

test("여러 키-값 쌍이 있는 쿼리 스트링을 올바르게 처리해야 함", () => {
vi.stubGlobal("location", {
search: "?name=John&age=30&city=NewYork",
});

const result = getAllQuery();
expect(result).toEqual({ name: "John", age: "30", city: "NewYork" });
});
});
22 changes: 22 additions & 0 deletions package/searchQueryUtil/getAllQuery/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export default function getAllQuery(): Record<string, string | string[]> {
if (window && typeof window.URLSearchParams === "undefined") {
throw new Error("URLSearchParams is not supported in this environment.");
}

const params = new URLSearchParams(window.location.search);
const result: { [key: string]: string | string[] } = {};

for (const [key, value] of params.entries()) {
if (result[key]) {
if (Array.isArray(result[key])) {
result[key].push(value);
} else {
result[key] = [result[key], value];
}
} else {
result[key] = value;
}
}

return result;
}
1 change: 1 addition & 0 deletions package/searchQueryUtil/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as getAllQuery } from "./getAllQuery";
Loading