JavaScript

URLSearchParams ๊ฐœ๋…๊ณผ ์ฟผ๋ฆฌ ์‚ฌ์šฉ๋ฒ•

martinooo 2024. 8. 28. 16:57

JS

 

 

 

๐Ÿคท‍โ™‚๏ธ ๋ณธ๋ก ์— ์•ž์„œ


๋ณธ๋ก ์— ์•ž์„œ ๋ฆฌ์•กํŠธ(react) ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ ์ค‘์— ์ฟผ๋ฆฌ ์ŠคํŠธ๋ง ๋‹ค๋ฃจ๊ธฐ ์œ„ํ•ด์„œ URLSearchParams API๋ฅผ ํ™œ์šฉํ•ด ์ฟผ๋ฆฌ ์ŠคํŠธ๋ง์„ ๋‹ค๋ฃจ๋ฉด์„œ ๊ฒช์€ ์ €์˜ ๊ฒฝํ—˜์„ ๊ณต์œ ํ•ด ๋“œ๋ฆฝ๋‹ˆ๋‹ค. 

 

 

๐Ÿคท‍โ™‚๏ธ URLSearchParams ๊ฐœ๋…


URLSearchParams๋Š” JavaScript ์›น API์ค‘ ํ•˜๋‚˜๋กœ URL ์ฃผ์†Œ์—์„œ ๊ฐ€์žฅ ๋‹ค๋ฃจ๊ธฐ ๊นŒ๋‹ค๋กœ์šด ์ฟผ๋ฆฌ ์ŠคํŠธ๋ง์„ ์‰ฝ๊ฒŒ ๋‹ค๋ฃฐ์ˆ˜ ์žˆ๋„๋ก ๋•๋Š” ๊ฐ์ฒด์ž…๋‹ˆ๋‹ค.

 

URLSearchParams MDN

https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams

 

URLSearchParams - Web APIs | MDN

The URLSearchParams interface defines utility methods to work with the query string of a URL.

developer.mozilla.org

 

๐Ÿคท‍โ™‚๏ธ ์ฟผ๋ฆฌ ์ŠคํŠธ๋ง์ด๋ž€?


 

 

URL ์ฃผ์†Œ๋ฅผ ๋ณด๋ฉด ๋„๋ฉ”์ธ ๋’ค์— ? ์‹œ์ž‘ํ•˜๋Š” ๊ธฐํ˜ธ๋ฅผ ํ”ํžˆ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

? ๊ธฐํ˜ธ ๋’ค์— ๋ถ™๋Š” ๊ฐ’๋“ค์„ ์ฟผ๋ฆฌ ์ŠคํŠธ๋ง(Query String) ๋ผ๊ณ  ๋ถ€๋ฅด๋ฉฐ key-value ํ˜•ํƒœ๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค.

 

์ฟผ๋ฆฌ ์ŠคํŠธ๋ง์€ ํ•„ํ„ฐ๋ง, ํŽ˜์ด์ง€๋„ค์ด์…˜, ์ •๋ ฌ, ๋‚ ์งœ ๋“ฑ ๋‹ค์–‘ํ•œ ์šฉ๋„๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

์ € ๊ฐ™์€ ๊ฒฝ์šฐ๋Š” ํ•„ํ„ฐ๋ง, ์ •๋ ฌ, ๋‚ ์งœ์— ๋Œ€ํ•œ ๊ฐ’๋“ค์€ ์ฟผ๋ฆฌ์ŠคํŠธ๋ง์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

 

์˜ˆ๋ฅผ ๋“ค์–ด

https://example.com/?name=John&age=30

 

? ๊ธฐํ˜ธ ๋’ค์— name=john๋Š” key-value ํ˜•ํƒœ์ด๊ณ  & ๊ธฐํ˜ธ๋กœ ๊ตฌ๋ถ„ํ•˜์—ฌ ์ƒˆ๋กœ์šด key-value ํ˜•ํƒœ์— ์ฟผ๋ฆฌ์ŠคํŠธ๋ง์„ ๋ช…์‹œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

์ด ๋ถ€๋ถ„์ด ์ฟผ๋ฆฌ ์ŠคํŠธ๋ง์ž…๋‹ˆ๋‹ค.

?name=John&age=30

 

 

๐Ÿคท‍โ™‚๏ธ URLSearchParams ์‚ฌ์šฉ๋ฐฉ๋ฒ•


URLSearchParams ๊ธฐ๋ณธ ์‚ฌ์šฉ๋ฒ•

const searchParams = new URLSearchParams(location.search);

or

const params = new URLSearchParams(window.location.search);

 

์ด ์ฝ”๋“œ๋Š” URLSearchParams ๊ฐ์ฒด๋ฅผ ํ•œ ๋ฒˆ์— ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

๊ทธ๋ž˜์„œ ์—ฌ๋Ÿฌ ์ฟผ๋ฆฌ ํŒŒ๋ผ๋ฏธํ„ฐ ๊ฐ’์„ ๊ฐ€์ ธ์˜ฌ ๋•Œ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

 

URLSearchParams get ์‚ฌ์šฉ์˜ˆ์‹œ

https://example.com/?name=John&age=30

const searchParams = new URLSearchParams(location.search);
const name = searchParams.get('name');

//๊ฒฐ๊ณผ๊ฐ’์€ name์— value ๊ฐ’์ธ John ์ž…๋‹ˆ๋‹ค.

 

์—ฌ๋Ÿฌ ๊ฐœ ์ฟผ๋ฆฌ ์ŠคํŠธ๋ง์— ๊ฐ’๋“ค์„ ์‚ฌ์šฉํ•  ๋•Œ ์„ฑ๋Šฅ์ด๋‚˜ ์ฝ”๋“œ ๊ฐ€๋…์„ฑ ๋ฉด์—์„œ ์ข‹์Šต๋‹ˆ๋‹ค.

 

URLSearchParams set ์‚ฌ์šฉ์˜ˆ์‹œ

const searchParams = new URLSearchParams('name=John&age=30');
searchParams.set("name", "yoo");
searchParams.set("age", 1);

๊ฒฐ๊ณผ๊ฐ’: ?name=yoo&age=1

 

set ๋ฉ”์„œ๋“œ๋Š” ์ด๋ฏธ ์กด์žฌํ•˜๋Š” ํŒŒ๋ผ๋ฏธํ„ฐ ๊ฐ’์„ ์˜ค๋ฒ„๋ผ์ด๋“œ ํ•ฉ๋‹ˆ๋‹ค.

 

URLSearchParams append ์‚ฌ์šฉ์˜ˆ์‹œ

const searchParams = new URLSearchParams('name=John&age=30');
searchParams.append("name", "yoo");

๊ฒฐ๊ณผ๊ฐ’: name=John&age=30&name=yoo

 

append ๋ฉ”์„œ๋“œ๋Š” ๊ธฐ๋ณธ ํŒŒ๋ผ๋ฏธํ„ฐ ๊ฐ’์ด ์žˆ์–ด๋„ ์ƒˆ๋กœ์šด ๊ฐ’์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

 

URLSearchParams delete ์‚ฌ์šฉ์˜ˆ์‹œ

const searchParams = new URLSearchParams('name=John&age=30');
searchParams.delete("name");

๊ฒฐ๊ณผ๊ฐ’: ?age=30

 

delete ๋ฉ”์„œ๋“œ๋Š” ํŠน์ • ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค.

 

๐Ÿคท‍โ™‚๏ธ URLSearchParams ๋งˆ์ง€๋ง‰์œผ๋กœ


URLSearchParams ์‚ฌ์šฉ๋ฒ•์— ๋Œ€ํ•ด์„œ ์ •๋ฆฌ๋ฅผ ํ•ด๋ดค์Šต๋‹ˆ๋‹ค.

 

๋” ๋‹ค์–‘ํ•œ URLSearchParams ๊ฐ์ฒด์— ๋ฉ”์„œ๋“œ๋“ค์ด ์กด์žฌํ•˜์ง€๋งŒ ์ €๋Š” ์œ„์— 4๊ฐœ ๋ฉ”์„œ๋“œ๋ฅผ ๊ฐœ๋…์„ ์ดํ•ดํ•˜๊ณ  ์‚ฌ์šฉ์„ ํ•˜์…”๋„ ์‹ค๋ฌด์—์„œ ๋ฌธ์ œ์—†์ด ์‚ฌ์šฉํ•˜์‹ค ์ˆ˜ ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ•ด์„œ URLSearchParams ๊ฐ์ฒด์— get, set, append, delete ๋ฉ”์„œ๋“œ๋ฅผ ์ •๋ฆฌํ•ด ๋ดค์Šต๋‹ˆ๋‹ค.

 

 


 

์žฌ๋ฐŒ๋Š” ์˜ค๋Š˜์˜ ๋ ๋ณ„ ์šด์„ธ ๋ณด๊ณ  ๊ฐ€์„ธ์š”! 

 

 

https://cometruedream.tistory.com/247

 

[React] Tailwind ํ•œ์ค„, ๋‘์ค„, ์„ธ์ค„ ํšจ๊ณผ className ์ปค์Šคํ…€

๐Ÿคท‍โ™‚๏ธ Tailwind ํ•œ์ค„, ๋‘์ค„, ์„ธ์ค„ ํšจ๊ณผํ”„๋กœ์ ํŠธ ์ง„ํ–‰์ค‘ ๋ฐฐ๋„ˆ ๋งํฌ์— URL ๊ธธ์ด๊ฐ€ ๋„ˆ๋ฌด ๊ธธ์–ด์„œ 3์ค„ ํšจ๊ณผ ์ฒ˜๋ฆฌ๋ฅผ ํ•ด์•ผ ํ–ˆ์Šต๋‹ˆ๋‹ค. React + Tailwind CSS ์…‹ํŒ…๋œ ํ”„๋กœ์ ํŠธ ์—ฌ์„œ CSS ํŒŒ์ผ & style ํƒœ๊ทธ๋ฅผ ์‚ฌ์šฉํ•˜

cometruedream.tistory.com

 

 

https://cometruedream.tistory.com/243

 

NestJS Lifecycle (์ƒ๋ช…์ฃผ๊ธฐ) ๊ฐœ๋…

๐Ÿคท‍โ™‚๏ธ ๋ณธ๋ก ์— ์•ž์„œ Nest JS ๊ฐœ๋…?Nest JS๋Š” Node JS ๊ธฐ๋ฐ˜์œผ๋กœ ํ•œ ์„œ๋ฒ„ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ํ”„๋ ˆ์ž„์›Œํฌ ์ž…๋‹ˆ๋‹ค. ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋Š” ์ƒ๋‹นํžˆ ์˜ค๋žซ๋™์•ˆ Express ๊ธฐ๋ฐ˜์œผ๋กœ ์„œ๋ฒ„ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ฐœ๋ฐœ์—์„œ ์••๋„์ ์ธ ์ 

cometruedream.tistory.com

 

 

https://cometruedream.tistory.com/242

 

๋ฆฌ์•กํŠธ Vite Proxy ํ™œ์šฉํ•œ CORS ์˜ค๋ฅ˜ ํ•ด๊ฒฐ

๐Ÿคท‍โ™‚๏ธ ๋ณธ๋ก ์— ์•ž์„œํ”„๋ก ํŠธ์—”๋“œ ๋ฒˆ๋“ค๋Ÿฌ ๊ฐœ๋…๊ณผ webpack vs vite ๋น„๊ต์— ๋Œ€ํ•ด์„œ ๊ณต๋ถ€๋ฅผ ํ•˜๊ณ  ๊ธ€์„ ๋ณด์‹œ๋ฉด ๋” ๋งŽ์€ ๋„์›€์ด ๋ฉ๋‹ˆ๋‹ค^^ํ”„๋ก ํŠธ์—”๋“œ ๊ฐœ๋ฐœ์„ ์œ„ํ•œ ๋ฒˆ๋“ค๋Ÿฌ ๊ฐœ๋…๊ณผ webpack vs vite ๋น„๊ตhttps://comet

cometruedream.tistory.com

 

 

https://cometruedream.tistory.com/241

 

React ํด๋”๊ตฌ์กฐ FSD ๊ธฐ๋Šฅ ๋ถ„ํ™œ ์„ค๊ณ„ ์•„ํ‚คํ…์ฒ˜

๐Ÿคท‍โ™‚๏ธ ๋ณธ๋ก ์— ์•ž์„œํ”„๋กœ์ ํŠธ๋ฅผ ์‹œ์ž‘ํ•˜๊ธฐ์— ์•ž์„œ ํด๋” ๊ตฌ์กฐ, ์„ค๊ณ„์— ๋Œ€ํ•œ ์•„ํ‚คํ…์ฒ˜๋ฅผ ๋งŒ๋“œ๋Š” ๊ฒƒ์€ ์ƒ๋‹นํžˆ ์–ด๋ ต๋‹ค. ์ด๋ฒˆ ํ”„๋กœ์ ํŠธ์— React FSD ํด๋”๊ตฌ์กฐ ์•„ํ‚คํ…์ฒ˜๋ฅผ ์„ค๊ณ„ํ•  ์˜ˆ์ •์ด๋ผ์„œ FSD ์•„ํ‚คํ…

cometruedream.tistory.com

 

 

https://cometruedream.tistory.com/244

 

์‰ฝ๊ฒŒ ์ดํ•ดํ•˜๊ณ  ์‚ฌ์šฉํ• ์ˆ˜ ์žˆ๋Š” Prisma ๋ช…๋ น์–ด ์ •๋ฆฌ

๐Ÿคท‍โ™‚๏ธ Prisma ๋ช…๋ น์–ด ๋ณธ๋ก ์— ์•ž์„œ Prisma๋ž€?Nest JS ํ”„๋ ˆ์ž„์›Œํฌ์™€ Prisma ORM์„ ํ™œ์šฉํ•ด์„œ ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๋ฉด์„œ Prisma๋Š” Node JS ๊ธฐ๋ฐ˜์— ํ”„๋ ˆ์ž„์›Œํฌ/๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์™€ ์ƒํ˜ธ์ž‘์šฉ์ด ์ž˜๋˜๋ฉฐ Prisma + DB ์—ฐ๋™์œผ

cometruedream.tistory.com

 

 

https://fnfentermagazine.com/%ec%9e%90%eb%b0%94%ec%8a%a4%ed%81%ac%eb%a6%bd%ed%8a%b8-%ec%88%ab%ec%9e%90-%ec%9e%90%eb%a3%8c%ea%b5%ac%ec%a1%b0%ec%9d%98-%ea%b0%9c%eb%85%90%ea%b3%bc-%eb%82%b4%ec%9e%a5%ed%95%a8%ec%88%98/

 

[์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ 2ํƒ„] ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์ˆซ์ž ์ž๋ฃŒ๊ตฌ์กฐ์˜ ๊ฐœ๋…๊ณผ ๋‚ด์žฅํ•จ์ˆ˜

์„ธ์ƒ์„ ํ–ฅํ•ด ๋‹ฌ๋ ค - ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ(javascript) ์ˆซ์žํ˜• ๋ฐ์ดํ„ฐ ์ž๋ฃŒ๊ตฌ์กฐ๋Š” ๋ชจ๋“  ์ข…๋ฅ˜์˜ ์ˆ˜ํ•™์  ์—ฐ์‚ฐ์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” ์ค‘์š”ํ•œ ๋ฐ์ดํ„ฐ ํƒ€์ž…์ž…๋‹ˆ๋‹ค. [์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ 2ํƒ„] ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์ˆซ์ž ์ž๋ฃŒ๊ตฌ์กฐ์˜

fnfentermagazine.com