-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext.js
More file actions
26 lines (24 loc) · 667 Bytes
/
text.js
File metadata and controls
26 lines (24 loc) · 667 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const hyperchain = require('.');
const _ = require('./utils');
module.exports = opts => hyperchain(toString, opts);
function toString(tag, ...args) {
const { props, children } = _.getPropsAndChildren(args);
// console.log({props, children});
return `<${tag}`
+ Object.keys(props || {})
.map(prop => {
const val = props[prop];
switch (typeof val) {
case 'number':
case 'string':
return ` ${prop}=${JSON.stringify(val)}`;
case 'boolean':
return ` ${prop}="${JSON.stringify(val)}"`;
}
})
.filter(Boolean)
.join('')
+ `>`
+ (_.flat(children)).join('')
+ `</${tag}>`;
}