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
51aee719
Commit
51aee719
authored
Feb 06, 2020
by
Milan Wikarski
Browse files
added is.keyValuePair
parent
16eca243
Changes
3
Hide whitespace changes
Inline
Side-by-side
index.js
View file @
51aee719
...
...
@@ -6,6 +6,7 @@ const _is = {
undefined
:
require
(
'
./src/is-undefined
'
),
callable
:
require
(
'
./src/is-callable
'
),
emptyString
:
require
(
'
./src/is-empty-string
'
),
keyValuePair
:
require
(
'
./src/is-key-value-pair
'
),
instance
:
require
(
'
./src/is-instance
'
)
};
...
...
@@ -53,7 +54,7 @@ _is.array = function isArray(val, typeCheck = null) {
/**
* Checks if value is of one of valid types specified by `types` array.
* valid items in `types` are:
* - `{string}`: type name - one of {'string', 'array', 'numeric', 'object', 'null', 'undefined', 'callable', 'emptyString'}
* - `{string}`: type name - one of {'string', 'array', 'numeric', 'object', 'null', 'undefined', 'callable', 'emptyString'
, 'keyValuePair'
}
* - `{Object}`: instance (eg. Regex) - checks instanceof
*
* @param {*} val
...
...
@@ -89,6 +90,7 @@ is.null = _is.null;
is
.
undefined
=
_is
.
undefined
;
is
.
callable
=
_is
.
callable
;
is
.
emptyString
=
_is
.
emptyString
;
is
.
keyValuePair
=
_is
.
keyValuePair
;
is
.
instance
=
_is
.
instance
;
...
...
src/is-key-value-pair.js
0 → 100644
View file @
51aee719
const
isObject
=
require
(
'
./is-object
'
);
/**
* Returns `true` if val is an key-value pair (object with one key and one value); `false` otherwise
*
* @param {*} val
* @returns {Boolean}
*/
function
isKeyValuePair
(
val
)
{
return
isObject
(
val
)
&&
Object
.
entries
(
val
).
length
==
1
;
}
module
.
exports
=
isKeyValuePair
;
test/test.js
View file @
51aee719
...
...
@@ -12,4 +12,7 @@ const { is, force } = require('../index');
// is.undefined(undefined)
// ]);
console
.
log
(
is
.
array
([
''
,
'
2
'
,
''
],
'
emptyString
'
));
// console.log(is.array(['', '2', ''], 'emptyString'));
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