# @pakal/assertify

> Assertify is package from Pakal library

Latest version **0.2.1** (published 2019-04-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install @pakal/assertify
pnpm add @pakal/assertify
yarn add @pakal/assertify
bun add @pakal/assertify
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2019-04-15 |
| First published | 2018-07-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 44.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Yisrael Eliev |
| Maintainers | yisraelx |
| Keywords | utils, utilities, modules, modular |

## Links

- npm: https://www.npmjs.com/package/@pakal/assertify
- Repository: https://github.com/yisraelx/pakal
- Homepage: https://github.com/yisraelx/pakal#readme
- Issues: https://github.com/yisraelx/pakal/issues
- npm.io page: https://npm.io/package/@pakal/assertify

## Dependencies (2)

- [@pakal/arity](https://npm.io/package/@pakal/arity.md) ^0.2.1
- [@pakal/type-of](https://npm.io/package/@pakal/type-of.md) ^0.2.1

## Recent versions

- 0.2.1 (latest) — 2019-04-15
- 0.2.0 — 2019-03-31
- 0.1.1 — 2018-07-14
- 0.1.0 — 2018-07-03

## README

# @pakal/assertify
[![Source Code](https://img.shields.io/badge/%3C%2F%3E-source_code-blue.svg)](https://github.com/yisraelx/pakal/blob/master/modules/assertify)
[![Version](https://img.shields.io/npm/v/@pakal/assertify.svg)](https://www.npmjs.com/package/@pakal/assertify)
[![MIT License](https://img.shields.io/npm/l/@pakal/assertify.svg?color=yellow)](https://github.com/yisraelx/pakal/blob/master/LICENSE)
[![Bundle Size](https://img.shields.io/bundlephobia/min/@pakal/assertify.svg?color=green)](https://bundlephobia.com/result?p=@pakal/assertify)
[![TypeScript](https://img.shields.io/badge/100%25-TypeScript-blue.svg)](https://www.typescriptlang.org)

**Assertify is package from Pakal library**

## Install
```sh
$ yarn add @pakal/assertify
```
Or
```sh
$ npm install --save @pakal/assertify
```

## Use
**Module**
```typescript
import {
  default as assertify
} from '@pakal/assertify';
```

**Browser**
```html
<script src="https://unpkg.com/@pakal/assertify/bundle.umd.min.js"></script>
```
```typescript
let {
  assertify
} = _;
```

**Examples**
```typescript
 let isFoo = (value: string) => value === 'bar';

 let assertFoo = assertify(isFoo, 'The value is not foo');

 assertFoo('bar'); // => 'bar'
 assertFoo('some'); // throw Error('The value is not foo')
```
```typescript
 let isEquals = (value: any, other: any) => value === other;

 let assertEquals = assertify(isEquals, (value: any, other: any) => {
     return `${value} !== ${other}`;
 }, false);

 assertEquals(true, true); // => void
 assertEquals(0, 2); // throw Error('0 !== 2')
```
```typescript
 let isString = (value: any) => typeof value === 'string';
 let assertString = assertify(isString, (value) => TypeError(`type of '${value}' is not string.`), 0);

 assertString('some'); // => 'some'
 assertString(true); // throw TypeError(`type of 'true' is not string`)
```
```typescript
 let contains = (items: any[], value: any) => items.indexOf(value) > -1;
 let assertContains = assertify(contains, (items, value) => ({message: (`'${value}' not in ['${items.join(', ')}']`}), contains), 1);


 assertContains(['red', 'black', 'green'], 'black'); // => 'black'
 assertContains(['tea', 'beer'], 'coffee'); // throw {message: `'coffee' not in ['tea', 'beer']`}
```


## License
Copyright © [Yisrael Eliev](https://github.com/yisraelx),
Licensed under the [MIT license](https://github.com/yisraelx/pakal/blob/master/LICENSE).

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