You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
804 B

  1. 'use strict'
  2. const _ = require('lodash')
  3. const isoDurationReg = /^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/
  4. module.exports = {
  5. /**
  6. * Parse configuration value for environment vars
  7. *
  8. * Replaces `$(ENV_VAR_NAME)` with value of `ENV_VAR_NAME` environment variable.
  9. *
  10. * Also supports defaults by if provided as `$(ENV_VAR_NAME:default)`
  11. *
  12. * @param {any} cfg Configuration value
  13. * @returns Parse configuration value
  14. */
  15. parseConfigValue (cfg) {
  16. return _.replace(
  17. cfg,
  18. /\$\(([A-Z0-9_]+)(?::(.+))?\)/g,
  19. (fm, m, d) => { return process.env[m] || d }
  20. )
  21. },
  22. isValidDurationString (val) {
  23. return isoDurationReg.test(val)
  24. }
  25. }