lua-resty-dotenv
parse and expand .env file
$ opm get xiangnanscu/lua-resty-dotenv
lua-resty-dotenv
parse .env file, varible expandation and comment included.
Usage
    local dotenv = require "resty.dotenv"
    
    -- parsing .env file by default, same as: dotenv {'.env'}
    local env = dotenv()
    
    -- parsing giving string, same as: dotenv.parse()
    local env2 = dotenv([[
    A = 1
    B = ${A}+2
    ]])
    
    -- parsing a list of files
    local env3 = dotenv {'.env', '.env.local'}
Synopsis
.env
    A=1 # comment
    # a line comment
    B = 2
    C = 3
    D="4"
    E=${D}
    F=${E}
    G="g"
    JSON='{"foo": "bar"}'
    TRIM_STRING=    some spaced out string
    LINES1="this\nis\nmultiple line"
    LINES2="this
    is
    multiple line"
    LINES3="this
    is
    multiple line"
    RSA_KEY=`-----BEGIN RSA PRIVATE KEY-----
    #YOUR/FANCY/=KEY/YOUR/FANCY/=KEY
    YOUR/FANCY/=KEY/YOUR/FANCY/=KEY
    -----END RSA PRIVATE KEY-----`
    X=1
    Y=2
    Z=$X+${Y}
    XY=3
    S=${X}Y
    T=$XY+
    foo1='1
    2'
    foo2="1#1
    2"
    foo3=`1#1
    2`
    SPACE=  a + b = c    # comment
    EMPTY =
output
    {
      A = '1',
      B = '2',
      C = '3',
      D = '4',
      E = '4',
      F = '4',
      G = 'g',
      JSON = '{"foo": "bar"}',
      TRIM_STRING = 'some spaced out string',
      LINES1 = [[this\nis\nmultiple line]],
      LINES2 = [[this
    is
    multiple line]],
      LINES3 = [[this
    is
    multiple line]],
      RSA_KEY = [[-----BEGIN RSA PRIVATE KEY-----
    #YOUR/FANCY/=KEY/YOUR/FANCY/=KEY
    YOUR/FANCY/=KEY/YOUR/FANCY/=KEY
    -----END RSA PRIVATE KEY-----]],
      X = '1',
      Y = '2',
      Z = '1+2',
      XY = '3',
      S = '1Y',
      T = '3+',
      foo1 = '1\n2',
      foo2 = '1#1\n2',
      foo3 = '1#1\n2',
      SPACE = 'a + b = c',
      EMPTY = ''
    }
    
Authors
Nan Xiang(@xiangnanscu)
License
mit
Versions
- 
    
    
    parse and expand .env file 2025-02-08 13:30:47
 - 
    
    
    parse and expand .env file 2025-02-08 13:13:31
 - 
    
    
    parse and expand .env file 2024-07-07 15:16:20
 - 
    
    
    parse .env file 2024-07-07 07:23:57
 - 
    
    
    parse .env file 2024-07-07 07:17:31
 - 
    
    
    parse .env file 2024-02-19 01:58:18
 - 
    
    
    parse .env file 2024-01-25 12:16:52
 - 
    
    
    parse .env file 2024-01-25 01:11:43
 - 
    
    
    parse .env file 2024-01-24 16:36:19