config.mjs 794 B

123456789101112131415161718192021222324252627
  1. import { replace } from 'lodash-es'
  2. 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)?)?$/
  3. export default {
  4. /**
  5. * Parse configuration value for environment vars
  6. *
  7. * Replaces `$(ENV_VAR_NAME)` with value of `ENV_VAR_NAME` environment variable.
  8. *
  9. * Also supports defaults by if provided as `$(ENV_VAR_NAME:default)`
  10. *
  11. * @param {any} cfg Configuration value
  12. * @returns Parse configuration value
  13. */
  14. parseConfigValue (cfg) {
  15. return replace(
  16. cfg,
  17. /\$\(([A-Z0-9_]+)(?::(.+))?\)/g,
  18. (fm, m, d) => { return process.env[m] || d }
  19. )
  20. },
  21. isValidDurationString (val) {
  22. return isoDurationReg.test(val)
  23. }
  24. }