getProperties.js 771 B

1234567891011121314151617181920212223242526272829303132333435
  1. /*!
  2. * Chai - getProperties utility
  3. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  4. * MIT Licensed
  5. */
  6. /**
  7. * ### .getProperties(object)
  8. *
  9. * This allows the retrieval of property names of an object, enumerable or not,
  10. * inherited or not.
  11. *
  12. * @param {Object} object
  13. * @returns {Array}
  14. * @name getProperties
  15. * @api public
  16. */
  17. module.exports = function getProperties(object) {
  18. var result = Object.getOwnPropertyNames(subject);
  19. function addProperty(property) {
  20. if (result.indexOf(property) === -1) {
  21. result.push(property);
  22. }
  23. }
  24. var proto = Object.getPrototypeOf(subject);
  25. while (proto !== null) {
  26. Object.getOwnPropertyNames(proto).forEach(addProperty);
  27. proto = Object.getPrototypeOf(proto);
  28. }
  29. return result;
  30. };