UNPKG

@expressjs/codemod

Version:

Codemods for updating express servers.

19 lines (18 loc) 723 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getOptions = getOptions; /** * By default, jscodeshift(recast) uses the line terminator of the OS the code runs on. * This is often not desired, so we instead try to detect it from the input. * If there is at least one Windows-style linebreak (CRLF) in the input and * no Unix-style linebreak (LF), use that. In all other cases, use Unix-style (LF). * @return '\n' or '\r\n' */ function getOptions(code) { return { lineTerminator: detectLineTerminator(code) }; } function detectLineTerminator(code) { const hasCRLF = /\r\n/.test(code); const hasLF = /[^\r]\n/.test(code); return hasCRLF && !hasLF ? '\r\n' : '\n'; }