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

Function parseDotEnv

packages/platform/src/internal/platformConfigProvider.ts:62–95  ·  view source on GitHub ↗
(lines: string)

Source from the content-addressed store, hash-verified

60
61/** @internal */
62const 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 */
98const expand = (parsed: Record<string, string>) => {

Callers 1

fromDotEnvFunction · 0.85

Calls 2

execMethod · 0.80
expandFunction · 0.70

Tested by

no test coverage detected