21 lines
479 B
JavaScript
21 lines
479 B
JavaScript
|
/** @type {(k: string) => string} */
|
||
|
const required = k => {
|
||
|
if (!process.env[k]) {
|
||
|
throw new Error(`Required environment variable not set: ${k}`)
|
||
|
}
|
||
|
return process.env[k]
|
||
|
}
|
||
|
|
||
|
/** @type {(k: string) => Array<string>} */
|
||
|
const array = k => {
|
||
|
const vals = required(k)
|
||
|
.split(',')
|
||
|
.flatMap(s => (!s.trim() ? [] : [s.trim()]))
|
||
|
if (vals.length === 0) {
|
||
|
throw new Error(`At least 1 value required: ${k}`)
|
||
|
}
|
||
|
return vals
|
||
|
}
|
||
|
|
||
|
export default { required, array }
|