(lines: string)
| 60 | |
| 61 | /** @internal */ |
| 62 | const parseDotEnv = (lines: string): Record<string, string> => { |
| 63 | const obj: Record<string, string> = {} |
| 64 | |
| 65 | // Convert line breaks to same format |
| 66 | lines = lines.replace(/\r\n?/gm, "\n") |
| 67 | |
| 68 | let match: RegExpExecArray | null |
| 69 | while ((match = DOT_ENV_LINE.exec(lines)) != null) { |
| 70 | const key = match[1] |
| 71 | |
| 72 | // Default undefined or null to empty string |
| 73 | let value = match[2] || "" |
| 74 | |
| 75 | // Remove whitespace |
| 76 | value = value.trim() |
| 77 | |
| 78 | // Check if double quoted |
| 79 | const maybeQuote = value[0] |
| 80 | |
| 81 | // Remove surrounding quotes |
| 82 | value = value.replace(/^(['"`])([\s\S]*)\1$/gm, "$2") |
| 83 | |
| 84 | // Expand newlines if double quoted |
| 85 | if (maybeQuote === "\"") { |
| 86 | value = value.replace(/\\n/g, "\n") |
| 87 | value = value.replace(/\\r/g, "\r") |
| 88 | } |
| 89 | |
| 90 | // Add to object |
| 91 | obj[key] = value |
| 92 | } |
| 93 | |
| 94 | return expand(obj) |
| 95 | } |
| 96 | |
| 97 | /** @internal */ |
| 98 | const expand = (parsed: Record<string, string>) => { |
no test coverage detected