문자열에서 앞뒤 공백, URL 인코딩, 따옴표를 걷어냅니다.
| 인자 |
설명 |
타입 |
string |
정리된 문자열 |
string |
| 매개변수 |
설명 |
타입 |
기본값 |
str |
정리할 문자열 |
string |
필수 |
options |
설정 옵션 |
ClearStrOption |
{} |
| 매개변수 |
설명 |
타입 |
기본값 |
urlencoded |
URL 디코딩을 할지 여부 |
boolean |
true |
import { clearStr } from 'ranuts';
const str = ' "hello world" ';
const cleaned = clearStr(str);
console.log(cleaned); // 'hello world'
import { clearStr } from 'ranuts';
const encoded = ' "hello%20world" ';
const cleaned = clearStr(encoded);
console.log(cleaned); // 'hello world' (알아서 디코딩됨)
import { clearStr } from 'ranuts';
const str = ' "hello%20world" ';
const cleaned = clearStr(str, { urlencoded: false });
console.log(cleaned); // 'hello%20world' (디코딩 안 됨)
import { clearStr } from 'ranuts';
const str1 = "'test'";
const str2 = '"test"';
console.log(clearStr(str1)); // 'test'
console.log(clearStr(str2)); // 'test'
- 걷어내는 것: 앞뒤 공백, 작은따옴표, 큰따옴표를 걷어냅니다.
- URL 디코딩: 기본으로 URL 디코딩을 하며,
urlencoded: false로 끌 수 있습니다.
- 활용: 사용자가 입력한 값이나 URL 매개변수에서 꺼낸 값을 정리할 때 흔히 쓰입니다.