blob: f5e0d164f9edcfb6bc3a963b47cd39641f9ebfa1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
// return the description of the valid values of a field
// returns a string for one thing, or an array of descriptions
const typeDefs = require('./type-defs.js')
const typeDescription = t => {
if (!t || typeof t !== 'function' && typeof t !== 'object') {
return t
}
if (Array.isArray(t)) {
return t.map(t => typeDescription(t))
}
for (const { type, description } of Object.values(typeDefs)) {
if (type === t) {
return description || type
}
}
return t
}
module.exports = t => [].concat(typeDescription(t)).filter(t => t !== undefined)
|