I tried to use isEmpty() and received some illogical results. So a dig a little deeper and found some incorrect logic and tests.
Below is my code to just print to the console some common scenario using isEmpt():
import { isEmpty } from 'radash'
console.log(`\n🟠====== typed | isEmpty() ========`)
// console.log(`\n🔷 Comparing radash isEmpty() to fxts isEmpty()`)
console.log(`\n🔷 Number`)
console.log(`✅ isEmpty(1)`, isEmpty(1)) // false
console.log(`✅ isEmpty(0)`, isEmpty(0)) // false
console.log(`\n🔷 Boolean`)
console.log(`✅ isEmpty(false)`, isEmpty(false)) // false
console.log(`✅ isEmpty(true)`, isEmpty(true)) // false
console.log(`\n🔷 Date`)
console.log(`✅ isEmpty(new Date())`, isEmpty(new Date())) // false
console.log(`\n🔷 Null and Undefined`)
console.log(`✅ isEmpty(undefined)`, isEmpty(undefined)) // true
console.log(`✅ isEmpty(null)`, isEmpty(null)) // true
console.log(`\n🔷 Object`)
console.log(`✅ isEmpty({})`, isEmpty({})) // true
console.log(`✅ isEmpty({a:1})`, isEmpty({ a: 1 })) // false
console.log(`\n🔷 Array`)
console.log(`✅ isEmpty([])`, isEmpty([])) // true
console.log(`✅ isEmpty([1])`, isEmpty([1])) // false
console.log(`\n🔷 String/Char`)
console.log(`✅ isEmpty("")`, isEmpty('')) // true
console.log(`✅ isEmpty("a")`, isEmpty('a')) // false
console.log(`\n🔷 Function`)
console.log(
`✅ isEmpty(function(){})`,
isEmpty(function () {})
) // false
console.log(`\n🔷 Symbol`)
console.log(`✅ isEmpty(Symbol(""))`, isEmpty(Symbol(''))) // false
... and below is the result:
![image](https://user-images.githubusercontent.com/3227590/187710211-a234878b-0c39-4072-95d7-70aefaf08a6f.png)
As you can see, my expectations as indicated by the // comments in the console statements do differ from yours significantly.
I looked at your tests and it seems the test would suggest what I received. For instance, take your tests from your test suite for the first two console statements above:
test('returns true for number greater than 0', () => {
const input = 22
const result = _.isEmpty(input)
assert.isTrue(result)
})
test('returns true for number 0', () => {
const input = 0
const result = _.isEmpty(input)
assert.isTrue(result)
})
The logic is suggesting that both digits test return true. Is it an error?
Another example pertaining to arrays...
console.log(\n🔷 Array
)
console.log(✅ isEmpty([])
, isEmpty([])) // true
console.log(✅ isEmpty([1])
, isEmpty([1])) // false
🔷 Array
✅ isEmpty([]) true
✅ isEmpty([1]) true
const input = [1, 2, 3]
const result = _.isEmpty(input)
assert.isFalse(result)
})
test('returns true for empty array', () => {
const input = []
const result = _.isEmpty(input)
assert.isTrue(result)
})
Again the test for isEmpty(array) is not in keeping with what I am expecting or the test assertion - an array with no elements returns true and an array with elements returns false (as your test) and what I expect. But, as you see above true is being returned by both.
Cheers