@kbach/react 0.5.22 → 0.5.23

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.
@@ -3453,11 +3453,20 @@ function kbach(userConfig) {
3453
3453
  const origEnd = res.end.bind(res);
3454
3454
  const chunks = [];
3455
3455
  let done = false;
3456
+ function toBuffer(chunk, enc) {
3457
+ if (chunk == null) return Buffer.alloc(0);
3458
+ if (typeof chunk === "string") {
3459
+ return Buffer.from(chunk, typeof enc === "string" ? enc : "utf-8");
3460
+ }
3461
+ if (ArrayBuffer.isView(chunk)) {
3462
+ return Buffer.from(chunk.buffer, chunk.byteOffset, chunk.byteLength);
3463
+ }
3464
+ if (chunk instanceof ArrayBuffer) return Buffer.from(chunk);
3465
+ return Buffer.from(String(chunk));
3466
+ }
3456
3467
  res.write = function(chunk, enc, cb) {
3457
3468
  if (done) return origWrite(chunk, enc, cb);
3458
- if (chunk != null) {
3459
- chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk ?? "")));
3460
- }
3469
+ if (chunk != null) chunks.push(toBuffer(chunk, enc));
3461
3470
  if (typeof enc === "function") enc();
3462
3471
  else if (typeof cb === "function") cb();
3463
3472
  return true;
@@ -3472,9 +3481,7 @@ function kbach(userConfig) {
3472
3481
  cb = enc;
3473
3482
  enc = null;
3474
3483
  }
3475
- if (chunk != null) {
3476
- chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk ?? "")));
3477
- }
3484
+ if (chunk != null) chunks.push(toBuffer(chunk, enc));
3478
3485
  if (chunks.length > 0) {
3479
3486
  const html = Buffer.concat(chunks).toString("utf-8");
3480
3487
  if (html.includes("</head>")) {
@@ -111,11 +111,20 @@ function kbach(userConfig) {
111
111
  const origEnd = res.end.bind(res);
112
112
  const chunks = [];
113
113
  let done = false;
114
+ function toBuffer(chunk, enc) {
115
+ if (chunk == null) return Buffer.alloc(0);
116
+ if (typeof chunk === "string") {
117
+ return Buffer.from(chunk, typeof enc === "string" ? enc : "utf-8");
118
+ }
119
+ if (ArrayBuffer.isView(chunk)) {
120
+ return Buffer.from(chunk.buffer, chunk.byteOffset, chunk.byteLength);
121
+ }
122
+ if (chunk instanceof ArrayBuffer) return Buffer.from(chunk);
123
+ return Buffer.from(String(chunk));
124
+ }
114
125
  res.write = function(chunk, enc, cb) {
115
126
  if (done) return origWrite(chunk, enc, cb);
116
- if (chunk != null) {
117
- chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk ?? "")));
118
- }
127
+ if (chunk != null) chunks.push(toBuffer(chunk, enc));
119
128
  if (typeof enc === "function") enc();
120
129
  else if (typeof cb === "function") cb();
121
130
  return true;
@@ -130,9 +139,7 @@ function kbach(userConfig) {
130
139
  cb = enc;
131
140
  enc = null;
132
141
  }
133
- if (chunk != null) {
134
- chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk ?? "")));
135
- }
142
+ if (chunk != null) chunks.push(toBuffer(chunk, enc));
136
143
  if (chunks.length > 0) {
137
144
  const html = Buffer.concat(chunks).toString("utf-8");
138
145
  if (html.includes("</head>")) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kbach/react",
3
- "version": "0.5.22",
3
+ "version": "0.5.23",
4
4
  "description": "React / React Native components and hooks for the Kbach framework",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./dist/index.js",