UNPKG

marko

Version:

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

46 lines (37 loc) 944 B
"use strict"; var changeCase = require("./_change-case"); /** * Helper for generating the string for a style attribute */ module.exports = function styleHelper(style) { if (!style) { return; } var type = typeof style; if (type !== "string") { var styles = ""; var sep = ""; if (Array.isArray(style)) { for (var i = 0, len = style.length; i < len; i++) { var next = styleHelper(style[i]); if (next) { styles += sep + next; sep = ";"; } } } else if (type === "object") { for (var name in style) { var value = style[name]; if (value != null && value !== false) { if (typeof value === "number" && value) { value += "px"; } styles += sep + changeCase.___camelToDashCase(name) + ":" + value; sep = ";"; } } } return styles || undefined; } return style; };