88cd7b370d144e5e1cd7cb2311178b6b6fbce645925189dca1233515b419ea872a4c93e7a952ad1dc3d6490298a69051db9a01d1027ad5f414f0af98bcf556 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. * Check if argument is a list of HTML elements.
  14. *
  15. * @param {Object} value
  16. * @return {Boolean}
  17. */
  18. exports.nodeList = function(value) {
  19. var type = Object.prototype.toString.call(value);
  20. return value !== undefined
  21. && (type === '[object NodeList]' || type === '[object HTMLCollection]')
  22. && ('length' in value)
  23. && (value.length === 0 || exports.node(value[0]));
  24. };
  25. /**
  26. * Check if argument is a string.
  27. *
  28. * @param {Object} value
  29. * @return {Boolean}
  30. */
  31. exports.string = function(value) {
  32. return typeof value === 'string'
  33. || value instanceof String;
  34. };
  35. /**
  36. * Check if argument is a function.
  37. *
  38. * @param {Object} value
  39. * @return {Boolean}
  40. */
  41. exports.fn = function(value) {
  42. var type = Object.prototype.toString.call(value);
  43. return type === '[object Function]';
  44. };