if2
v0.2.0
Published
if2 A,B := if A then A else B
Downloads
3,709
Readme
if2
if2 A,B := if A then A else B
Table Of Contents
Links
Get Started
var if2 = require('if2');
if2(null, 1);
// RETURN 1
if2(true, 2);
// RETURN true
if2(null, undefined, false, 3);
// RETURN 3
if2(null, false, "");
// RETURN undefined
API
Basic
if2(...)
Return the first argument which is truthy。
Read Truthy and Falsy: When All is Not Equal in JavaScript for more.if2.satisfies( Function judger, ... )
Return the first remainder argument which satisfies the judger.
This method may be curried. If only one argument passed, it will return something like function satisfiesJudger.if2.is( Function proto, ... )
Return the first remainder argument which is an instance of proto.
This method may be curried. If only one argument passed, it will return something like function isInstanceOfProto.if2.assignIfHasnot( Object foo, string propertyName, ANY value )
Assign specified property of the object if it has not such property.
Predefined Methods
For convenience, some frequently-used judger is predfined. The usage of following methods is self-evident.
- if2.array(...)
- if2.boolean(...)
- if2.defined(...)
- if2.function(...)
- if2.number(...)
- if2.string(...)
Examples
if2 can be used with other type testing library such as is. E.g.
const if2 = require('if2');
const is = require('is');
if2.statisfies(is.even, 1, 3, 4);
// RETURN 4