trim

说明

去除字符串首尾的指定字符, 默认为空格(whitespace)

源码

用法

trim.test.ts
1
import { trim } from "../../utility/string/trim";
2
3
describe('trim() tests', () => {
4
test('trim should return a new processed string by using the default replacer when receive an empty string', () => {
5
const received = '';
6
const expected = '';
7
8
const result = trim(received);
9
10
expect(result).toBe(expected);
11
});
12
13
test('trim should return a new processed string that throw away the whitespace by using the default replacer', () => {
14
const received = ' ddzy ';
15
const expected = 'ddzy';
16
17
const result = trim(received);
18
19
expect(result).toBe(expected);
20
});
21
22
test('trim should return a new processed string by using a special replacer', () => {
23
const received = [
24
'wow, i like program!',
25
'oh... i love you oh',
26
];
27
const expected = [
28
', i like program!',
29
'... i love you ',
30
];
31
32
const replacer = ['wow', 'oh'];
33
34
const result = received.map((v, i) => {
35
return trim(v, replacer[i]);
36
});
37
38
result.forEach((v, i) => {
39
expect(v).toBe(expected[i]);
40
});
41
});
42
});
Copied!
最近更新 1yr ago
复制链接