| 1136 | export const kebabToSnake = (self: string): string => self.replace(/-/g, "_") |
| 1137 | |
| 1138 | class LinesIterator implements IterableIterator<string> { |
| 1139 | private index: number |
| 1140 | private readonly length: number |
| 1141 | readonly s: string |
| 1142 | readonly stripped: boolean |
| 1143 | |
| 1144 | constructor( |
| 1145 | s: string, |
| 1146 | stripped: boolean = false |
| 1147 | ) { |
| 1148 | this.s = s |
| 1149 | this.stripped = stripped |
| 1150 | this.index = 0 |
| 1151 | this.length = s.length |
| 1152 | } |
| 1153 | |
| 1154 | next(): IteratorResult<string> { |
| 1155 | if (this.done) { |
| 1156 | return { done: true, value: undefined } |
| 1157 | } |
| 1158 | const start = this.index |
| 1159 | while (!this.done && !isLineBreak(this.s[this.index]!)) { |
| 1160 | this.index = this.index + 1 |
| 1161 | } |
| 1162 | let end = this.index |
| 1163 | if (!this.done) { |
| 1164 | const char = this.s[this.index]! |
| 1165 | this.index = this.index + 1 |
| 1166 | if (!this.done && isLineBreak2(char, this.s[this.index]!)) { |
| 1167 | this.index = this.index + 1 |
| 1168 | } |
| 1169 | if (!this.stripped) { |
| 1170 | end = this.index |
| 1171 | } |
| 1172 | } |
| 1173 | return { done: false, value: this.s.substring(start, end) } |
| 1174 | } |
| 1175 | |
| 1176 | [Symbol.iterator](): IterableIterator<string> { |
| 1177 | return new LinesIterator(this.s, this.stripped) |
| 1178 | } |
| 1179 | |
| 1180 | private get done(): boolean { |
| 1181 | return this.index >= this.length |
| 1182 | } |
| 1183 | } |
| 1184 | |
| 1185 | /** |
| 1186 | * Checks whether the provided character is a line break character (i.e. either `"\r"` |
nothing calls this directly
no outgoing calls
no test coverage detected