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 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 array-like containers (each
17
- element is added separately).
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(elt, ...children) {
3
+ function crelt() {
4
+ var elt = arguments[0];
4
5
  if (typeof elt == "string") elt = document.createElement(elt);
5
- let i = 0;
6
- if (children.length && typeof children[0] == "object" && children[0] && children[0].nodeType == null) {
7
- let attrs = children[0];
8
- for (let name in attrs) if (Object.prototype.hasOwnProperty.call(attrs, name)) {
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 = 1;
13
+ i++;
14
14
  }
15
- for (; i < children.length; i++) add(elt, children[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.length != null) {
25
- for (let i = 0; i < child.length; i++) add(elt, child[i]);
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
- attrs?: Child | {[attr: string]: any},
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(elt, ...children) {
1
+ export default function crelt() {
2
+ var elt = arguments[0]
2
3
  if (typeof elt == "string") elt = document.createElement(elt)
3
- let i = 0
4
- if (children.length && typeof children[0] == "object" && children[0] && children[0].nodeType == null) {
5
- let attrs = children[0]
6
- for (let name in attrs) if (Object.prototype.hasOwnProperty.call(attrs, name)) {
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 = 1
11
+ i++
12
12
  }
13
- for (; i < children.length; i++) add(elt, children[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.length != null) {
24
- for (let i = 0; i < child.length; i++) add(elt, child[i])
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.1",
3
+ "version": "1.0.5",
4
4
  "description": "Tiny DOM-element-creation utility",
5
- "main": "dist/index.js",
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": {
package/rollup.config.js CHANGED
@@ -1,7 +1,7 @@
1
1
  export default {
2
2
  input: "index.es.js",
3
3
  output: {
4
- file: "dist/index.js",
4
+ file: "dist/index.cjs",
5
5
  format: "cjs"
6
6
  }
7
7
  }