Usuń ostatni ciąg z pliku w TypeScript

if(x.lastIndexOf("\n")>0) {
    return x.substring(0, x.lastIndexOf("\n"));
} else {
    return x;
}
Creepy Gábor