+1 - especially if you are dealing with files that have strings inside of them…
const str = "hello\nworld!"
That string would be counted as 2 lines if we’re going by newline alone. Now, this is clearly not impossible so I don’t want the to discourage the OP from trying. Almost every text editor has to over come this problem. Helix, for instance, knows what line number things are