Created
June 26, 2020 07:57
-
-
Save 77Z/698e3dc2a3d27c4cd1e3178af3cebf22 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getLineBreakChar(string) { | |
const indexOfLF = string.indexOf('\n', 1); // No need to check first-character | |
if (indexOfLF === -1) { | |
if (string.indexOf('\r') !== -1) return '\r'; | |
return '\n'; | |
} | |
if (string[indexOfLF - 1] === '\r') return '\r\n'; | |
return '\n'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment