(lines: string)
| 1094 | /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg |
| 1095 | |
| 1096 | function parseDotEnvContents(lines: string): Record<string, string> { |
| 1097 | const obj: Record<string, string> = Object.create(null) |
| 1098 | |
| 1099 | // Convert line breaks to same format |
| 1100 | lines = lines.replace(/\r\n?/gm, "\n") |
| 1101 | |
| 1102 | let match: RegExpExecArray | null |
| 1103 | while ((match = DOT_ENV_LINE.exec(lines)) != null) { |
| 1104 | const key = match[1] |
| 1105 | |
| 1106 | // Default undefined or null to empty string |
| 1107 | let value = match[2] || "" |
| 1108 | |
| 1109 | // Remove whitespace |
| 1110 | value = value.trim() |
| 1111 | |
| 1112 | // Check if double quoted |
| 1113 | const maybeQuote = value[0] |
| 1114 | |
| 1115 | // Remove surrounding quotes |
| 1116 | value = value.replace(/^(['"`])([\s\S]*)\1$/gm, "$2") |
| 1117 | |
| 1118 | // Expand newlines if double quoted |
| 1119 | if (maybeQuote === "\"") { |
| 1120 | value = value.replace(/\\n/g, "\n") |
| 1121 | value = value.replace(/\\r/g, "\r") |
| 1122 | } |
| 1123 | |
| 1124 | // Add to object |
| 1125 | obj[key] = value |
| 1126 | } |
| 1127 | |
| 1128 | return obj |
| 1129 | } |
| 1130 | |
| 1131 | function dotEnvExpand(parsed: Record<string, string>): Record<string, string> { |
| 1132 | const newParsed: Record<string, string> = Object.create(null) |
no test coverage detected