# type-func

> Type functions

Latest version **1.0.3** (published 2016-11-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install type-func
pnpm add type-func
yarn add type-func
bun add type-func
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2016-11-17 |
| First published | 2016-11-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Quentin Engles |
| Maintainers | hollowdoor |

## Links

- npm: https://www.npmjs.com/package/type-func
- npm.io page: https://npm.io/package/type-func

## Recent versions

- 1.0.3 (latest) — 2016-11-17
- 1.0.2 — 2016-11-17
- 1.0.1 — 2016-11-02
- 1.0.0 — 2016-11-02

## README

Install
-------

`npm install --save type-func`

About
-----


This is a collection of functions that return functions that return certain types of values.

The signature is:

```javascript
typeFunc(func|value, default|undefined)
```

`typeFunc` is one of these types.

-	`boolean(func|boolean, default|undefined) -> fn(...args)`
-	`integer(func|integer, default|undefined) -> fn(...args)`
-	`string(func|string, default|undefined) -> fn(...args)`

The `fn` function returned by one of the above type functions returns the value of that type.

Example:

```javascript
import { boolean } from 'type-func';
let bool1 = boolean(true);

let bool2 = boolean(()=>false);

```

The variables bool1, and bool2 in the above example are functions that return a boolean.

All returned types are converted from the input to the respective type.

Example:

```javascript
import { boolean } from 'type-func';
let zero1 = boolean(0);
console.log(zero1());// prints false
let zero2 = boolean(()=>0);
console.log(zero2());// also prints false
```

When `undefined` is passed a default value is used. If there is no default value set then `undefined` will be converted as needed.

```javascript
import { boolean } from 'type-func';

let defaultToFalse = boolean(undefined, false)
console.log(defaultToFalse());// prints false
let undef = boolean(undefined);
console.log(undef()); // prints false
```

What's this good for?
---------------------

Default options. Examples:

```javascript
import { boolean } from 'type-func';

function myClass(options){
    this.opt = boolean(options.opt, false);
}
```

```javascript
import { boolean } from 'type-func';

function myClass({opt: opt} = {opt: false}){
    this.opt = boolean(options.opt);
}
```

```javascript
import { boolean } from 'type-func';

function myClass(opt = boolean(true)){
    this.opt = boolean(opt);
}
```

About
-----

Just some helper functions that return consistent types.

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