crelt 1.0.1 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/{index.js → index.cjs} +10 -10
- package/index.d.ts +2 -3
- package/index.es.js +10 -10
- package/package.json +7 -2
- package/rollup.config.js +1 -1
package/README.md
CHANGED
|
@@ -13,8 +13,8 @@ which is a function that you call with:
|
|
|
13
13
|
not assigned.
|
|
14
14
|
|
|
15
15
|
- Any number of children, which may be null (ignored), strings (added
|
|
16
|
-
as text nodes), DOM nodes (added), or
|
|
17
|
-
|
|
16
|
+
as text nodes), DOM nodes (added), or arrays (each element is added
|
|
17
|
+
separately).
|
|
18
18
|
|
|
19
19
|
The function returns a DOM element.
|
|
20
20
|
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
function crelt(
|
|
3
|
+
function crelt() {
|
|
4
|
+
var elt = arguments[0];
|
|
4
5
|
if (typeof elt == "string") elt = document.createElement(elt);
|
|
5
|
-
|
|
6
|
-
if (
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
let value = attrs[name];
|
|
6
|
+
var i = 1, next = arguments[1];
|
|
7
|
+
if (next && typeof next == "object" && next.nodeType == null && !Array.isArray(next)) {
|
|
8
|
+
for (var name in next) if (Object.prototype.hasOwnProperty.call(next, name)) {
|
|
9
|
+
var value = next[name];
|
|
10
10
|
if (typeof value == "string") elt.setAttribute(name, value);
|
|
11
11
|
else if (value != null) elt[name] = value;
|
|
12
12
|
}
|
|
13
|
-
i
|
|
13
|
+
i++;
|
|
14
14
|
}
|
|
15
|
-
for (; i <
|
|
15
|
+
for (; i < arguments.length; i++) add(elt, arguments[i]);
|
|
16
16
|
return elt
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -21,8 +21,8 @@ function add(elt, child) {
|
|
|
21
21
|
elt.appendChild(document.createTextNode(child));
|
|
22
22
|
} else if (child == null) ; else if (child.nodeType != null) {
|
|
23
23
|
elt.appendChild(child);
|
|
24
|
-
} else if (child
|
|
25
|
-
for (
|
|
24
|
+
} else if (Array.isArray(child)) {
|
|
25
|
+
for (var i = 0; i < child.length; i++) add(elt, child[i]);
|
|
26
26
|
} else {
|
|
27
27
|
throw new RangeError("Unsupported child node: " + child)
|
|
28
28
|
}
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
type Child = string | Node | null | undefined | readonly Child[]
|
|
2
2
|
|
|
3
|
-
export default function crelt(elt: string | HTMLElement,
|
|
4
|
-
|
|
5
|
-
...children: Child[]): HTMLElement
|
|
3
|
+
export default function crelt(elt: string | HTMLElement, attrs: {[attr: string]: any}, ...children: Child[]): HTMLElement
|
|
4
|
+
export default function crelt(elt: string | HTMLElement, ...children: Child[]): HTMLElement
|
package/index.es.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export default function crelt(
|
|
1
|
+
export default function crelt() {
|
|
2
|
+
var elt = arguments[0]
|
|
2
3
|
if (typeof elt == "string") elt = document.createElement(elt)
|
|
3
|
-
|
|
4
|
-
if (
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
let value = attrs[name]
|
|
4
|
+
var i = 1, next = arguments[1]
|
|
5
|
+
if (next && typeof next == "object" && next.nodeType == null && !Array.isArray(next)) {
|
|
6
|
+
for (var name in next) if (Object.prototype.hasOwnProperty.call(next, name)) {
|
|
7
|
+
var value = next[name]
|
|
8
8
|
if (typeof value == "string") elt.setAttribute(name, value)
|
|
9
9
|
else if (value != null) elt[name] = value
|
|
10
10
|
}
|
|
11
|
-
i
|
|
11
|
+
i++
|
|
12
12
|
}
|
|
13
|
-
for (; i <
|
|
13
|
+
for (; i < arguments.length; i++) add(elt, arguments[i])
|
|
14
14
|
return elt
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -20,8 +20,8 @@ function add(elt, child) {
|
|
|
20
20
|
} else if (child == null) {
|
|
21
21
|
} else if (child.nodeType != null) {
|
|
22
22
|
elt.appendChild(child)
|
|
23
|
-
} else if (child
|
|
24
|
-
for (
|
|
23
|
+
} else if (Array.isArray(child)) {
|
|
24
|
+
for (var i = 0; i < child.length; i++) add(elt, child[i])
|
|
25
25
|
} else {
|
|
26
26
|
throw new RangeError("Unsupported child node: " + child)
|
|
27
27
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "crelt",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "Tiny DOM-element-creation utility",
|
|
5
|
-
"main": "dist/index.
|
|
5
|
+
"main": "dist/index.cjs",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
"import": "./index.es.js",
|
|
9
|
+
"require": "./dist/index.cjs"
|
|
10
|
+
},
|
|
6
11
|
"module": "index.es.js",
|
|
7
12
|
"types": "index.d.ts",
|
|
8
13
|
"scripts": {
|