1'use strict'; 2module.exports = function (str) { 3 if (typeof str !== 'string') { 4 throw new TypeError('Expected a string'); 5 } 6 7 var newlines = (str.match(/(?:\r?\n)/g) || []); 8 9 if (newlines.length === 0) { 10 return null; 11 } 12 13 var crlf = newlines.filter(function (el) { 14 return el === '\r\n'; 15 }).length; 16 17 var lf = newlines.length - crlf; 18 19 return crlf > lf ? '\r\n' : '\n'; 20}; 21 22module.exports.graceful = function (str) { 23 return module.exports(str) || '\n'; 24}; 25