INNER CODE UNIT · JavaScript
createRegistry
dotenvx/dotenvx · src/lib/custodians/index.js:13
function createRegistry (custodians) {
const entries = new Map()
for (const custodian of custodians) {
if (!custodian || typeof custodian.id !== 'string' || !custodian.id || entries.has(custodian.id)) {
throw new Error('custodians must have unique, nonempty ids')
}
for (const method of ['enabled', 'available', 'store']) {
if (typeof custodian[method] !== 'function') throw new Error(`custodian ${custodian.id} requires ${method}()`)
}
entries.set(custodian.id, custodian)
}
function get (id) {
const custodian = entries.get(id)
if (!custodian) throw new Error(`unknown custodian: ${id}`)
return custodian
}