Commit 7aec48dd authored by Milan Wikarski's avatar Milan Wikarski
Browse files

Added IS.NOT function, which returns the reverse IS

parent 3fa18d65
......@@ -15,7 +15,7 @@ const _is = {
* Returns `true` if val is an array; `false` otherwise.
* typeCheck can be one of:
* - Function -- in this case it has to be a function from is object. Each value in array will be checked vs this function
* - Array -- in this case it has to be a valid argument for is function
* - Array -- in this case it has to be a valid argument for `is` function
*
* @param {*} val
* @param {Function|Array} typeCheck?
......@@ -82,17 +82,59 @@ function is(val, types) {
return false;
}
is.not = function(val, types) {
return !is(val, types);
};
is.string = _is.string;
is.not.string = function() {
return !_is.string(...arguments);
};
is.array = _is.array;
is.not.array = function() {
return !_is.array(...arguments);
};
is.numeric = _is.numeric;
is.not.numeric = function() {
return !_is.numeric(...arguments);
};
is.object = _is.object;
is.not.object = function() {
return !_is.object(...arguments);
};
is.null = _is.null;
is.not.null = function() {
return !_is.null(...arguments);
};
is.undefined = _is.undefined;
is.not.undefined = function() {
return !_is.undefined(...arguments);
};
is.callable = _is.callable;
is.not.callable = function() {
return !_is.callable(...arguments);
};
is.emptyString = _is.emptyString;
is.not.emptyString = function() {
return !_is.emptyString(...arguments);
};
is.keyValuePair = _is.keyValuePair;
is.not.keyValuePair = function() {
return !_is.keyValuePair(...arguments);
};
is.instance = _is.instance;
is.not.instance = function() {
return !_is.instance(...arguments);
};
module.exports = {
is,
......
const { is, force } = require('../index');
// console.log([
// is.array(['foo', 'bar']),
// is.emptyString(''),
// is.callable(() => null),
// is.instance([], Object),
// is.null(null),
// is.numeric('42'),
// is.object({ foo: 'bar' }),
// is.string('halo'),
// is.undefined(undefined)
// ]);
console.log(is.not.array(['foo', 'bar']));
console.log(is.not.emptyString(''));
console.log(is.not.callable(() => null));
console.log(is.not.instance([], Object));
console.log(is.not.null(null));
console.log(is.not.numeric('42'));
console.log(is.not.object({ foo: 'bar' }));
console.log(is.not.string('halo'));
console.log(is.not.undefined(undefined));
// console.log(is.array(['', '2', ''], 'emptyString'));
console.log(is.keyValuePair({ key: 'value' }));
console.log(is.keyValuePair({ key: 'value', key2: 'value2' }));
// console.log(is.keyValuePair({ key: 'value' }));
// console.log(is.keyValuePair({ key: 'value', key2: 'value2' }));
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment