isNode.js.flow 713 B

123456789101112131415161718192021
  1. /**
  2. * Copyright (c) 2013-present, Facebook, Inc.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @providesModule isNode
  8. * @typechecks
  9. */
  10. /**
  11. * @param {*} object The object to check.
  12. * @return {boolean} Whether or not the object is a DOM node.
  13. */
  14. function isNode(object) {
  15. var doc = object ? object.ownerDocument || object : document;
  16. var defaultView = doc.defaultView || window;
  17. return !!(object && (typeof defaultView.Node === 'function' ? object instanceof defaultView.Node : typeof object === 'object' && typeof object.nodeType === 'number' && typeof object.nodeName === 'string'));
  18. }
  19. module.exports = isNode;