فاصلههای دو سر، کدگذاری نشانی و گیومهها را از یک رشته برمیدارد.
| آرگومان |
توضیح |
نوع |
string |
رشتهٔ پاکشده |
string |
| پارامتر |
توضیح |
نوع |
پیشفرض |
str |
رشتهای که پاک میشود |
string |
الزامی |
options |
گزینههای پیکربندی |
ClearStrOption |
{} |
| پارامتر |
توضیح |
نوع |
پیشفرض |
urlencoded |
اینکه رمزگشایی نشانی انجام شود یا نه |
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'
- چه چیزی برداشته میشود: فاصلههای دو سر و گیومههای تکی و دوتایی.
- رمزگشایی نشانی: بهطور پیشفرض انجام میشود و با
urlencoded: false میتوان خاموشش کرد.
- کاربرد: معمولاً برای پاک کردن ورودی کاربر یا مقدارهایی که از پارامترهای نشانی بیرون کشیده شدهاند به کار میرود.