'use strict'; var ok = require('assert').ok; var HtmlAttribute = require('./HtmlAttribute'); class HtmlAttributeCollection { constructor(attributes) { this.all = []; this.lookup = {}; if (attributes) { if (Array.isArray(attributes)) { attributes.forEach((attr) => { this.addAttribute(attr); }); } else { for (var attrName in attributes) { if (attributes.hasOwnProperty(attrName)) { var attr = attributes[attrName]; attr.name = attrName; this.addAttribute(attr); } } } } } addAttribute(newAttr) { if (arguments.length === 2) { let name = arguments[0]; let expression = arguments[1]; newAttr = new HtmlAttribute(name, expression); } ok(HtmlAttribute.isHtmlAttribute(newAttr), 'Invalid attribute'); var name = newAttr.name; if (this.lookup.hasOwnProperty(name)) { for (var i=0; i 0; } getAttribute(name) { return this.lookup[name]; } getAttributes() { return this.all; } toJSON() { return this.all; } toString() { return JSON.stringify(this.all); } } module.exports = HtmlAttributeCollection;