atlassian-webresource-webpack-plugin
Version:
Auto-generates web-resource definitions from your webpacked code, for usage in an Atlassian product or plugin.
37 lines • 1.31 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.renderElement = exports.stringifyAttributes = void 0;
const stringifyAttributes = (attributes) => {
if (!attributes) {
return '';
}
return (' ' +
Object.keys(attributes)
.map((key) => {
const val = typeof attributes[key] === 'undefined' ? '' : String(attributes[key]);
return `${key}="${val}"`;
})
.join(' '));
};
exports.stringifyAttributes = stringifyAttributes;
const renderElement = (name, attributes, children) => {
if (typeof attributes === 'object') {
attributes = (0, exports.stringifyAttributes)(attributes);
}
// avoid outputting 'undefined' when attributes aren't present.
if (!attributes) {
attributes = '';
}
// convert children array in to a string.
// assume they are string values already. (todo: refactor for nested rendering?)
if (Array.isArray(children)) {
children = children.join('\n');
}
// render self-closing tags based on whether there is no child input.
if (!children) {
return `<${name}${attributes}/>`;
}
return `<${name}${attributes}>${children}</${name}>`;
};
exports.renderElement = renderElement;
//# sourceMappingURL=xml.js.map
;