MCPcopy Create free account
hub / github.com/effect-app/libs / LinesIterator

Class LinesIterator

repos/effect/packages/effect/src/String.ts:1166–1211  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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"`
1187 * or `"\n"`).
1188 */
1189const isLineBreak = (char: string): boolean => {
1190 const code = char.charCodeAt(0)
1191 return code === CR || code === LF
1192}
1193
1194/**
1195 * Checks whether the provided characters combine to form a carriage return/line-feed
1196 * (i.e. `"\r\n"`).
1197 */
1198const isLineBreak2 = (char0: string, char1: string): boolean => char0.charCodeAt(0) === CR && char1.charCodeAt(0) === LF
1199
1200const linesSeparated = (self: string, stripped: boolean): LinesIterator => new LinesIterator(self, stripped)
1201
1202/**
1203 * Normalizes a string by splitting it into word parts, transforming each part,
1204 * and joining the parts with a configurable delimiter.
1205 *
1206 * **When to use**
1207 *
1208 * Use when you need custom word-case output with a delimiter or part transform
1209 * that the fixed case helpers do not provide.
1210 *
1211 * @see {@link pascalCase} for fixed PascalCase output
1212 * @see {@link camelCase} for fixed lower-initial camelCase output
1213 * @see {@link constantCase} for fixed uppercase underscore-separated output
1214 * @see {@link kebabCase} for fixed lowercase hyphen-separated output

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…