# if2

> if2 A,B := if A then A else B

Latest version **0.2.0** (published 2018-01-07) · ISC license · 0 weekly downloads

## Install

```sh
npm install if2
pnpm add if2
yarn add if2
bun add if2
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2018-01-07 |
| First published | 2017-07-20 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | youngoat@163.com |
| Maintainers | youngoat.elite, youngoat |
| Keywords | if, type-satisfy |

## Links

- npm: https://www.npmjs.com/package/if2
- Repository: https://github.com/YounGoat/ecmascript.if2
- Homepage: https://github.com/YounGoat/ecmascript.if2#readme
- Issues: https://github.com/YounGoat/ecmascript.if2/issues
- npm.io page: https://npm.io/package/if2

## Alternatives

- [update-check](https://npm.io/package/update-check.md) — 4.0M weekly downloads
- [react-native-onesignal](https://npm.io/package/react-native-onesignal.md) — 134.5K weekly downloads
- [react-redux-toastr](https://npm.io/package/react-redux-toastr.md) — 33.7K weekly downloads
- [@nocobase/plugin-notification-manager](https://npm.io/package/@nocobase/plugin-notification-manager.md) — 2.0K weekly downloads
- [react-simple-toasts](https://npm.io/package/react-simple-toasts.md) — 1.9K weekly downloads

## Recent versions

- 0.2.0 (latest) — 2018-01-07
- 0.1.2 — 2017-07-20

## README

#   if2
__if2 A,B := if A then A else B__

##	Table Of Contents

*	[Get Started](#get-started)
*	[API](#api)
*	[Examples](#examples)

##	Links

[CHANGE LOG](./CHANGELOG.md)
[Homepage](https://github.com/YounGoat/ecmascript.if2)

##  Get Started

```js   
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](https://developer.mozilla.org/en-US/docs/Glossary/Truthy) 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](https://www.npmjs.com/package/is). E.g.

```javascript
const if2 = require('if2');
const is = require('is');

if2.statisfies(is.even, 1, 3, 4);
// RETURN 4
```

---
_Source: https://npm.io/package/if2 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
