# qualify

> JavaScript library to help building functions with checks for specific conditions

Latest version **0.0.5** (published 2012-10-24) · MIT license · 0 weekly downloads

## Install

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

## 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.0.5 |
| Published | 2012-10-24 |
| First published | 2012-10-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Jaakko-Heikki Heusala |
| Maintainers | jhh |
| Keywords | javascript, function |

## Links

- npm: https://www.npmjs.com/package/qualify
- Repository: https://github.com/jheusala/qualify
- npm.io page: https://npm.io/package/qualify

## Dependencies (2)

- [snippets](https://npm.io/package/snippets.md) *
- [json-schema](https://npm.io/package/json-schema.md) *

## Recent versions

- 0.0.5 (latest) — 2012-10-24
- 0.0.4 — 2012-10-22
- 0.0.3 — 2012-10-19
- 0.0.2 — 2012-10-19
- 0.0.1 — 2012-10-19

## README

qualify
=======

JavaScript library to help building functions and methods with qualification 
checks for specific conditions.

License
-------

License is MIT.

Usage with Node.js
------------------

Install using NPM:

	npm install qualify

Use it in the application:

	var qualify = require('qualify');

Method `qualify.create`
-----------------------

`qualify.create` can be used to build functions and methods that validate their arguments and return values.

### Example

Create your functions like:

	var foo = qualify.create({
		type: 'async',
		defaults: 'right',
		max: 2, 
		validate: [{type:'string'}]
	}, function(path, fn) {
		fn("Path was " + path);
	});

### `type`

The type of the function's error handling. This is required if you use differend styles of error handling and want to use those styles to catch conform's errors too.

Possible values are: 

* `"basic"` is the default option. This is a standard function. Conform's errors are handled by throwing exceptions.
* `"async"` is a basic async function. Last argument must be a function which can be called with an argument as an optional error message.
* `"promise"` the function will return an async Promise object (CommonJS/PromiseA). [Not implemented yet.]

### `defaults`

The direction of fulfilling missing arguments. If set as `"right"` then all optional arguments are fulfilled from right to left. This is optional argument. Default is `"left"`.

### `max` and `min` or `length`

How many arguments the function must have. `length` will override `max` and `min` as the same value.

### `validate`

An array for each schema that will be used to specify how arguments are validated. Optional arguments should be set as `undefined`.

### `returns`

Validate the return value of the function in our schema format.

Notes about our schema validation
---------------------------------

The library uses [json-schema](https://github.com/kriszyp/json-schema) to validate JavaScript objects. As an exception `conform` also supports `{type:'function'}` with 
support for optional `required` field. (However at the moment it does not support functions outside top level.)

Other methods
-------------

### `qualify.isFunction(what)`

Returns `true` if `what` is a function. 

### `qualify.isObject(what)`

Returns `true` if `what` is an object. 

### `qualify.validate(what, schema)`

Is the same as `JSONSchema.validate()` except it has extended support for `{type:'function'}`. Returns an object in format `{valid:true|false, errors:[]}`.

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