endsWith

说明

检查字符串text是否以给定的target字符串结尾

源码

用法

endsWith.test.ts
1
import { endsWith } from "../../utility/string/endsWith";
2
3
describe('endsWith tests...', () => {
4
5
test('endsWith should return the correct value', () => {
6
interface IReceivedParams {
7
text: string;
8
target: string;
9
position: number | undefined;
10
};
11
12
const received: IReceivedParams[] = [
13
{
14
text: 'duanzhaoyang',
15
target: 'a',
16
position: 3,
17
},
18
{
19
text: 'duanzhaoyang',
20
target: 'ao',
21
position: undefined,
22
},
23
{
24
text: 'ddzy',
25
target: 'y',
26
position: undefined,
27
},
28
{
29
text: 'duan',
30
target: 'd',
31
position: 4,
32
},
33
];
34
const expected = [true, false, true, true];
35
36
received.forEach((v, i) => {
37
const result = endsWith(v.text, v.target, v.position);
38
39
expect(result).toBe(expected[i]);
40
});
41
});
42
43
});
Copied!
最近更新 1yr ago
复制链接