simplify TypeError throwing for startsWith & endsWith