FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
docs/javascripts/hyperscript.js at main · NoraHansen/docs · GitHub
NoraHansen
/
docs
Public
forked from
github/docs
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
docs
/
javascripts
/
hyperscript.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
44 lines (37 loc) · 1.15 KB
Breadcrumbs
docs
/
javascripts
/
hyperscript.js
Copy path
File metadata and controls
44 lines (37 loc) · 1.15 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const
xmlns
=
'http://www.w3.org/2000/svg'
const
plainObjectConstructor
=
{
}
.
constructor
function
exists
(
value
)
{
return
value
!==
null
&&
typeof
value
!==
'undefined'
}
function
isPlainObject
(
value
)
{
return
value
.
constructor
===
plainObjectConstructor
}
function
isString
(
value
)
{
return
typeof
value
===
'string'
}
function
renderChildren
(
el
,
children
)
{
for
(
const
child
of
children
)
{
if
(
isPlainObject
(
child
)
)
{
Object
.
entries
(
child
)
.
filter
(
(
[
key
,
value
]
)
=>
exists
(
value
)
)
.
forEach
(
(
[
key
,
value
]
)
=>
el
.
setAttribute
(
key
,
value
)
)
}
else
if
(
Array
.
isArray
(
child
)
)
{
renderChildren
(
el
,
child
)
}
else
if
(
isString
(
child
)
)
{
el
.
append
(
document
.
createTextNode
(
child
)
)
}
else
{
el
.
append
(
child
)
}
}
}
export
default
function
h
(
tagName
,
...
children
)
{
const
el
=
[
'svg'
,
'path'
]
.
includes
(
tagName
)
?
document
.
createElementNS
(
xmlns
,
tagName
)
:
document
.
createElement
(
tagName
)
renderChildren
(
el
,
children
)
return
el
}
export
const
tags
=
Object
.
fromEntries
(
[
'div'
,
'form'
,
'a'
,
'input'
,
'button'
,
'ol'
,
'li'
,
'mark'
]
.
map
(
tagName
=>
[
tagName
,
(
...
args
)
=>
h
(
tagName
,
...
args
)
]
)
)
Back
|
FazBrowse Home
|
New Git URL