setup-kubectl/node_modules/detect-newline/index.js
github-actions[bot] 7f7e5ba5ea
Add node modules and compiled JavaScript from main (#57)
Co-authored-by: Oliver King <oking3@uncc.edu>
2022-06-21 12:18:30 -04:00

21 lines
505 B
JavaScript

'use strict';
const detectNewline = string => {
if (typeof string !== 'string') {
throw new TypeError('Expected a string');
}
const newlines = string.match(/(?:\r?\n)/g) || [];
if (newlines.length === 0) {
return;
}
const crlf = newlines.filter(newline => newline === '\r\n').length;
const lf = newlines.length - crlf;
return crlf > lf ? '\r\n' : '\n';
};
module.exports = detectNewline;
module.exports.graceful = string => (typeof string === 'string' && detectNewline(string)) || '\n';