bot18
Version:
A high-frequency cryptocurrency trading bot by Zenbot creator @carlos8f
47 lines (34 loc) • 1.05 kB
JavaScript
const flatten = require('lodash.flattendeep');
const VNode = require('./vnode');
const h = (component, props, ...children) => {
if (typeof component !== 'function' && typeof component !== 'string') {
throw new TypeError(`Expected component to be a function, but received ${typeof component}. You may have forgotten to export a component.`);
}
props = props || {};
const readyChildren = [];
if (children.length > 0) {
props.children = children;
}
flatten(props.children).forEach(child => {
if (typeof child === 'number') {
child = String(child);
}
if (typeof child === 'boolean' || child === null) {
child = '';
}
if (typeof child === 'string') {
if (typeof readyChildren[readyChildren.length - 1] === 'string') {
readyChildren[readyChildren.length - 1] += child;
} else {
readyChildren.push(child);
}
} else {
readyChildren.push(child);
}
});
props.children = readyChildren;
return new VNode(component, props);
};
h.Fragment = ({children}) => children;
module.exports = h;
;