trim content builder model attributes

This commit is contained in:
Getriax 2019-03-18 22:18:55 +01:00
parent 9b20f27657
commit b9c67e7f8f
2 changed files with 27 additions and 5 deletions

View File

@ -10,6 +10,7 @@ const {
createManager, createManager,
removeColsLine, removeColsLine,
reorderList, reorderList,
deepTrimObject,
} = require('../utils/helpers.js'); } = require('../utils/helpers.js');
module.exports = { module.exports = {
@ -336,8 +337,9 @@ module.exports = {
}); });
Object.assign(attributesNotConfigurable, attrs); Object.assign(attributesNotConfigurable, attrs);
const trimmedNotConfigurableAttributes = deepTrimObject(attributesNotConfigurable);
return [attributesNotConfigurable, errors]; return [trimmedNotConfigurableAttributes, errors];
}, },
clearRelations: (model, source, force) => { clearRelations: (model, source, force) => {

View File

@ -65,11 +65,31 @@ const escapeNewlines = (content, placeholder = '\n') => {
return content.replace(/[\r\n]+/g, placeholder); return content.replace(/[\r\n]+/g, placeholder);
} }
const deepTrimObject = attribute => {
if (Array.isArray(attribute)) {
return attribute.map(deepTrimObject);
}
if (typeof attribute === 'object') {
return Object.entries(attribute)
.reduce((acc, [key, value]) => {
const trimmedObject = deepTrimObject(value);
return { ...acc, [key]: trimmedObject };
}, {});
}
return typeof attribute === 'string'
? attribute.trim()
: attribute;
}
module.exports = { module.exports = {
createArrayOfLastEls, createArrayOfLastEls,
createManager, createManager,
getElementsOnALine, getElementsOnALine,
removeColsLine, removeColsLine,
reorderList, reorderList,
escapeNewlines escapeNewlines,
deepTrimObject
}; };