ghtml 1.2.4 → 1.2.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
@@ -20,7 +20,7 @@ The `htmlGenerator` function acts as the generator version of the `html` functio
20
20
 
21
21
  **Note:**
22
22
 
23
- A key difference of `htmlGenerator` is its ability to recognize and properly handle iterable elements within array expressions. This is to detect nested `htmlGenerator` usage, enabling scenarios such as ``[1,2,3].map(i => htmlGenerator`<li>${i}</li>`)``.
23
+ A key difference of `htmlGenerator` is its ability to recognize and properly handle iterable elements within array expressions. This is to detect nested `htmlGenerator` usage, enabling scenarios such as ``${[1, 2, 3].map(i => htmlGenerator`<li>${i}</li>`)}``.
24
24
 
25
25
  As a side effect, an expression like `${[[1, 2, 3], 4]}` (where an element is an array itself) will not be rendered as `"1,2,34"`, which is the case with `html`, but as `"1234"`. This is the intended behavior most of the time anyway.
26
26
 
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Replace your template engine with fast JavaScript by leveraging the power of tagged templates.",
4
4
  "author": "Gürgün Dayıoğlu",
5
5
  "license": "MIT",
6
- "version": "1.2.4",
6
+ "version": "1.2.5",
7
7
  "type": "module",
8
8
  "main": "./src/index.js",
9
9
  "exports": {
package/src/html.js CHANGED
@@ -29,7 +29,7 @@ const html = ({ raw: literals }, ...expressions) => {
29
29
  let expression =
30
30
  typeof expressions[index] === "string"
31
31
  ? expressions[index]
32
- : expressions[index] == null
32
+ : expressions[index] === undefined || expressions[index] === null
33
33
  ? ""
34
34
  : Array.isArray(expressions[index])
35
35
  ? expressions[index].join("")
@@ -61,12 +61,15 @@ const htmlGenerator = function* ({ raw: literals }, ...expressions) {
61
61
 
62
62
  if (typeof expressions[index] === "string") {
63
63
  expression = expressions[index];
64
- } else if (expressions[index] == null) {
64
+ } else if (
65
+ expressions[index] === undefined ||
66
+ expressions[index] === null
67
+ ) {
65
68
  expression = "";
66
69
  } else {
67
70
  if (typeof expressions[index][Symbol.iterator] === "function") {
68
71
  const isRaw =
69
- literal.length > 0 && literal.charCodeAt(literal.length - 1) === 33;
72
+ literal.length !== 0 && literal.charCodeAt(literal.length - 1) === 33;
70
73
 
71
74
  if (isRaw) {
72
75
  literal = literal.slice(0, -1);
@@ -79,16 +82,13 @@ const htmlGenerator = function* ({ raw: literals }, ...expressions) {
79
82
  for (const value of expressions[index]) {
80
83
  if (typeof value === "string") {
81
84
  expression = value;
82
- } else if (value == null) {
85
+ } else if (value === undefined || value === null) {
83
86
  expression = "";
84
87
  } else if (typeof value[Symbol.iterator] === "function") {
85
88
  expression = "";
86
89
 
87
90
  for (const innerValue of value) {
88
- if (innerValue != null) {
89
- // At this level, we simply mirror Array.prototype.join
90
- expression += innerValue;
91
- }
91
+ expression += innerValue ?? "";
92
92
  }
93
93
  } else {
94
94
  expression = `${value}`;