UNPKG

marko

Version:

UI Components + streaming, async, high performance, HTML templating for Node.js and the browser.

63 lines (50 loc) 1.47 kB
"use strict"; // eslint-disable-next-line no-constant-binary-expression var complain = "MARKO_DEBUG" && require("complain"); var classHelper = require("../../helpers/class-value"); var styleHelper = require("../../helpers/style-value"); var parseHTML = require("../parse-html"); /** * Helper for processing dynamic attributes */ module.exports = function (attributes) { if (typeof attributes === "string") { // eslint-disable-next-line no-constant-condition if ("MARKO_DEBUG") { complain( "Passing a string as a dynamic attribute value is deprecated - More details: https://github.com/marko-js/marko/wiki/Deprecation:-String-as-dynamic-attribute-value", ); } return parseAttrs(attributes); } if (attributes) { var newAttributes = {}; for (var attrName in attributes) { var val = attributes[attrName]; if (attrName === "renderBody") { continue; } if (attrName === "class") { val = classHelper(val); } else if (attrName === "style") { val = styleHelper(val); } newAttributes[attrName] = val; } return newAttributes; } return attributes; }; function parseAttrs(str) { if (str === "") { return {}; } var attrs = parseHTML("<a " + str + ">").attributes; var result = {}; var attr; for (var len = attrs.length, i = 0; i < len; i++) { attr = attrs[i]; result[attr.name] = attr.value; } return result; }