Skip to content

Commit eda7837

Browse files
committed
Use a unique global name and export all three characters
1 parent c9a53b6 commit eda7837

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/textics.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,28 @@
88
// return str && typeof str === "string" && str.length > 0;
99
// }
1010

11+
/**
12+
* \r = CR (Carriage Return) → Used as a new line character in Mac OS before X
13+
* \n = LF (Line Feed) → Used as a new line character in Unix/Mac OS X
14+
* \r\n = CR + LF → Used as a new line character in Windows
15+
*/
16+
const CR = /\r/g;
17+
const CRLF = /\r\n/g;
18+
const LF = /\n/g;
19+
1120
/**
1221
* Extracts new line used char in a given string.
1322
*
1423
* @param {string} str
1524
* @returns {string}
1625
*/
1726
function getNewLineChar(str) {
18-
const NL_R = /\r/g;
19-
const NL_RN = /\r\n/g;
20-
const NL_N = /\n/g;
21-
22-
let lineChar = NL_N;
27+
let lineChar = LF;
2328

24-
if (NL_R.test(str)) {
25-
lineChar = NL_R;
26-
} else if (NL_RN.test(str)) {
27-
lineChar = NL_RN;
29+
if (CR.test(str)) {
30+
lineChar = CR;
31+
} else if (CRLF.test(str)) {
32+
lineChar = CRLF;
2833
}
2934

3035
return lineChar;
@@ -118,4 +123,4 @@ function textics(str) {
118123
};
119124
}
120125

121-
module.exports = { textics, getNewLineChar };
126+
module.exports = { textics, getNewLineChar, CR, CRLF, LF };

0 commit comments

Comments
 (0)