MCPcopy Create free account
hub / github.com/Effect-TS/effect / stripComment

Function stripComment

packages/effect/src/unstable/encoding/Yaml.ts:48–74  ·  view source on GitHub ↗
(input: string)

Source from the content-addressed store, hash-verified

46}
47
48const stripComment = (input: string): string => {
49 let quote: "'" | "\"" | undefined
50 let escaped = false
51 for (let index = 0; index < input.length; index++) {
52 const character = input[index]
53 if (quote === "\"") {
54 if (escaped) {
55 escaped = false
56 } else if (character === "\\") {
57 escaped = true
58 } else if (character === quote) {
59 quote = undefined
60 }
61 } else if (quote === "'") {
62 if (character === quote && input[index + 1] === quote) {
63 index++
64 } else if (character === quote) {
65 quote = undefined
66 }
67 } else if (character === "'" || character === "\"") {
68 quote = character
69 } else if (character === "#" && (index === 0 || /\s/.test(input[index - 1]))) {
70 return input.slice(0, index).trimEnd()
71 }
72 }
73 return input.trimEnd()
74}
75
76const mappingSeparator = (input: string): number => {
77 let quote: "'" | "\"" | undefined

Callers 1

parseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected