Skip to content

Boolean helper #254

Open
Open
@GammaGames

Description

@GammaGames

Pretty frequently I come across the problem of needing to check if an optional variable is true or false. The problem is that the server can send it as true, false, undefined, "true", or "false". I added this mixin (based on this SO answer):

_.mixin({
  isTrue: function(str) {
    return JSON.parse((str || "false").toLowerCase());
  }
});

Thoughts on adding this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions