清除字符串中的空格、HTML 标签和换行符。
| 参数 |
说明 |
类型 |
string |
清理后的字符串 |
string |
| 参数 |
说明 |
类型 |
默认值 |
str |
要清理的字符串 |
string |
'' |
import { clearBr } from 'ranuts';
const text = ' <p>Hello\nWorld</p> ';
const cleaned = clearBr(text);
console.log(cleaned); // 'HelloWorld'
import { clearBr } from 'ranuts';
const html = '<div>这是<strong>测试</strong>内容</div>\n换行';
const cleaned = clearBr(html);
console.log(cleaned); // '这是测试内容换行'
import { clearBr } from 'ranuts';
console.log(clearBr('')); // '' (空字符串)
console.log(clearBr()); // '' (空字符串)
- 清理内容:会移除所有空格、HTML 标签和换行符(
\r\n)。
- 空字符串处理:如果输入为空字符串,直接返回空字符串。
- 用途:常用于提取纯文本内容,去除格式标记。