Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
NPM Packages
js-type
Commits
7aec48dd
Commit
7aec48dd
authored
Feb 14, 2020
by
Milan Wikarski
Browse files
Added IS.NOT function, which returns the reverse IS
parent
3fa18d65
Changes
2
Hide whitespace changes
Inline
Side-by-side
index.js
View file @
7aec48dd
...
...
@@ -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
,
...
...
test/test.js
View file @
7aec48dd
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' }));
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment