mirror of
https://github.com/sasjs/lint.git
synced 2025-12-10 17:34:36 +00:00
18 lines
709 B
TypeScript
18 lines
709 B
TypeScript
import { LintConfig } from '../types/LintConfig'
|
|
import { LineEndings } from '../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
|
|
*/
|
|
export const splitText = (text: string, config: LintConfig): string[] => {
|
|
if (!text) return []
|
|
const expectedLineEndings =
|
|
config.lineEndings === LineEndings.LF ? '\n' : '\r\n'
|
|
const incorrectLineEndings = expectedLineEndings === '\n' ? '\r\n' : '\n'
|
|
return text
|
|
.replace(new RegExp(incorrectLineEndings, 'g'), expectedLineEndings)
|
|
.split(expectedLineEndings)
|
|
}
|