hyperx-to-snabbdom
Advanced tools
Comparing version 1.0.0 to 1.1.0
196
index.js
@@ -1,70 +0,154 @@ | ||
module.exports = function (h) { | ||
return function (tagName, attrs, children) { | ||
var data = { | ||
"class": {}, | ||
props: {}, | ||
style: {}, | ||
attrs: {}, | ||
hook: {}, | ||
on: {} | ||
} | ||
module.exports = function(h) { | ||
return function(tagName, attrs, children) { | ||
var data = { | ||
class: {}, | ||
props: {}, | ||
style: {}, | ||
attrs: {}, | ||
hook: {}, | ||
on: {} | ||
} | ||
for (var key in attrs) { | ||
if (key === undefined || !attrs.hasOwnProperty(key)) { | ||
continue | ||
} | ||
var value = attrs[key] | ||
if (children && !isTextTag(tagName) && !isCodeTag(tagName)) { | ||
children = children.filter(function(child) { | ||
return typeof child !== "string" || child.trim() !== "" | ||
}) | ||
} | ||
if (key === "className") { | ||
var cls = value.split(" ") | ||
for (var i = 0; i < cls.length; i++) { | ||
data["class"][cls[i]] = true | ||
} | ||
} else if (key === "style") { | ||
data.style = value | ||
for (var key in attrs) { | ||
if (key === undefined || !attrs.hasOwnProperty(key)) { | ||
continue | ||
} | ||
var value = attrs[key] | ||
} else if ("on" === key.substr(0, 2)) { | ||
data.on[key.substr(2)] = value | ||
if (key === "className") { | ||
var cls = value.split(" ") | ||
for (var i = 0; i < cls.length; i++) { | ||
data["class"][cls[i]] = true | ||
} | ||
} else if (key === "style") { | ||
data.style = value | ||
} else if (key.substr(0, 2) === "on") { | ||
data.on[key.substr(2)] = value | ||
} else if (key.substr(0, 10) === "data-hook-") { | ||
data.hook[key.substr(10)] = value | ||
} else { | ||
if (isSVG(tagName)) { | ||
data.attrs[key] = parseBool(value) | ||
continue | ||
} | ||
data.props[key] = data.attrs[key] = parseBool(value) | ||
} | ||
} | ||
} else if ("data-hook-" === key.substr(0, 10)) { | ||
data.hook[key.substr(10)] = value | ||
return h(tagName, data, children ? [].concat.apply([], children) : children) | ||
} | ||
} | ||
} else { | ||
if (isSVG(tagName)) { | ||
data.attrs[key] = parseBool(value) | ||
continue | ||
} | ||
data.props[key] = data.attrs[key] = parseBool(value) | ||
} | ||
} | ||
function isTextTag(tagName) { | ||
var TEXT_TAGS = [ | ||
"a", | ||
"abbr", | ||
"b", | ||
"bdi", | ||
"bdo", | ||
"br", | ||
"cite", | ||
"data", | ||
"dfn", | ||
"em", | ||
"i", | ||
"kbd", | ||
"mark", | ||
"q", | ||
"rp", | ||
"rt", | ||
"rtc", | ||
"ruby", | ||
"s", | ||
"amp", | ||
"small", | ||
"span", | ||
"strong", | ||
"sub", | ||
"sup", | ||
"time", | ||
"u", | ||
"var", | ||
"wbr" | ||
] | ||
return h(tagName, data, children ? [].concat.apply([], children) : children) | ||
} | ||
return TEXT_TAGS.indexOf(tagName) !== -1 | ||
} | ||
function parseBool(value) { | ||
return value === "true" ? true : value === "false" ? false : value | ||
function isCodeTag(tagName) { | ||
var CODE_TAGS = ["code", "pre"] | ||
return CODE_TAGS.indexOf(tagName) !== -1 | ||
} | ||
function isSVG(tagName) { | ||
var svgTags = [ | ||
"svg", "animate", "animateTransform", "circle", "cursor", "desc", "ellipse", | ||
"feBlend", "feColorMatrix", "feComposite", | ||
"feConvolveMatrix", "feDiffuseLighting", "feDisplacementMap", | ||
"feDistantLight", "feFlood", "feFuncA", "feFuncB", "feFuncG", "feFuncR", | ||
"feGaussianBlur", "feImage", "feMergeNode", "feMorphology", | ||
"feOffset", "fePointLight", "feSpecularLighting", "feSpotLight", "feTile", | ||
"feTurbulence", "font-face-format", "font-face-name", "font-face-uri", | ||
"glyph", "glyphRef", "hkern", "image", "line", "missing-glyph", "mpath", | ||
"path", "polygon", "polyline", "rect", "set", "stop", "tref", "use", "view", | ||
"vkern" | ||
] | ||
var svgTags = [ | ||
"svg", | ||
"animate", | ||
"animateTransform", | ||
"circle", | ||
"cursor", | ||
"desc", | ||
"ellipse", | ||
"feBlend", | ||
"feColorMatrix", | ||
"feComposite", | ||
"feConvolveMatrix", | ||
"feDiffuseLighting", | ||
"feDisplacementMap", | ||
"feDistantLight", | ||
"feFlood", | ||
"feFuncA", | ||
"feFuncB", | ||
"feFuncG", | ||
"feFuncR", | ||
"feGaussianBlur", | ||
"feImage", | ||
"feMergeNode", | ||
"feMorphology", | ||
"feOffset", | ||
"fePointLight", | ||
"feSpecularLighting", | ||
"feSpotLight", | ||
"feTile", | ||
"feTurbulence", | ||
"font-face-format", | ||
"font-face-name", | ||
"font-face-uri", | ||
"glyph", | ||
"glyphRef", | ||
"hkern", | ||
"image", | ||
"line", | ||
"missing-glyph", | ||
"mpath", | ||
"path", | ||
"polygon", | ||
"polyline", | ||
"rect", | ||
"set", | ||
"stop", | ||
"tref", | ||
"use", | ||
"view", | ||
"vkern" | ||
] | ||
for (var i = 0; i < svgTags.length; i++) { | ||
if (tagName === svgTags[i]) { | ||
return true | ||
} | ||
for (var i = 0; i < svgTags.length; i++) { | ||
if (tagName === svgTags[i]) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
return false | ||
} | ||
function parseBool(value) { | ||
return value === "true" ? true : value === "false" ? false : value | ||
} |
{ | ||
"name": "hyperx-to-snabbdom", | ||
"version": "1.0.0", | ||
"description": "Use snabbdom with hyperx.", | ||
"version": "1.1.0", | ||
"description": "Use Snabbdom with Hyperx.", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "scripts": { |
# hyperx-to-snabbdom | ||
Use [snabbdom](https://github.com/snabbdom/snabbdom) with [hyperx](https://github.com/substack/hyperx). | ||
Use [Snabbdom](https://github.com/snabbdom/snabbdom) with [Hyperx](https://github.com/substack/hyperx). | ||
@@ -5,0 +5,0 @@ ## Installation |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4945
142
1