From 7114a1584ebe18d395940f448c75747d169fbb2c Mon Sep 17 00:00:00 2001 From: Joeylene <23741509+jorenrui@users.noreply.github.com> Date: Sun, 24 Mar 2024 16:03:34 +0800 Subject: [PATCH] refactor: prevent array.nextItem and array.previousItem to return null --- lib/helpers/array.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/helpers/array.js b/lib/helpers/array.js index a7f330c..7fc7846 100644 --- a/lib/helpers/array.js +++ b/lib/helpers/array.js @@ -136,7 +136,7 @@ export class MiniArray extends Array { } else { const flatArray = this.deepFlat() const nextIndex = flatArray.indexOf(item) + 1 - if (nextIndex === -1) return null + if (nextIndex === -1) return flatArray.first return nextIndex >= flatArray.length ? flatArray.first : flatArray.at(nextIndex) } } @@ -147,7 +147,7 @@ export class MiniArray extends Array { } else { const flatArray = this.deepFlat() const previousIndex = flatArray.indexOf(item) - 1 - if (previousIndex === -1) return null + if (previousIndex === -1) return flatArray.last return previousIndex < 0 ? flatArray.last : flatArray.at(previousIndex) } }