# All files / server-old/src/config env.js

95.65% Statements 22/23
91.67% Branches 11/12
100% Functions 4/4
100% Lines 18/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    27x

    27x
    4752x
    4158x
    3618x

    27x
    6372x
    4752x
    4752x
    4158x
    3618x
    3618x

    27x

    3564x

    27x
    27x
    6372x

    27x
     // Load them from the environment file if any
    require('dotenv').config({ silent: true });

    // Check if a variable is numeric even if string
    const is = {
      numeric: num => !isNaN(num),
      boolean: bool => /^(true|false)$/i.test(bool),
      json: str => /^[{[]/.test(str) && /[}\]]$/.test(str)
    };

    const type = str => {
      if (!str) return;
      Iif (typeof str !== 'string') return str;
      if (is.numeric(str)) return +str;
      if (is.boolean(str)) return /true/i.test(str);
      try {
        if (is.json(str)) return JSON.parse(str);
      } catch (err) {
        return str;
      }
      return str;
    };

    const env = {};
    for (let key in process.env) {
      env[key] = type(process.env[key]);
    }

    module.exports = env;