Hyperlinkv0.8.0-beta.28

String

String.stripMarginWithconsteffect/String.ts:1010
(marginChar: string): (self: string) => string
(self: string, marginChar: string): string

Strips a leading margin prefix from every line using the supplied margin character.

Example (Stripping custom margins)

import { String } from "effect"

const text = "  |hello\n  |world"
const result = String.stripMarginWith(text, "|")
console.log(result) // "hello\nworld"
transforming
Source effect/String.ts:101022 lines
export const stripMarginWith: {
  (marginChar: string): (self: string) => string
  (self: string, marginChar: string): string
} = dual(2, (self: string, marginChar: string): string => {
  let out = ""

  for (const line of linesWithSeparators(self)) {
    let index = 0

    while (index < line.length && line.charAt(index) <= " ") {
      index = index + 1
    }

    const stripped = index < line.length && line.charAt(index) === marginChar
      ? line.substring(index + 1)
      : line

    out = out + stripped
  }

  return out
})
Referenced by 1 symbols