hyperscript-helpers
Version:
Terse syntax for hyperscript
47 lines (39 loc) • 2.53 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', {
value: true
});
var isValidString = function isValidString(param) {
return typeof param === 'string' && param.length > 0;
};
var startsWith = function startsWith(string, start) {
return string[0] === start;
};
var isSelector = function isSelector(param) {
return isValidString(param) && (startsWith(param, '.') || startsWith(param, '#'));
};
var node = function node(h) {
return function (tagName) {
return function (first) {
for (var _len = arguments.length, rest = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
rest[_key - 1] = arguments[_key];
}
if (isSelector(first)) {
return h.apply(undefined, [tagName + first].concat(rest));
} else if (typeof first === 'undefined') {
return h(tagName);
} else {
return h.apply(undefined, [tagName, first].concat(rest));
}
};
};
};
var TAG_NAMES = ['a', 'abbr', 'acronym', 'address', 'applet', 'area', 'article', 'aside', 'audio', 'b', 'base', 'basefont', 'bdi', 'bdo', 'bgsound', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'command', 'content', 'data', 'datalist', 'dd', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'embed', 'fieldset', 'figcaption', 'figure', 'font', 'footer', 'form', 'frame', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'iframe', 'image', 'img', 'input', 'ins', 'isindex', 'kbd', 'keygen', 'label', 'legend', 'li', 'link', 'listing', 'main', 'map', 'mark', 'marquee', 'math', 'menu', 'menuitem', 'meta', 'meter', 'multicol', 'nav', 'nextid', 'nobr', 'noembed', 'noframes', 'noscript', 'object', 'ol', 'optgroup', 'option', 'output', 'p', 'param', 'picture', 'plaintext', 'pre', 'progress', 'q', 'rb', 'rbc', 'rp', 'rt', 'rtc', 'ruby', 's', 'samp', 'script', 'section', 'select', 'shadow', 'slot', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'svg', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'title', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr', 'xmp'];
exports['default'] = function (h) {
var createTag = node(h);
var exported = { TAG_NAMES: TAG_NAMES, isSelector: isSelector, createTag: createTag };
TAG_NAMES.forEach(function (n) {
exported[n] = createTag(n);
});
return exported;
};
module.exports = exports['default'];