From 0390e9c8bffb64eca27de067cd608d382015e711 Mon Sep 17 00:00:00 2001 From: madtisa Date: Sat, 10 Aug 2024 05:33:43 +0300 Subject: [PATCH] refactor: improve code readability --- src/index.ts | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/index.ts b/src/index.ts index 72c74a7..8784570 100644 --- a/src/index.ts +++ b/src/index.ts @@ -38,25 +38,22 @@ export default function isApng(buffer: Buffer | Uint8Array): boolean { let firstIndex = 0 let secondIndex = 0 for (let i = 0; i < buffer.length; i++) { - if ( - !foundFirst && - (buffer[i] === sequences.animationControlChunk[firstIndex] || - (firstIndex > 0 && - ((firstIndex = 0) || - buffer[i] === sequences.animationControlChunk[firstIndex]))) - ) { + if (buffer[i] !== sequences.animationControlChunk[firstIndex]) { + firstIndex = 0 + } + + if (buffer[i] === sequences.animationControlChunk[firstIndex]) { firstIndex++ if (firstIndex === sequences.animationControlChunk.length) { return true } } - if ( - buffer[i] === sequences.imageDataChunk[secondIndex] || - (secondIndex > 0 && - ((secondIndex = 0) || - buffer[i] === sequences.imageDataChunk[secondIndex])) - ) { + if (buffer[i] !== sequences.imageDataChunk[secondIndex]) { + secondIndex = 0 + } + + if (buffer[i] === sequences.imageDataChunk[secondIndex]) { secondIndex++ if (secondIndex === sequences.imageDataChunk.length) { return false