Assertions

APIAssertions

Access it with:

const { assert } = Neft;

Source

assert(expression, message)

Parameters:
  • expression — Boolean
  • message — Stringoptional

Throws AssertionError if the given expression is falsy.

Source

**Class assert.AssertionError**()

Access it with:

const { AssertionError } = Neft.assert;

Source

assert.scope(message)

Parameters:
  • message — String
Returns:
assert

Returns new assert namespace where all failues are prefixed by the given message.

Source

assert.ok(expression, message)

Parameters:
  • expression — Boolean
  • message — Stringoptional

Link to the main assert function.

Throws an error if the given expression is falsy.

Source

assert.notOk(expression, message)

Parameters:
  • expression — Boolean
  • message — Stringoptional

Throws an error if the given expression is truthy.

Source

assert.is(actual, expected, message)

Parameters:
  • actual — Any
  • expected — Any
  • message — Stringoptional

Throws an error if the given actual is not the same as expected.

Strict comparison operator is used in this operation (===). Types needs to be the same. Read more about [comparison operators in JavaScript](https://developer.mozilla.org/en-US/docs /Web/JavaScript/Reference/Operators/Comparison_Operators).

Source

assert.isNot(actual, expected, message)

Parameters:
  • actual — Any
  • expected — Any
  • message — Stringoptional

Throws an error if the given actual is the same as expected.

Strict comparison operator is used in this operation (===).

Source

assert.isDefined(value, message)

Parameters:
  • value — Any
  • message — Stringoptional

Throws an error if the given value is null or undefined.

Source

assert.isNotDefined(value, message)

Parameters:
  • value — Any
  • message — Stringoptional

Throws an error if the given value is not null or undefined.

Source

assert.isPrimitive(value, message)

Parameters:
  • value — Any
  • message — Stringoptional

Throws an error if the given value is not a primitive value.

Primitive value must be null, string, number, boolean or undefined.

Source

assert.isNotPrimitive(value, message)

Parameters:
  • value — Any
  • message — Stringoptional

Throws an error if the given value if a primitive value.

Primitive value must be null, string, number, boolean or undefined.

Source

assert.isString(value, message)

Parameters:
  • value — String
  • message — Stringoptional

Throws an error if the given value is not a string.

Source

assert.isNotString(value, message)

Parameters:
  • value — Any
  • message — Stringoptional

Throws an error if the given value is a string.

Source

assert.isFloat(value, message)

Parameters:
  • value — Float
  • message — Stringoptional

Throws an error if the given value is not a float number.

Float number needs to be finite and may be an integer.

Source

assert.isNotFloat(value, message)

Parameters:
  • value — Any
  • message — Stringoptional

Throws an error if the given value is a float number.

Float number needs to be finite and may be an integer.

Source

assert.isInteger(value, message)

Parameters:
  • value — Integer
  • message — Stringoptional

Throws an error if the given value is not an integer.

Source

assert.isNotInteger(value, message)

Parameters:
  • value — Any
  • message — Stringoptional

Throws an error if the given value is an integer.

Source

assert.isBoolean(value, message)

Parameters:
  • value — Boolean
  • message — Stringoptional

Throws an error if the given value is not a boolean.

Source

assert.isNotBoolean(value, message)

Parameters:
  • value — Any
  • message — Stringoptional

Throws an error if the given value is a boolean.

Source

assert.isFunction(value, message)

Parameters:
  • value — Function
  • message — Stringoptional

Throws an error if the given value is not a function.

Source

assert.isNotFunction(value, message)

Parameters:
  • value — Any
  • message — Stringoptional

Throws an error if the given value is a function.

Source

assert.isObject(value, message)

Parameters:
  • value — Object
  • message — Stringoptional

Throws an error if the given value is not an object.

Arrays are objects.

null is not an object.

Source

assert.isNotObject(value, message)

Parameters:
  • value — Any
  • message — Stringoptional

Throws an error if the given value is an object.

Arrays are objects.

null is not an object.

Source

assert.isPlainObject(value, message)

Parameters:
  • value — PlainObject
  • message — Stringoptional

Throws an error if the given value is not a plain object.

Plain object in an object with no prototype or direct standard Object prototype.

Arrays and instances of classes are not plain objects.

Source

assert.isNotPlainObject(value, message)

Parameters:
  • value — Any
  • message — Stringoptional

Throws an error if the given value is a plain object.

Plain object in an object with no prototype or direct standard Object prototype.

Arrays and instances of classes are not plain objects.

Source

assert.isArray(value, message)

Parameters:
  • value — Array
  • message — Stringoptional

Throws an error if the given value is not an array.

Typed arrays are not arrays.

Source

assert.isNotArray(value, message)

Parameters:
  • value — Any
  • message — Stringoptional

Throws an error if the given value is an array.

Source

assert.isEqual(value1, value2, message, options)

Parameters:
  • value1 — Any
  • value2 — Any
  • message — Stringoptional
  • options — Objectoptional

Throws an error if the given values are not equal.

Objects and arrays are tested recursively.

Maximum deepness may be specified by options.maxDeep. Default value is Infinity.

Source

assert.isNotEqual(value1, value2, message, options)

Parameters:
  • value1 — Any
  • value2 — Any
  • message — Stringoptional
  • options — Objectoptional

Throws an error if the given values are equal.

Source

assert.instanceOf(object, constructor, message)

Parameters:
  • object — Object
  • constructor — Function
  • message — Stringoptional

Throws an error if the given object is not an instance of the given constructor.

Source

assert.notInstanceOf(object, constructor, message)

Parameters:
  • object — Any
  • constructor — Function
  • message — Stringoptional

Throws an error if the given object is an instance of the given constructor.

Source

assert.lengthOf(value, length, message)

Parameters:
  • value — Any
  • length — Integer
  • message — Stringoptional

Throws an error if the given value object length is not equal the given length.

Source

assert.notLengthOf(value, length, message)

Parameters:
  • value — Any
  • length — Integer
  • message — Stringoptional

Throws an error if the given value object length is equal the given length.

Source

assert.operator(value1, operator, value2, message)

Parameters:
  • value1 — Any
  • operator — String
  • value2 — Any
  • message — Stringoptional

Throws an error if the given operator comparison is falsy on the given values.

operator is a string as follow: >, >=, <, or <=. TypeError is thrown if unexpected operator has been given.

Example:

assert.operator(2, '>', 1); // true
assert.operator(2, '<=', 1); // AssertionError

Source

assert.match(value, regexp, message)

Parameters:
  • value — Any
  • regexp — RegExp
  • message — Stringoptional

Throws an error if the given regexp does not test on the given value.

Example:

assert.match('12', /[0-9]+/); // true

Source

assert.notMatch(value, regexp, message)

Parameters:
  • value — Any
  • regexp — RegExp
  • message — Stringoptional

Throws an error if the given regexp tests on the given value.

Source