| 1 |
/** |
| 2 |
* Check if argument is a HTML element. |
| 3 |
* |
| 4 |
* @param {Object} value |
| 5 |
* @return {Boolean} |
| 6 |
*/ |
| 7 |
exports.node = function(value) { |
| 8 |
return value !== undefined |
| 9 |
&& value instanceof HTMLElement |
| 10 |
&& value.nodeType === 1; |
| 11 |
}; |
| 12 |
|
| 13 |
/** |
| 14 |
* Check if argument is a list of HTML elements. |
| 15 |
* |
| 16 |
* @param {Object} value |
| 17 |
* @return {Boolean} |
| 18 |
*/ |
| 19 |
exports.nodeList = function(value) { |
| 20 |
var type = Object.prototype.toString.call(value); |
| 21 |
|
| 22 |
return value !== undefined |
| 23 |
&& (type === '[object NodeList]' || type === '[object HTMLCollection]') |
| 24 |
&& ('length' in value) |
| 25 |
&& (value.length === 0 || exports.node(value[0])); |
| 26 |
}; |
| 27 |
|
| 28 |
/** |
| 29 |
* Check if argument is a string. |
| 30 |
* |
| 31 |
* @param {Object} value |
| 32 |
* @return {Boolean} |
| 33 |
*/ |
| 34 |
exports.string = function(value) { |
| 35 |
return typeof value === 'string' |
| 36 |
|| value instanceof String; |
| 37 |
}; |
| 38 |
|
| 39 |
/** |
| 40 |
* Check if argument is a function. |
| 41 |
* |
| 42 |
* @param {Object} value |
| 43 |
* @return {Boolean} |
| 44 |
*/ |
| 45 |
exports.fn = function(value) { |
| 46 |
var type = Object.prototype.toString.call(value); |
| 47 |
|
| 48 |
return type === '[object Function]'; |
| 49 |
}; |