| 524 | * @since 4.0.0 |
| 525 | */ |
| 526 | export const parse = (input: string): unknown => { |
| 527 | const source = input.replace(/^\uFEFF/, "").replace(/\r\n?/g, "\n") |
| 528 | const lines = source.split("\n").map((raw, index): Line => { |
| 529 | const indentation = /^( *)/.exec(raw)![1].length |
| 530 | if (raw.slice(0, indentation + 1).includes("\t")) { |
| 531 | throw new SyntaxError(`Tabs cannot be used for YAML indentation at line ${index + 1}`) |
| 532 | } |
| 533 | return { |
| 534 | raw, |
| 535 | text: stripComment(raw.slice(indentation)), |
| 536 | indent: indentation, |
| 537 | number: index + 1 |
| 538 | } |
| 539 | }) |
| 540 | return new YamlParser(lines).parse() |
| 541 | } |