Files
2023-11-24 22:35:41 +01:00

27 lines
526 B
JavaScript

'use strict';
const {htmlEscape} = require('escape-goat');
module.exports = attributes => {
const handledAttributes = [];
for (let [key, value] of Object.entries(attributes)) {
if (value === false) {
continue;
}
if (Array.isArray(value)) {
value = value.join(' ');
}
let attribute = htmlEscape(key);
if (value !== true) {
attribute += `="${htmlEscape(String(value))}"`;
}
handledAttributes.push(attribute);
}
return handledAttributes.length > 0 ? ' ' + handledAttributes.join(' ') : '';
};