create-element-ns
Advanced tools
Comparing version 0.6.0 to 0.7.0
12
elm.js
@@ -7,2 +7,4 @@ var dom = require('dom-document'), | ||
var assign = Object.assign | ||
module.exports = elementFactory | ||
@@ -18,3 +20,3 @@ | ||
if (i === 0 && !cfg.element) { | ||
if (is.string(arg)) copyKeys(cfg, parse(arg)) | ||
if (is.string(arg)) assign(cfg, parse(arg)) | ||
else if (is.node(arg)) cfg.element = arg | ||
@@ -42,3 +44,3 @@ else if (is.function(arg)) cfg.element = arg(cfg) | ||
} | ||
return config ? copyKeys(create, config) : create | ||
return config ? assign(create, config) : create | ||
} | ||
@@ -56,6 +58,2 @@ function decorate(el, cfg) { | ||
} | ||
function copyKeys(t, s) { | ||
for (var i=0, ks=Object.keys(s); i<ks.length; ++i) t[ks[i]] = s[ks[i]] | ||
return t | ||
} | ||
function clone2(t, s) { | ||
@@ -66,3 +64,3 @@ for (var i=0, ks=Object.keys(s); i<ks.length; ++i) { | ||
: Array.isArray(s[k]) ? s[k].slice() | ||
: is.object(s[k]) ? copyKeys({}, s[k]) | ||
: is.object(s[k]) ? assign({}, s[k]) | ||
: s[k] | ||
@@ -69,0 +67,0 @@ } |
@@ -6,2 +6,5 @@ var dom = require('dom-document'), | ||
var el = factory() | ||
el.svg = el({xmlns: 'http://www.w3.org/2000/svg'}) | ||
module.exports = { | ||
@@ -11,4 +14,3 @@ dom: dom, | ||
decorators: decorators, | ||
html: factory(), | ||
svg: factory({xmlns: 'http://www.w3.org/2000/svg'}) | ||
el: el | ||
} |
{ | ||
"name": "create-element-ns", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"description": "dom createElement hyperscript with svg, namespace and selector support", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -14,18 +14,17 @@ <!-- markdownlint-disable MD004 MD007 MD010 MD041 MD022 MD024 MD032 MD036 --> | ||
var html = createElementNS.html, | ||
createHtmlFac = createElementNS.html({partial: true}), | ||
svg = createElementNS.svg | ||
var el = createElementNS.el, | ||
createHtmlFac = createElementNS.el({partial: true}), | ||
// selectors or attributes | ||
var divEl1 = html('div.c1#i1[style="color:blue"].c2', {onclick: function() {}}), | ||
divEl2 = html('div.i1', {style: {color: 'blue'}, props:{className: 'c1 c2', , onclick: function() {}}}) | ||
var divEl1 = el('div.c1#i1[style="color:blue"].c2', {onclick: function() {}}), | ||
divEl2 = el('div.i1', {style: {color: 'blue'}, props:{className: 'c1 c2', , onclick: function() {}}}) | ||
// namespace in different ways | ||
var circleEl1 = html('svg:circle'), | ||
circleEl2 = svg('svg:circle'), | ||
circleEl3 = html('circle[xmlns=http://www.w3.org/2000/svg]') | ||
circleEl3 = html('circle', {element: {xmlns : 'http://www.w3.org/2000/svg'}}) | ||
var circleEl1 = el('svg:circle'), | ||
circleEl2 = el.svg('circle'), | ||
circleEl3 = el('circle[xmlns=http://www.w3.org/2000/svg]') | ||
circleEl3 = el('circle', {element: {xmlns : 'http://www.w3.org/2000/svg'}}) | ||
// partial application to reate multiple modified clones | ||
var pFactory = html('p', {textContent: 'x', partial: true}), | ||
var pFactory = el('p', {textContent: 'x', partial: true}), | ||
pEl1 = pFactory({textContent: 'x'}) | ||
@@ -53,4 +52,4 @@ ``` | ||
To create an element (methods that return a DOM Element): | ||
* `html(definition [, options][, content])` => `HTMLElement` || `elementFactory` | ||
* `svg(definition [, options][, content])` => `SVGElement` || `elementFactory` | ||
* `el(definition [, options][, content])` => `HTMLElement` || `elementFactory` | ||
* `el.svg(definition [, options][, content])` => `SVGElement` || `elementFactory` | ||
@@ -57,0 +56,0 @@ If there is no tagName defined or if there is a partial property `{partial: true}` in the arguments, |
@@ -7,4 +7,4 @@ var jsdom = require('jsdom'), | ||
DOM = document.defaultView, | ||
htm = ceNS.html, | ||
svg = ceNS.svg | ||
htm = ceNS.el, | ||
svg = htm.svg | ||
@@ -36,2 +36,7 @@ ceNS.dom.document = document | ||
}) | ||
ct('svg style attributes', function() { | ||
var el = svg('svg[style="display: none;"]') | ||
ct('===', el.hasAttribute('style'), true) | ||
ct('===', el.getAttribute('style'), 'display: none;') | ||
}) | ||
ct('html text nodes', function() { | ||
@@ -38,0 +43,0 @@ var el = htm('div', 'one', [2, 'three']) |
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
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
13066
279
80