Skip to content

Commit 497a816

Browse files
authored
Merge pull request #200 from msgpack/gfx/process-env-may-not-be-defined
Handle the case where process.env does not exists (but process exists)
2 parents b041a96 + d81001c commit 497a816

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/utils/utf8.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
12
import { UINT32_MAX } from "./int";
23

34
const TEXT_ENCODING_AVAILABLE =
4-
(typeof process === "undefined" || process.env["TEXT_ENCODING"] !== "never") &&
5+
(typeof process === "undefined" || process?.env?.["TEXT_ENCODING"] !== "never") &&
56
typeof TextEncoder !== "undefined" &&
67
typeof TextDecoder !== "undefined";
78

@@ -91,7 +92,7 @@ export function utf8EncodeJs(str: string, output: Uint8Array, outputOffset: numb
9192
const sharedTextEncoder = TEXT_ENCODING_AVAILABLE ? new TextEncoder() : undefined;
9293
export const TEXT_ENCODER_THRESHOLD = !TEXT_ENCODING_AVAILABLE
9394
? UINT32_MAX
94-
: typeof process !== "undefined" && process.env["TEXT_ENCODING"] !== "force"
95+
: typeof process !== "undefined" && process?.env?.["TEXT_ENCODING"] !== "force"
9596
? 200
9697
: 0;
9798

@@ -159,7 +160,7 @@ export function utf8DecodeJs(bytes: Uint8Array, inputOffset: number, byteLength:
159160
const sharedTextDecoder = TEXT_ENCODING_AVAILABLE ? new TextDecoder() : null;
160161
export const TEXT_DECODER_THRESHOLD = !TEXT_ENCODING_AVAILABLE
161162
? UINT32_MAX
162-
: typeof process !== "undefined" && process.env["TEXT_DECODER"] !== "force"
163+
: typeof process !== "undefined" && process?.env?.["TEXT_DECODER"] !== "force"
163164
? 200
164165
: 0;
165166

0 commit comments

Comments
 (0)