UNPKG

@contentstack/utils

Version:
53 lines 2.01 kB
import { replaceHtmlEntities, forbiddenAttrChars } from '../helper/string-utils'; export function createMetadata(attribute) { return { text: attribute['#text'], itemUid: attribute['data-sys-entry-uid'] || attribute['data-sys-asset-uid'], itemType: attribute.type, styleType: attribute['sys-style-type'], attributes: attribute, contentTypeUid: attribute['data-sys-content-type-uid'], }; } export function nodeToMetadata(attribute, textNode) { return { text: textNode.text, itemUid: attribute['entry-uid'] || attribute['asset-uid'], itemType: attribute.type, styleType: attribute['display-type'], attributes: attribute, contentTypeUid: attribute['content-type-uid'], }; } export function attributeToString(attributes) { var result = ''; var _loop_1 = function (key) { if (Object.prototype.hasOwnProperty.call(attributes, key)) { if (forbiddenAttrChars.some(function (char) { return key.includes(char); })) { return "continue"; } var value = attributes[key]; if (Array.isArray(value)) { value = value.join(', '); } else if (typeof value === 'object') { var elementString = ''; for (var subKey in value) { if (Object.prototype.hasOwnProperty.call(value, subKey)) { var subValue = value[subKey]; if (subValue != null && subValue !== '') { elementString += "".concat(subKey, ":").concat(subValue, "; "); } } } value = elementString; } result += " ".concat(key, "=\"").concat(replaceHtmlEntities(String(value)), "\""); } }; for (var key in attributes) { _loop_1(key); } return result; } //# sourceMappingURL=metadata-model.js.map