From 83e8ed58b98076784844964a91caba5df87f2724 Mon Sep 17 00:00:00 2001 From: Heathcliff Date: Wed, 11 Sep 2024 14:08:57 +0800 Subject: [PATCH] fix: isEmpty returning incorrect value --- src/tests/typed.test.ts | 2 ++ src/typed.ts | 1 + 2 files changed, 3 insertions(+) diff --git a/src/tests/typed.test.ts b/src/tests/typed.test.ts index fdc8d6ac..60cad096 100644 --- a/src/tests/typed.test.ts +++ b/src/tests/typed.test.ts @@ -360,6 +360,7 @@ describe('typed module', () => { assert.isTrue(_.isEmpty(0)) assert.isTrue(_.isEmpty(true)) assert.isTrue(_.isEmpty([])) + assert.isTrue(_.isEmpty(0n)) assert.isTrue(_.isEmpty(false)) assert.isTrue(_.isEmpty({})) assert.isTrue(_.isEmpty('')) @@ -371,6 +372,7 @@ describe('typed module', () => { assert.isFalse(_.isEmpty(new Date())) assert.isFalse(_.isEmpty(new Date('2022-09-01T02:19:55.976Z'))) assert.isFalse(_.isEmpty(22)) + assert.isFalse(_.isEmpty(1n)) assert.isFalse(_.isEmpty(new Person())) assert.isFalse(_.isEmpty({ name: 'x' })) assert.isFalse(_.isEmpty('abc')) diff --git a/src/typed.ts b/src/typed.ts index fc1c15fc..402fd788 100644 --- a/src/typed.ts +++ b/src/typed.ts @@ -72,6 +72,7 @@ export const isEmpty = (value: any) => { if (value === true || value === false) return true if (value === null || value === undefined) return true if (isNumber(value)) return value === 0 + if (isBigInt(value)) return value === 0n if (isDate(value)) return isNaN(value.getTime()) if (isFunction(value)) return false if (isSymbol(value)) return false