MCPcopy
hub / github.com/motdotla/dotenv / parse

Function parse

lib/main.js:41–77  ·  view source on GitHub ↗
(src)

Source from the content-addressed store, hash-verified

39
40// Parse src into an Object
41function parse (src) {
42 const obj = {}
43
44 // Convert buffer to string
45 let lines = src.toString()
46
47 // Convert line breaks to same format
48 lines = lines.replace(/\r\n?/mg, '\n')
49
50 let match
51 while ((match = LINE.exec(lines)) != null) {
52 const key = match[1]
53
54 // Default undefined or null to empty string
55 let value = (match[2] || '')
56
57 // Remove whitespace
58 value = value.trim()
59
60 // Check if double quoted
61 const maybeQuote = value[0]
62
63 // Remove surrounding quotes
64 value = value.replace(/^(['"`])([\s\S]*)\1$/mg, '$2')
65
66 // Expand newlines if double quoted
67 if (maybeQuote === '"') {
68 value = value.replace(/\\n/g, '\n')
69 value = value.replace(/\\r/g, '\r')
70 }
71
72 // Add to object
73 obj[key] = value
74 }
75
76 return obj
77}
78
79function _parseVault (options) {
80 options = options || {}

Callers 1

test.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…