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