endsWith

源码

https://github.com/ddzy/ts-utility-plugins/tree/master/src/ddzy/utility/string/endsWith

说明

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

用法

endsWith.ts
endsWith.test.ts
import { endsWith } from "./ddzy/utility/string/endsWith";
// ?
const s1 = {
text: 'duanzhaoyang',
target: 'a',
};
const p1 = endsWith(s1.text, s1.target, 3);
console.log(p1);
console.log('----------------------');
const s2 = {
text: 'duanzhaoyang',
target: 'ao',
};
const p2 = endsWith(s2.text, s2.target);
console.log(p2);
console.log('-----------------------');
const s3 = {
text: 'ddzy',
target: 'y',
};
const p3 = endsWith(s3.text, s3.target);
console.log(p3);
const s4 = {
text: 'duan',
target: 'd',
position: 4,
};
const p4 = endsWith(s4.text, s4.target, s4.position);
console.log(p4);
import { endsWith } from "../../utility/string/endsWith";
describe('endsWith tests...', () => {
test('endsWith should return the correct value', () => {
interface IReceivedParams {
text: string;
target: string;
position: number | undefined;
};
const received: IReceivedParams[] = [
{
text: 'duanzhaoyang',
target: 'a',
position: 3,
},
{
text: 'duanzhaoyang',
target: 'ao',
position: undefined,
},
{
text: 'ddzy',
target: 'y',
position: undefined,
},
{
text: 'duan',
target: 'd',
position: 4,
},
];
const expected = [true, false, true, true];
received.forEach((v, i) => {
const result = endsWith(v.text, v.target, v.position);
expect(result).toBe(expected[i]);
});
});
});