You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.1 KiB

  1. const _ = require('lodash')
  2. module.exports = {
  3. /**
  4. * Get default value of type
  5. *
  6. * @param {any} type primitive type name
  7. * @returns Default value
  8. */
  9. getTypeDefaultValue (type) {
  10. switch (type.toLowerCase()) {
  11. case 'string':
  12. return ''
  13. case 'number':
  14. return 0
  15. case 'boolean':
  16. return false
  17. }
  18. },
  19. parseModuleProps (props) {
  20. return _.transform(props, (result, value, key) => {
  21. let defaultValue = ''
  22. if (_.isPlainObject(value)) {
  23. defaultValue = !_.isNil(value.default) ? value.default : this.getTypeDefaultValue(value.type)
  24. } else {
  25. defaultValue = this.getTypeDefaultValue(value)
  26. }
  27. _.set(result, key, {
  28. default: defaultValue,
  29. type: (value.type || value).toLowerCase(),
  30. title: value.title || _.startCase(key),
  31. hint: value.hint || false,
  32. enum: value.enum || false,
  33. multiline: value.multiline || false,
  34. sensitive: value.sensitive || false,
  35. order: value.order || 100
  36. })
  37. return result
  38. }, {})
  39. }
  40. }