source: frontend/node_modules/dotenv-expand/lib/main.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.3 KB
Line 
1'use strict'
2
3var dotenvExpand = function (config) {
4 // if ignoring process.env, use a blank object
5 var environment = config.ignoreProcessEnv ? {} : process.env
6
7 var interpolate = function (envValue) {
8 var matches = envValue.match(/(.?\${?(?:[a-zA-Z0-9_]+)?}?)/g) || []
9
10 return matches.reduce(function (newEnv, match) {
11 var parts = /(.?)\${?([a-zA-Z0-9_]+)?}?/g.exec(match)
12 var prefix = parts[1]
13
14 var value, replacePart
15
16 if (prefix === '\\') {
17 replacePart = parts[0]
18 value = replacePart.replace('\\$', '$')
19 } else {
20 var key = parts[2]
21 replacePart = parts[0].substring(prefix.length)
22 // process.env value 'wins' over .env file's value
23 value = environment.hasOwnProperty(key) ? environment[key] : (config.parsed[key] || '')
24
25 // Resolve recursive interpolations
26 value = interpolate(value)
27 }
28
29 return newEnv.replace(replacePart, value)
30 }, envValue)
31 }
32
33 for (var configKey in config.parsed) {
34 var value = environment.hasOwnProperty(configKey) ? environment[configKey] : config.parsed[configKey]
35
36 config.parsed[configKey] = interpolate(value)
37 }
38
39 for (var processKey in config.parsed) {
40 environment[processKey] = config.parsed[processKey]
41 }
42
43 return config
44}
45
46module.exports = dotenvExpand
Note: See TracBrowser for help on using the repository browser.