ends-with-string
Version:
Check if a string or buffer ends with a given string
13 lines (12 loc) • 432 B
JavaScript
import charToString from "char-to-string";
export default function endsWith(input, string) {
if (string.length > input.length) {
return false;
} else {
return Array.from(string).reduceRight((retval, match, index)=>{
const pointer = input.length - string.length + index;
const char = input[pointer];
return retval && charToString(char) === match;
}, true);
}
}