wikijs-fork/server/helpers/common.js

43 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2018-08-04 21:27:55 +00:00
const _ = require('lodash')
module.exports = {
/**
* Get default value of type
*
* @param {any} type primitive type name
* @returns Default value
*/
getTypeDefaultValue (type) {
switch (type.toLowerCase()) {
case 'string':
return ''
case 'number':
return 0
case 'boolean':
return false
}
2018-08-04 21:27:55 +00:00
},
parseModuleProps (props) {
return _.transform(props, (result, value, key) => {
let defaultValue = ''
if (_.isPlainObject(value)) {
defaultValue = !_.isNil(value.default) ? value.default : this.getTypeDefaultValue(value.type)
} else {
defaultValue = this.getTypeDefaultValue(value)
}
_.set(result, key, {
default: defaultValue,
type: (value.type || value).toLowerCase(),
title: value.title || _.startCase(key),
hint: value.hint || false,
2019-02-03 22:08:06 +00:00
enum: value.enum || false,
2019-07-14 22:55:12 +00:00
multiline: value.multiline || false,
sensitive: value.sensitive || false,
maxWidth: value.maxWidth || 0,
2019-02-03 22:08:06 +00:00
order: value.order || 100
2018-08-04 21:27:55 +00:00
})
return result
}, {})
}
}