| 48 | (value.startsWith("'") && value.endsWith("'"))) |
| 49 | |
| 50 | const 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. |