Skip to content

Commit

Permalink
refactor: update checking condition
Browse files Browse the repository at this point in the history
  • Loading branch information
climba03003 committed Mar 29, 2024
1 parent 6091169 commit 6d63b9b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,28 @@ async function * intoAsyncIterator (payload) {
const isBuffer = Buffer.isBuffer(payload)

if (
(
!isBuffer && (
// ArrayBuffer
payload instanceof ArrayBuffer ||
// NodeJS.TypedArray
ArrayBuffer.isView(payload)
) &&
// Exclude Buffer to prevent double cast
!isBuffer
)
) {
payload = Buffer.from(payload)
}

const isObject = typeof payload === 'object'

// Iterator
if (typeof payload === 'object' && typeof payload[Symbol.iterator] === 'function' && !isBuffer) {
if (!isBuffer && isObject && Symbol.iterator in payload) {
for (const chunk of payload) {
yield chunk
}
return
}

// Async Iterator
if (typeof payload === 'object' && typeof payload[Symbol.asyncIterator] === 'function' && !isBuffer) {
if (!isBuffer && isObject && Symbol.asyncIterator in payload) {
for await (const chunk of payload) {
yield chunk
}
Expand Down

0 comments on commit 6d63b9b

Please sign in to comment.