Skip to content

Commit

Permalink
Use a unique global name and export all three characters
Browse files Browse the repository at this point in the history
  • Loading branch information
jalal246 committed Mar 11, 2020
1 parent c9a53b6 commit eda7837
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/textics.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,28 @@
// return str && typeof str === "string" && str.length > 0;
// }

/**
* \r = CR (Carriage Return) → Used as a new line character in Mac OS before X
* \n = LF (Line Feed) → Used as a new line character in Unix/Mac OS X
* \r\n = CR + LF → Used as a new line character in Windows
*/
const CR = /\r/g;
const CRLF = /\r\n/g;
const LF = /\n/g;

/**
* Extracts new line used char in a given string.
*
* @param {string} str
* @returns {string}
*/
function getNewLineChar(str) {
const NL_R = /\r/g;
const NL_RN = /\r\n/g;
const NL_N = /\n/g;

let lineChar = NL_N;
let lineChar = LF;

if (NL_R.test(str)) {
lineChar = NL_R;
} else if (NL_RN.test(str)) {
lineChar = NL_RN;
if (CR.test(str)) {
lineChar = CR;
} else if (CRLF.test(str)) {
lineChar = CRLF;
}

return lineChar;
Expand Down Expand Up @@ -118,4 +123,4 @@ function textics(str) {
};
}

module.exports = { textics, getNewLineChar };
module.exports = { textics, getNewLineChar, CR, CRLF, LF };

0 comments on commit eda7837

Please sign in to comment.