Closed junhaoyap closed 8 years ago
I did a search on the workspace, apparently this method is stolen from typeahead.bundle.min.js
. :stuck_out_tongue:
Any benefit of regex check over the simpler comparison?
Referring to this doc, this is how trim
is defined:
return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
So trim
itself is using regex, but the implementation is hidden from us (which can be a good or a bad thing).
str.trim() === ""
does look simpler, though.
OK then, we'll go for the simpler one.
I just tried something. The regex method can handle things like:
isBlank(0) // true
isBlank(123) // false
isBlank(true) // false
Whereas the trim method will throw errors on the above three cases. Proper usage of the method won't require us to handle those cases, but in JS where variables are untyped, we may need some sort of protection against such misuses. Should we keep the regex method?
@wkurniawan07 Do you think it's a good idea that we also test if the given input is a String? If it is not a String then let the method return false. In that way we could prevent misuses, and the trim() method could be used as well :P
Oops sorry I somehow missed this! @Gisonrg yeah sure, that's one way to deal with it. You wanna work on it? Btw, if you haven't done one d.FirstTimers
issue before, you should do one of those first.
@wkurniawan07 Yea sure I can work on this one
I will do one d.FirstTimers
on weekend. Quite busy this week :smile:
Suit yourself bro :+1: Just submit PRs when you're done. Remember to follow the workflow as specified here.
Regex can be slow, not everyone understands regex (I don't, yet) and the check can be as simple as
str.trim() === "", we don't need to add an extra layer of function to do that particular check