Skip to content

Commit d355bbd

Browse files
committed
Fix use of process for browsers
1 parent ad44f69 commit d355bbd

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/utils/utf8.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
export const TEXT_ENCODING_AVAILABLE =
2-
process.env.TEXT_ENCODING !== "never" && typeof TextEncoder !== "undefined" && typeof TextDecoder !== "undefined";
2+
typeof process !== "undefined" &&
3+
process.env.TEXT_ENCODING !== "never" &&
4+
typeof TextEncoder !== "undefined" &&
5+
typeof TextDecoder !== "undefined";
36

47
export function utf8Count(str: string): number {
58
const strLength = str.length;
@@ -85,7 +88,7 @@ export function utf8EncodeJs(str: string, output: Uint8Array, outputOffset: numb
8588
}
8689

8790
const sharedTextEncoder = TEXT_ENCODING_AVAILABLE ? new TextEncoder() : undefined;
88-
export const TEXT_ENCODER_THRESHOLD = process.env.TEXT_ENCODING !== "force" ? 200 : 0;
91+
export const TEXT_ENCODER_THRESHOLD = typeof process !== "undefined" && process.env.TEXT_ENCODING !== "force" ? 200 : 0;
8992

9093
function utf8EncodeTEencode(str: string, output: Uint8Array, outputOffset: number): void {
9194
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -151,7 +154,7 @@ export function utf8DecodeJs(bytes: Uint8Array, inputOffset: number, byteLength:
151154
}
152155

153156
const sharedTextDecoder = TEXT_ENCODING_AVAILABLE ? new TextDecoder() : null;
154-
export const TEXT_DECODER_THRESHOLD = process.env.TEXT_DECODER !== "force" ? 200 : 0;
157+
export const TEXT_DECODER_THRESHOLD = typeof process !== "undefined" && process.env.TEXT_DECODER !== "force" ? 200 : 0;
155158

156159
export function utf8DecodeTD(bytes: Uint8Array, inputOffset: number, byteLength: number): string {
157160
const stringBytes = bytes.subarray(inputOffset, inputOffset + byteLength);

0 commit comments

Comments
 (0)