Files
freeCodeCamp/utils/get-lines.ts
Tom Fattah 03fbf03c91 refactor(tools/scripts): convert validate and get-lines to TS (#48622)
* fix(tools/scripts) convert validate and get-lines to typescript files

* fix(tools/scripts) refactor validate and get-lines to typescript

* remove any type and eslint ignore

* Update utils/validate.ts

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>

* address comments

* update .ignore files to ignore newly generated utils files

* Update utils/get-lines.ts

Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>

* remove unneeded ErrorInterface

* add local type annotation to 'expected' variable

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>
2023-01-08 21:55:06 +00:00

11 lines
267 B
TypeScript

export function getLines(contents: string, range?: number[]) {
if (!range) {
return '';
}
const lines = contents.split('\n');
const editableLines =
range[1] <= range[0] ? [] : lines.slice(range[0], range[1] - 1);
return editableLines.join('\n');
}