bit-bin
Version:
<a href="https://opensource.org/licenses/Apache-2.0"><img alt="apache" src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"></a> <a href="https://github.com/teambit/bit/blob/master/CONTRIBUTING.md"><img alt="prs" src="https://img.shields.io/b
67 lines (51 loc) • 1.49 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.lf = lf;
exports.auto = auto;
exports.cr = cr;
exports.crlf = crlf;
function _isbinaryfile() {
const data = require("isbinaryfile");
_isbinaryfile = function () {
return data;
};
return data;
}
function _replaceBufferNonRecursive() {
const data = _interopRequireDefault(require("./buffer/replace-buffer-non-recursive"));
_replaceBufferNonRecursive = function () {
return data;
};
return data;
}
const isWindows = typeof process !== 'undefined' && process.platform === 'win32';
const lineBreak = isWindows ? '\r\n' : '\n';
const newLines = ['\r\n', '\r', '\n'];
const newline = /\r\n|\r|\n/g;
function converts(text, to) {
if (Buffer.isBuffer(text)) {
if ((0, _isbinaryfile().isBinaryFileSync)(text)) return text; // don't touch binary files
newLines.forEach(newLine => {
// $FlowFixMe text is Buffer here
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
if (newLine !== to) text = (0, _replaceBufferNonRecursive().default)(text, newLine, to);
});
return text;
}
return text.toString().replace(newline, to);
}
function lf(text) {
return converts(text, '\n');
}
function auto(text) {
return converts(text, lineBreak);
}
function cr(text) {
return converts(text, '\r');
}
function crlf(text) {
return converts(text, '\r\n');
}
;