Skip to content

Instantly share code, notes, and snippets.

@MKRhere
Created September 18, 2018 14:39
Show Gist options
  • Save MKRhere/998ffec22c2df151e1fc83850efba82b to your computer and use it in GitHub Desktop.
Save MKRhere/998ffec22c2df151e1fc83850efba82b to your computer and use it in GitHub Desktop.
XMLBuilder
const tag = (name, attrs, close, content) => {
const end = close ? "/>" : ">";
const pairs = [];
let tag;
Object.keys(attrs).forEach(key => {
if (Object.prototype.hasOwnProperty.call(attrs, key)) {
pairs.push(key + '="' + (attrs[key]) + '"');
}
});
tag = "<" + name + (pairs.length ? " " + pairs.join(" ") : "") + end;
if (content) {
tag += content + "</" + name + end;
}
return new String(tag);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment