Remove leading/trailing spaces, URL encoding, and quotes from a string.
| Argument |
Description |
Type |
string |
Cleaned string |
string |
| Parameter |
Description |
Type |
Default |
str |
String to clean |
string |
Required |
options |
Configuration options |
ClearStrOption |
{} |
| Parameter |
Description |
Type |
Default |
urlencoded |
Whether to perform URL decode |
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' (auto decoded)
import { clearStr } from 'ranuts';
const str = ' "hello%20world" ';
const cleaned = clearStr(str, { urlencoded: false });
console.log(cleaned); // 'hello%20world' (not decoded)
import { clearStr } from 'ranuts';
const str1 = "'test'";
const str2 = '"test"';
console.log(clearStr(str1)); // 'test'
console.log(clearStr(str2)); // 'test'
- Cleaning content: Removes leading/trailing spaces, single quotes, and double quotes.
- URL decoding: Performs URL decoding by default, can be disabled with
urlencoded: false.
- Use case: Commonly used to clean user input or values extracted from URL parameters.