UNPKG

gumbajs

Version:

Component code generator for projects done with AEM and Sightly.

47 lines (39 loc) 1.14 kB
'use strict'; module.exports = object => { if (!object) { throw new Error('You forgot to pass the object that must be parsed..'); } const parsedAttribute = { defaultValue: handleDefaultValue(object.defaultValue), name: handleName(object.name), type: handleType(object.xtype), optional: handleOptional(object.allowBlank) }; return parsedAttribute; }; function handleDefaultValue(value) { value = value || ''; const parsedValue = value.replace('{Boolean}', ''); return parsedValue; } function handleName(name) { name = name || ''; const parsedValue = name.replace('./', ''); return parsedValue; } function handleType(type) { const typeReferences = { colorfield: 'string', pathfield: 'string', selection: 'string', textfield: 'string', textarea: 'string', multifield: 'list' }; return typeReferences[type] || ''; } function handleOptional(allowBlank) { allowBlank = allowBlank || 'true'; const parsedValue = allowBlank.replace('{Boolean}', ''); return parsedValue === 'true'; }