ecrmnn / collect.js

💎  Convenient and dependency free wrapper for working with arrays and objects
https://collect.js.org
MIT License
6.54k stars 313 forks source link

collect("").isEmpty()) return false. #310

Closed Gauravms2143 closed 1 year ago

Gauravms2143 commented 1 year ago

In JavaScript, string "" is considered as empty string.

But collect("").isEmpty()) // return output as false.

link for code

(https://github.com/ecrmnn/collect.js/blob/master/src/methods/isEmpty.js)

jjjrmy commented 1 year ago

Your code example above is creating an array with one element of "", therefor when you check if it is empty - it is not.

I have confirmed the same thing is happening with the Laravel Collection, so this is expected. Your best bet would be to filter the collection for null values first.

const c = collect("");

c.count(); // 1
c.isEmpty(); // false
c.filter().isEmpty(); // true

// Returns:
Collection {
  items: [ '' ]
}

This issue should be closed