Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle the case where process.env does not exists (but process exists) #200

Merged
merged 1 commit into from
Feb 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/utils/utf8.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
import { UINT32_MAX } from "./int";

const TEXT_ENCODING_AVAILABLE =
(typeof process === "undefined" || process.env["TEXT_ENCODING"] !== "never") &&
(typeof process === "undefined" || process?.env?.["TEXT_ENCODING"] !== "never") &&
typeof TextEncoder !== "undefined" &&
typeof TextDecoder !== "undefined";

Expand Down Expand Up @@ -91,7 +92,7 @@ export function utf8EncodeJs(str: string, output: Uint8Array, outputOffset: numb
const sharedTextEncoder = TEXT_ENCODING_AVAILABLE ? new TextEncoder() : undefined;
export const TEXT_ENCODER_THRESHOLD = !TEXT_ENCODING_AVAILABLE
? UINT32_MAX
: typeof process !== "undefined" && process.env["TEXT_ENCODING"] !== "force"
: typeof process !== "undefined" && process?.env?.["TEXT_ENCODING"] !== "force"
? 200
: 0;

Expand Down Expand Up @@ -159,7 +160,7 @@ export function utf8DecodeJs(bytes: Uint8Array, inputOffset: number, byteLength:
const sharedTextDecoder = TEXT_ENCODING_AVAILABLE ? new TextDecoder() : null;
export const TEXT_DECODER_THRESHOLD = !TEXT_ENCODING_AVAILABLE
? UINT32_MAX
: typeof process !== "undefined" && process.env["TEXT_DECODER"] !== "force"
: typeof process !== "undefined" && process?.env?.["TEXT_DECODER"] !== "force"
? 200
: 0;

Expand Down