$ cnpm install preconditions
Ensuring a fail fast development environment can help developers find bugs quicker and easier. Ensuring all invariants are true at an initial point of contact will help you ensure this fail fast environment. The Preconditions library will assist you in doing just that by immediately throwing an Error if any of your invariants fail. You can mix and match standard Guava API with convenience functions both with and without chaining.
Version 2 adds a new entry point on the interface, 'errr'. The errr interface decorates the errr node module and helps to solve some important issues with Node, listed below. See https://www.npmjs.com/package/errr. This version also updates the module to Node 5 paradigms.
npm install preconditions
There are four functions that are exposed from the library.
You can use a static instance to verify one value at a time while using the errr module to build an errr. For more on the errr module see here https://github.com/corybill/Preconditions#errrdecorator and here https://github.com/corybill/errr#errr.
var preconditions = require("preconditions").errr();
preconditions.shouldBeDefined(someObj.valueOne).test();
preconditions.shouldBeDefined(someObj.valueOne, "Custom error message.").test();
preconditions.shouldBeDefined(someObj.valueOne, "Error (%s:%s): Error Message.", [errType, errCode]).test();
preconditions.shouldBeDefined(someObj.valueOne, "Custom error message.").debug({param1: "someDebugParam"}).test();
preconditions.shouldBeDefined(someObj.valueOne, "Custom error message.").appendTo(someErrorObj).test();
preconditions.shouldBeDefined(someObj.valueTwo, "Error (%s:%s): Error Message.", [errType, errCode]);
.debug({param1: "someDebugParam"})
.appendTo(someErrorObj)
.test();
Best practice for achieving fail fast concept when function must return promise;
var preconditions = require("preconditions").errr();
new BlueBirdProm(function (resolve, reject {
// THIS WILL THROW AND BE CAUGHT AT THE NEXT LEVEL OF THE CHAIN
// NOTICE YOU DO NOT HAVE TO CALL REJECT BECAUSE WE ARE THROWING WITHIN A PROMISE.
preconditions.shouldBeDefined(someObj.valueTwo, "Error (%s:%s): Error Message.", [errType, errCode]);
.debug({param1: "someDebugParam"})
.set("reason", "Some Error").set("statusCode", 400)
.appendTo(someErrorObj)
.test(); // Can also short hand this call to .t();
return someAsynchFunc().then(function (result) {
resolve(result);
}).catch(function (err) {
reject(err);
});
});
You can use a static instance to verify one value at a time.
var preconditions = require("preconditions").singleton();
preconditions.shouldBeDefined(someObj.valueOne)
.shouldBeDefined(someObj.valueTwo, "Error (%s:%s): Error Message.", [errType, errCode]).test();
.shouldBeDefined(someObj.valueThree, "Custom error message.");
Should not be used in production code!
var preconditions = require("preconditions").instance(this);
preconditions.shouldBeDefined("foo.deep.stringValue", "Custom error message.")
.checkArguments("FOO" === "FOO");
Should not be used in production code!
The Preconditions object itself is exposed so that you can extend the Preconditions class.
let Constructor = preconditions.constructor();
let ChildClass = class extends Constructor {
constructor(out) {
super(out);
}
shouldBeFoo(value, message) {
let msg = message || defaultMessage;
if (value !== "FOO") {
throw new Error(msg);
}
}
};
new ChildClass(this).shouldBeDefined("foo.deep.stringValue", "Custom error message.")
.shouldBeFoo("foo.deep.foo");
Please reach out to me (Cory Parrish) if you would like a new precondition added or if you think you have found a bug.
###Known Issues
Validate values in a nested object using a dot notation structure (e.g. .shouldBeString("Person.Address.Street.zip")) System will validate the the Person, Person.Address, and Person.Address.Street objects exist, and will validate that zip is a String.
Use this interface if you want to utilize the following functionality:
Validate single value with a chainable interface. Use this interface if you want to utilize the following functionality:
Error Builder allows you to use optional functions to build an error object. The error can have appended stack traces and debug params to assist with debugging.
Validate single value with a buildable interface on top of the errr node module. Use this interface if you want to utilize the following functionality:
Preconditions entry point interface.
Validate values in a nested object using a dot notation structure (e.g. .shouldBeString("Person.Address.Street.zip")) System will validate the the Person, Person.Address, and Person.Address.Street objects exist, and will validate that zip is a String.
Use this interface if you want to utilize the following functionality:
Kind: global class
thisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthis| Param | Type | Description |
|---|---|---|
| objectUnderTest | Object |
Object to run validations against. |
thisThrows an error if any value does not exist in the objectToTest, from configPath. Throws an error if the last key from configPath is defined.
Kind: instance method of InstanceValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| configPath | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
thisThrows an error if any value does not exist in the objectToTest, from configPath. Throws an error if the last key from configPath is not defined.
Kind: instance method of InstanceValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| configPath | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
thisThrows an error if any value does not exist in the objectToTest, from configPath. Throws an error if the last key from configPath is not an array or is an empty array.
Kind: instance method of InstanceValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| configPath | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
thisThrows an error if any value does not exist in the objectToTest, from configPath. Throws an error if the last key from configPath is an array.
Kind: instance method of InstanceValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| configPath | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
thisThrows an error if any value does not exist in the objectToTest, from configPath. Throws an error if the last key from configPath is not an array.
Kind: instance method of InstanceValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| configPath | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
thisThrows an error if any value does not exist in the objectToTest, from configPath. Throws an error if the last key from configPath is of type Object.
Kind: instance method of InstanceValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| configPath | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
thisThrows an error if any value does not exist in the objectToTest, from configPath. Throws an error if the last key from configPath is not of type Object.
Kind: instance method of InstanceValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| configPath | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
thisThrows an error if any value does not exist in the objectToTest, from configPath. Throws an error if the last key from configPath is not empty.
Kind: instance method of InstanceValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| configPath | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
thisThrows an error if any value does not exist in the objectToTest, from configPath. Throws an error if the last key from configPath is empty.
Kind: instance method of InstanceValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| configPath | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
thisThrows an error if any value does not exist in the objectToTest, from configPath. Throws an error if the last key from configPath is not of type Function.
Kind: instance method of InstanceValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| configPath | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
thisThrows an error if any value does not exist in the objectToTest, from configPath. Throws an error if the last key from configPath is of type Function.
Kind: instance method of InstanceValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| configPath | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
thisThrows an error if any value does not exist in the objectToTest, from configPath. Throws an error if the last key from configPath is not of type String.
Kind: instance method of InstanceValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| configPath | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
thisThrows an error if any value does not exist in the objectToTest, from configPath. Throws an error if the last key from configPath is of type String.
Kind: instance method of InstanceValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| configPath | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
thisThrows an error if any value does not exist in the objectToTest, from configPath. Throws an error if the last key from configPath is not of type Number.
Kind: instance method of InstanceValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| configPath | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
thisThrows an error if any value does not exist in the objectToTest, from configPath. Throws an error if the last key from configPath is of type Number.
Kind: instance method of InstanceValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| configPath | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
thisThrows an error if any value does not exist in the objectToTest, from configPath. Throws an error if the last key from configPath is not finite.
Kind: instance method of InstanceValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| configPath | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
thisThrows an error if any value does not exist in the objectToTest, from configPath. Throws an error if the last key from configPath is not infinte.
Kind: instance method of InstanceValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| configPath | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
thisThrows an error if any value does not exist in the objectToTest, from configPath. Throws an error if the last key from configPath is not of type Boolean.
Kind: instance method of InstanceValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| configPath | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
thisThrows an error if any value does not exist in the objectToTest, from configPath. Throws an error if the last key from configPath is of type Boolean.
Kind: instance method of InstanceValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| configPath | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
thisThrows an error if any value does not exist in the objectToTest, from configPath. Throws an error if the last key from configPath is not of type Date.
Kind: instance method of InstanceValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| configPath | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
thisThrows an error if any value does not exist in the objectToTest, from configPath. Throws an error if the last key from configPath is of type Date.
Kind: instance method of InstanceValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| configPath | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
thisThrows an error if any value does not exist in the objectToTest, from configPath. Throws an error if the last key from configPath is not a Regular Expression.
Kind: instance method of InstanceValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| configPath | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
thisThrows an error if any value does not exist in the objectToTest, from configPath. Throws an error if the last key from configPath is a Regular Expression.
Kind: instance method of InstanceValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| configPath | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
thisThrows an error if any value does not exist in the objectToTest, from configPath. Throws an error if the last key from configPath is not falsey.
Kind: instance method of InstanceValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| configPath | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
thisThrows an error if any value does not exist in the objectToTest, from configPath. Throws an error if the last key from configPath is falsey.
Kind: instance method of InstanceValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| configPath | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
thisSynonym for shouldBeFalsey.
Kind: instance method of InstanceValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| configPath | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
thisSynonym for shouldNotBeFalsey.
Kind: instance method of InstanceValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| configPath | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
thisSynonym for shouldNotBeFalsey.
Kind: instance method of InstanceValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| configPath | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
thisSynonym for shouldBeFalsey.
Kind: instance method of InstanceValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| configPath | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
thisEnsures the truth of an expression involving one or more parameters to the calling method.
Kind: instance method of InstanceValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| expression | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
| [template] | Array |
Template params. If provided, the error message will be generated using util.format(message, template). |
thisEnsures the truth of an expression involving the state of the calling InstanceValidator, but not involving any parameters to the calling method.
Kind: instance method of InstanceValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| expression | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
thisEnsures that index specifies a valid element in an array, list or string of size size.
Kind: instance method of InstanceValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| index | Number |
|
| size | Number |
|
| [message] | String |
The error message or the error template string to use if the validation fails. |
thisEnsures that index specifies a valid position in an array, list or string of size size.
Kind: instance method of InstanceValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| index | Number |
|
| size | Number |
|
| [message] | String |
The error message or the error template string to use if the validation fails. |
thisEnsures that start and end specify a valid positions in an array, list or string of size size, and are in order.
Kind: instance method of InstanceValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| start | Number |
|
| end | Number |
|
| size | Number |
|
| [message] | String |
The error message or the error template string to use if the validation fails. |
Validate single value with a chainable interface. Use this interface if you want to utilize the following functionality:
Kind: global class
thisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisthisThrows an error if 'val' is not defined.
Kind: static method of SingletonValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| val | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
| [template] | Array |
Template params. If provided, the error message will be generated using util.format(message, template). |
thisThrows an error if 'val' is defined.
Kind: static method of SingletonValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| val | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
| [template] | Array |
Template params. If provided, the error message will be generated using util.format(message, template). |
thisThrows an error if 'val' is not of type Array.
Kind: static method of SingletonValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| val | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
| [template] | Array |
Template params. If provided, the error message will be generated using util.format(message, template). |
thisThrows an error if 'val' is of type Array.
Kind: static method of SingletonValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| val | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
| [template] | Array |
Template params. If provided, the error message will be generated using util.format(message, template). |
thisThrows an error if 'val' is not of type Object.
Kind: static method of SingletonValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| val | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
| [template] | Array |
Template params. If provided, the error message will be generated using util.format(message, template). |
thisThrows an error if 'val' is of type Object.
Kind: static method of SingletonValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| val | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
| [template] | Array |
Template params. If provided, the error message will be generated using util.format(message, template). |
thisThrows an error if 'val' is not empty.
Kind: static method of SingletonValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| val | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
| [template] | Array |
Template params. If provided, the error message will be generated using util.format(message, template). |
thisThrows an error if 'val' is empty.
Kind: static method of SingletonValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| val | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
| [template] | Array |
Template params. If provided, the error message will be generated using util.format(message, template). |
thisThrows an error if 'val' is not of type Function.
Kind: static method of SingletonValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| val | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
| [template] | Array |
Template params. If provided, the error message will be generated using util.format(message, template). |
thisThrows an error if 'val' is of type Function.
Kind: static method of SingletonValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| val | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
| [template] | Array |
Template params. If provided, the error message will be generated using util.format(message, template). |
thisThrows an error if 'val' is not of type String.
Kind: static method of SingletonValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| val | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
| [template] | Array |
Template params. If provided, the error message will be generated using util.format(message, template). |
thisThrows an error if 'val' is of type String.
Kind: static method of SingletonValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| val | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
| [template] | Array |
Template params. If provided, the error message will be generated using util.format(message, template). |
thisThrows an error if 'val' is not of type Number.
Kind: static method of SingletonValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| val | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
| [template] | Array |
Template params. If provided, the error message will be generated using util.format(message, template). |
thisThrows an error if 'val' is of type Number.
Kind: static method of SingletonValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| val | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
| [template] | Array |
Template params. If provided, the error message will be generated using util.format(message, template). |
thisThrows an error if 'val' is not finite.
Kind: static method of SingletonValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| val | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
| [template] | Array |
Template params. If provided, the error message will be generated using util.format(message, template). |
thisThrows an error if 'val' is not infinite.
Kind: static method of SingletonValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| val | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
| [template] | Array |
Template params. If provided, the error message will be generated using util.format(message, template). |
thisThrows an error if 'val' is not of type Boolean.
Kind: static method of SingletonValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| val | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
| [template] | Array |
Template params. If provided, the error message will be generated using util.format(message, template). |
thisThrows an error if 'val' is of type Boolean.
Kind: static method of SingletonValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| val | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
| [template] | Array |
Template params. If provided, the error message will be generated using util.format(message, template). |
thisThrows an error if 'val' is not of type Date.
Kind: static method of SingletonValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| val | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
| [template] | Array |
Template params. If provided, the error message will be generated using util.format(message, template). |
thisThrows an error if 'val' is of type Date.
Kind: static method of SingletonValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| val | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
| [template] | Array |
Template params. If provided, the error message will be generated using util.format(message, template). |
thisThrows an error if 'val' is not a Regular Expression.
Kind: static method of SingletonValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| val | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
| [template] | Array |
Template params. If provided, the error message will be generated using util.format(message, template). |
thisThrows an error if 'val' is a Regular Expression.
Kind: static method of SingletonValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| val | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
| [template] | Array |
Template params. If provided, the error message will be generated using util.format(message, template). |
thisThrows an error if 'val' is not falsey.
Kind: static method of SingletonValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| val | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
| [template] | Array |
Template params. If provided, the error message will be generated using util.format(message, template). |
thisThrows an error if 'val' is falsey.
Kind: static method of SingletonValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| val | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
| [template] | Array |
Template params. If provided, the error message will be generated using util.format(message, template). |
thisSynonym for shouldBeFalsey.
Kind: static method of SingletonValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| val | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
| [template] | Array |
Template params. If provided, the error message will be generated using util.format(message, template). |
thisSynonym for shouldNotBeFalsey.
Kind: static method of SingletonValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| val | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
| [template] | Array |
Template params. If provided, the error message will be generated using util.format(message, template). |
thisSynonym for shouldNotBeFalsey.
Kind: static method of SingletonValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| val | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
| [template] | Array |
Template params. If provided, the error message will be generated using util.format(message, template). |
thisSynonym for shouldBeFalsey.
Kind: static method of SingletonValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| val | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
| [template] | Array |
Template params. If provided, the error message will be generated using util.format(message, template). |
thisEnsures the truth of an expression involving one or more parameters to the calling method.
Kind: static method of SingletonValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| expression | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
| [template] | Array |
Template params. If provided, the error message will be generated using util.format(message, template). |
thisEnsures the truth of an expression involving the state of the calling instance, but not involving any parameters to the calling method.
Kind: static method of SingletonValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| expression | String |
The value to validate. |
| [message] | String |
The error message or the error template string to use if the validation fails. |
| [template] | Array |
Template params. If provided, the error message will be generated using util.format(message, template). |
thisEnsures that index specifies a valid element in an array, list or string of size size.
Kind: static method of SingletonValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| index | Number |
|
| size | Number |
|
| [message] | String |
The error message or the error template string to use if the validation fails. |
| [template] | Array |
Template params. If provided, the error message will be generated using util.format(message, template). |
thisEnsures that index specifies a valid position in an array, list or string of size size.
Kind: static method of SingletonValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| index | Number |
|
| size | Number |
|
| [message] | String |
The error message or the error template string to use if the validation fails. |
| [template] | Array |
Template params. If provided, the error message will be generated using util.format(message, template). |
thisEnsures that start and end specify a valid positions in an array, list or string of size size, and are in order.
Kind: static method of SingletonValidator
Returns: this - - Returns itself to allow chainable validations.
| Param | Type | Description |
|---|---|---|
| start | Number |
|
| end | Number |
|
| size | Number |
|
| [message] | String |
The error message or the error template string to use if the validation fails. |
| [template] | Array |
Template params. If provided, the error message will be generated using util.format(message, template). |
Error Builder allows you to use optional functions to build an error object. The error can have appended stack traces and debug params to assist with debugging.
Kind: global class
Provides an interface to build an error. Then allows you to get or throw the error.
| Param |
Copyright 2013 - present © cnpmjs.org | Home |