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

Function unquote

packages/effect/src/unstable/encoding/Ini.ts:50–80  ·  view source on GitHub ↗
(input: string | undefined)

Source from the content-addressed store, hash-verified

48 (value.startsWith("'") && value.endsWith("'")))
49
50const unquote = (input: string | undefined): string => {
51 let value = (input ?? "").trim()
52 if (isQuoted(value)) {
53 if (value[0] === "'") {
54 value = value.slice(1, -1)
55 }
56 try {
57 return JSON.parse(value)
58 } catch {
59 return value
60 }
61 }
62
63 let escaped = false
64 let output = ""
65 for (const character of value) {
66 if (escaped) {
67 output += character === ";" || character === "#" || character === "\\"
68 ? character
69 : `\\${character}`
70 escaped = false
71 } else if (character === ";" || character === "#") {
72 break
73 } else if (character === "\\") {
74 escaped = true
75 } else {
76 output += character
77 }
78 }
79 return output.trim()
80}
81
82/**
83 * Parses an INI document into a null-prototype record.

Callers 1

parseFunction · 0.70

Calls 2

isQuotedFunction · 0.85
parseMethod · 0.45

Tested by

no test coverage detected