Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf5e6375

Browse files
committed
fix isEmpty bug with bigInt
1 parent90aa135 commitf5e6375

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

‎src/danfojs-base/shared/utils.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,25 @@ export default class Utils {
8686
}
8787

8888
/**
89-
* Checks if a value is empty. Empty means it's either null, undefined or NaN
89+
* Checks if a value is empty. Empty means it's either null, undefined or NaN.
90+
* Empty strings are NOT considered empty.
9091
*@param value The value to check.
91-
*@returns
92+
*@returnsboolean indicating if the value is empty
9293
*/
9394
isEmpty<T>(value:T):boolean{
94-
returnvalue===undefined||value===null||(isNaN(valueasany)&&typeofvalue!=="string");
95+
if(value===undefined||value===null){
96+
returntrue;
97+
}
98+
99+
if(typeofvalue==='bigint'){
100+
returnfalse;// BigInt values are never considered empty
101+
}
102+
103+
if(typeofvalue==='number'){
104+
returnisNaN(value);
105+
}
106+
107+
returnfalse;// All other types (strings, objects, arrays, etc) are not considered empty
95108
}
96109

97110
/**

‎src/danfojs-node/test/utils.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,49 @@ describe("Utils", function () {
4040
assert.isTrue(utils.isUndefined(arr));
4141
});
4242

43+
describe("isEmpty",function(){
44+
it("should return true for null values",function(){
45+
assert.isTrue(utils.isEmpty(null));
46+
});
47+
48+
it("should return true for undefined values",function(){
49+
assert.isTrue(utils.isEmpty(undefined));
50+
});
51+
52+
it("should return true for NaN values",function(){
53+
assert.isTrue(utils.isEmpty(NaN));
54+
});
55+
56+
it("should return false for strings (including empty strings)",function(){
57+
assert.isFalse(utils.isEmpty(""));
58+
assert.isFalse(utils.isEmpty(" "));
59+
assert.isFalse(utils.isEmpty("hello"));
60+
});
61+
62+
it("should return false for numbers (except NaN)",function(){
63+
assert.isFalse(utils.isEmpty(0));
64+
assert.isFalse(utils.isEmpty(-1));
65+
assert.isFalse(utils.isEmpty(42.5));
66+
});
67+
68+
it("should return false for BigInt values",function(){
69+
assert.isFalse(utils.isEmpty(BigInt(9007199254740991)));
70+
assert.isFalse(utils.isEmpty(BigInt(0)));
71+
});
72+
73+
it("should return false for objects and arrays",function(){
74+
assert.isFalse(utils.isEmpty({}));
75+
assert.isFalse(utils.isEmpty([]));
76+
assert.isFalse(utils.isEmpty({key:"value"}));
77+
assert.isFalse(utils.isEmpty([1,2,3]));
78+
});
79+
80+
it("should return false for boolean values",function(){
81+
assert.isFalse(utils.isEmpty(true));
82+
assert.isFalse(utils.isEmpty(false));
83+
});
84+
});
85+
4386
it("Checks if value is a valid Date object",function(){
4487
letdate1=newDate();
4588
letdate2="2021-01-01 00:00:00";

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp