# bycontract-plus

> Extensions to byconvention library

Latest version **1.1.4** (published 2022-03-19) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install bycontract-plus
pnpm add bycontract-plus
yarn add bycontract-plus
bun add bycontract-plus
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.1.4 |
| Published | 2022-03-19 |
| First published | 2022-03-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 9.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Blaine Simpson |
| Maintainers | unsaved |
| Keywords | validation, parameter validation, byextension |

## Links

- npm: https://www.npmjs.com/package/bycontract-plus
- Repository: https://github.com/unsaved/bycontract-plus
- Issues: https://github.com/unsaved/bycontract-plus/issues
- npm.io page: https://npm.io/package/bycontract-plus

## Dependencies (2)

- [util](https://npm.io/package/util.md) ^0.12.4
- [bycontract](https://npm.io/package/bycontract.md) ^2.0.11

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.1.4 (latest) — 2022-03-19
- 1.1.3 — 2022-03-17
- 1.1.2 — 2022-03-13
- 1.1.1 — 2022-03-13
- 1.1.0 — 2022-03-13
- 1.0.2 — 2022-03-10
- 1.0.1 — 2022-03-10
- 1.0.0 — 2022-03-06

## README

# Description
node.js module for validating (primarily) function parameters.

This module provides a map that's the same as that provided by Dmitry Sheiko's
'bycontract' module, with the feature extensions described below.
I tried contracting Dmitry to get his direction on the best way to extend his
module, but he hasn't replied to me.  Not knowing if I will have to repeat
this extension work, I went with strategy that I can do most quickly and easily 
(but not necessarily best long-term)-- just make this new project that loads
the bycontract module and adds to it.

# Usage
Users will usually want to require/import the 'validate' and 'is' objects.
The first for performing validations, and the second to add custom
validator functions.

## Enhancements
1. The original 'validate' function requires 2 and only 2 parameters.
I support some optional extra params.
1. For validate calls where contract parameter (2nd) is an Array, I enforce
that the number of value elements doesn't exceed that of the specified
contract.
1. Test element count enforcement (previous item) is not done if 3rd parameter
to validate call given as fase.
1. If the first non-boolean validate parameter after #2 is a string, then
it is a message to be used in validation Errors, overriding the default.
1. The message for previous feature can use util.format % placeholders, with
format varargs parameters being all remaining parameters.

I added the following validator functions, whose purposes should be obvious
from the names.
* int
* date
* posint
* nonnegint
* posnum
* isotimestr
* plainobject

See file "readme.txt" for planned future enhancements.

Usage is same as for [bycontract](https://www.npmjs.com/package/bycontract) other than...
```javascript
const { validate, is } = require("bcontract-plus");

// Allow more than two arguments elements:
validate(arguments, ["string", "int"], false);

// In case of validation failure, use the specified Error message.
validate(var, "string", "%ith element in issue list not a string", i);

// In particular, the run "[]" no longer means "any" Array, it means
// precisely [], a 0-length array.
// To get the original bycontract behavior to test for any Array, use:
validate(var, "", false);
validate(arguments, [""], false);
```

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