From 87c340412455cf322451d0a016de99b6bc1666f1 Mon Sep 17 00:00:00 2001 From: Lordfirespeed <28568841+Lordfirespeed@users.noreply.github.com> Date: Sun, 25 Aug 2024 16:15:10 +0100 Subject: [PATCH] fix: import `iconv-lite` using namespace import --- src/get-read.ts | 4 ++-- src/utils/iconv.ts | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 src/utils/iconv.ts diff --git a/src/get-read.ts b/src/get-read.ts index 1693ace..ef8fe57 100644 --- a/src/get-read.ts +++ b/src/get-read.ts @@ -3,8 +3,8 @@ import { finished } from 'node:stream/promises' import * as zlib from 'node:zlib' import { ClientError, HttpError, ServerError } from '@otterhttp/errors' import { parse as parseBytes } from 'bytes' -import { encodingExists as charsetExists, decode as iconvDecode } from 'iconv-lite' +import { charsetExists, decodeCharset } from '@/utils/iconv' import { alreadyParsed } from '@/utils/already-parsed-symbol' import { ClientCharsetError, ClientEncodingError, ParseFailedError, VerifyFailedError } from '@/utils/errors' import { getCharset } from '@/utils/get-request-charset' @@ -215,7 +215,7 @@ export const getRead = (parseFunction: (body: string) => T | Promis let body: string try { - body = iconvDecode(bodyBlob, requestCharset) + body = decodeCharset(bodyBlob, requestCharset) } catch (err) { throw new ClientError(`request body does not adhere to charset '${requestCharset}'`, { statusCode: 400, diff --git a/src/utils/iconv.ts b/src/utils/iconv.ts new file mode 100644 index 0000000..ecb7484 --- /dev/null +++ b/src/utils/iconv.ts @@ -0,0 +1,4 @@ +import * as iconv from "iconv-lite" + +export const charsetExists = iconv.encodingExists +export const decodeCharset = iconv.decode \ No newline at end of file