cert-is
Provides a collection of assertion tools for checking strict equality, type, and range of a set of values.
This project aims to simplify runtime value checking for safety-critical applications.
Migration Notice 0.2.1 --> 1.0.0:
- Certifier.isRange and Checker.isRange have been removed.
- Exports are now structured as follows:
export declare function cert(...values: any): Certifier
export declare function check(...values: any): Checker
export {
Certifier,
Checker,
RangeArgumentError,
RangeAssertionError,
TypeArgumentError,
TypeAssertionError,
ValueArgumentError,
ValueAssertionError
};
export default cert;
- Project has been converted to TypeScript
Update 1.0.0:
- This library has been converted to TypeScript, but development will likely stop here.
- Please check out jpcx/restrict-v instead.
Installation
yarn add cert-is
Testing
cd /path/to/node_modules/cert-is
yarn install -dev
yarn test
Contribution
Please raise an issue if you find any. Pull requests are welcome!
Documentation
Module: cert-is
Index
Classes
Type aliases
Functions
Type aliases
AnyConstructorFunction
Ƭ AnyConstructorFunction: object
Defined in src/certifier.ts:16
Any function that uses new to construct an object.
Type declaration:
Functions
cert
▸ cert(...values
: any): Certifier
Defined in src/index.ts:59
Constructs a Certifier instance given a set of values. All values must pass
the supplied tests.
func
cert
example
const certifier = cert('foo', 'bar')
certifier.is('foo')
certifier.is('bar')
certifier.is('qux')
example
cert('foo').is('foo')
cert('foo').is('bar')
cert('foo').is('foo', 'bar')
cert('foo').isNot('foo')
cert('foo').isType('string')
cert('foo').isType('number')
cert('foo').isType('string', 'number')
cert(new Map()).isType(Map)
cert(new Map()).isType(Object)
cert(new Map()).isType(Set)
cert(new Map()).isType(Map, Set)
cert(15).isGT(2)
cert(15).isGT(2).isLT(17)
cert(18).isGT(17).isLT(2)
cert(15).isGT(15)
cert(15).isGTE(15)
cert(15, 23).isGTE(15)
cert(15, 23).isGTE('foo')
Parameters:
Name | Type | Description |
---|
...values | any | Values to construct Certifier with. |
Returns: Certifier
Certifier instance.
check
▸ check(...values
: any): Checker
Defined in src/index.ts:80
Constructs a Checker instance given a set of values. All values must pass
the supplied tests.
func
check
example
check('foo').is('foo')
check('foo').is('bar')
check('foo').isType('string')
check('foo').isType('bar')
check('foo').isGT('')
Parameters:
Name | Type | Description |
---|
...values | any | Values to construct Checker with. |
Returns: Checker
Checker instance.
License
This project is licensed under the MIT License - see the LICENSE file for details