UNPKG

@sasjs/lint

Version:

Linting and formatting for SAS code

22 lines 1.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.splitText = void 0; const LineEndings_1 = require("../types/LineEndings"); /** * Splits the given content into a list of lines, regardless of CRLF or LF line endings. * @param {string} text - the text content to be split into lines. * @returns {string[]} an array of lines from the given text */ const splitText = (text, config) => { if (!text) return []; const expectedLineEndings = config.lineEndings === LineEndings_1.LineEndings.LF ? '\n' : '\r\n'; const incorrectLineEndings = expectedLineEndings === '\n' ? '\r\n' : '\n'; text = text.replace(new RegExp(incorrectLineEndings, 'g'), expectedLineEndings); // splitting text on '\r\n' was causing some problem // as it was retaining carriage return at the end of each line // so, removed the carriage returns from text and splitted on line feed (lf) return text.replace(/\r/g, '').split(/\n/); }; exports.splitText = splitText; //# sourceMappingURL=splitText.js.map