Skip to content

Instantly share code, notes, and snippets.

@77Z
Created June 26, 2020 07:57
Show Gist options
  • Save 77Z/698e3dc2a3d27c4cd1e3178af3cebf22 to your computer and use it in GitHub Desktop.
Save 77Z/698e3dc2a3d27c4cd1e3178af3cebf22 to your computer and use it in GitHub Desktop.
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