util.js 906 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. 'use strict';
  2. var _ = require('lodash');
  3. /*----------------------------------------------------------------------------*/
  4. /**
  5. * Creates a hash object. If a `properties` object is provided, its own
  6. * enumerable properties are assigned to the created hash.
  7. *
  8. * @memberOf util
  9. * @param {Object} [properties] The properties to assign to the hash.
  10. * @returns {Object} Returns the new hash object.
  11. */
  12. function Hash(properties) {
  13. return _.transform(properties, function(result, value, key) {
  14. result[key] = (_.isPlainObject(value) && !(value instanceof Hash))
  15. ? new Hash(value)
  16. : value;
  17. }, this);
  18. }
  19. Hash.prototype = Object.create(null);
  20. /**
  21. * This method throws any error it receives.
  22. *
  23. * @memberOf util
  24. * @param {Object} [error] The error object.
  25. */
  26. function pitch(error) {
  27. if (error != null) {
  28. throw error;
  29. }
  30. }
  31. module.exports = {
  32. 'Hash': Hash,
  33. 'pitch': pitch
  34. };